Since Android Studio uses the new Gradle-based build system , you should be putting assets/
inside of the source sets (eg, src/main/assets/
).
(由于Android Studio使用新的基于Gradle的构建系统 ,因此您应将assets/
放在源集中 (例如src/main/assets/
)。)
In a typical Android Studio project, you will have an app/
module, with a main/
sourceset ( app/src/main/
off of the project root), and so your primary assets would go in app/src/main/assets/
.
(在一个典型的Android Studio项目中,您将有一个app/
模块,具有一个main/
源码集( app/src/main/
在项目根目录之外),因此您的主要资产将进入app/src/main/assets/
。)
However: (然而:)
If you need assets specific to a build, such as debug
versus release
, you can create sourcesets for those roles (eg,. app/src/release/assets/
)
(如果您需要特定于构建的资产(例如debug
与release
,则可以为这些角色创建源集(例如app/src/release/assets/
)。)
Your product flavors can also have sourcesets with assets (eg, app/src/googleplay/assets/
)
(您的产品口味还可以包含带有资产的资源集(例如app/src/googleplay/assets/
))
Your instrumentation tests can have an androidTest
sourceset with custom assets (eg, app/src/androidTest/assets/
), though be sure to ask the InstrumentationRegistry
for getContext()
, not getTargetContext()
, to access those assets
(您的检测测试可以具有带有自定义资产的androidTest
(例如app/src/androidTest/assets/
),尽管一定要向InstrumentationRegistry
请求getContext()
而不是getTargetContext()
来访问这些资产)
Also, a quick reminder: assets are read-only at runtime.
(另外,还有一个简短的提醒:资产在运行时是只读的。)
Use internal storage , external storage , or the Storage Access Framework for read/write content. (使用内部存储 , 外部存储或Storage Access Framework读取/写入内容。)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…