我正在尝试使用动态模块分割API交付来将我的游戏应用分解为即时和可安装版本。我一直在遵循这里的Codelabs教程https://codelabs.developers.google.com/codelabs/on-demand-dynamic-delivery/index.html#0。不幸的是,它使用Kotlin编写MainActivity代码,相对于Java而言较为笼统,但如果您已经完成了Kotlin教程,仍然可以跟随。该示例包括访问“assets”功能模块中的“assets”文件夹中的文本文件,具体如下:
private const val packageName = "com.google.android.samples.dynamicfeatures.ondemand"
val assetManager = createPackageContext(packageName, 0).assets
// Now treat it like any other asset file.
val assets = assetManager.open("assets.txt")
val assetContent = assets.bufferedReader()
.use {
it.readText()
}
现在我只想访问动态功能模块中可绘制文件夹中的图形文件。我将仅使用我的动态功能模块来存储大型图形,这些图形会使我超过即时应用程序下载的10 MG限制。最清洁的方法是什么?
主要“应用”模块:
'app'中的Java代码:
loadTexture(R.drawable.aaa_image);
Bitmap bitmap;
public void loadTexture(final int resourceId){
bitmap = BitmapFactory.decodeResource(context.getResources(), resourceId, options);
***
动态提供的“installationassets”模块:
仍然有Java代码在'app'中,无法到达:
loadTexture(R.drawable.testgraphic);
cannot resolve symbol 'testgraphic'