4

I packed some assets in my Android kotlin app using the asset-pack library: https://developer.android.com/guide/app-bundle/asset-delivery/build-native-java

Not I should be able to access the assets using the AssetManager via context.assets. However, I have no clue what the correct path is.

My assets pack is called models and correctly created in the root folder of the .aab file, so I guess it is also installed correctly. enter image description here

Now according to the documentation (https://developer.android.com/guide/playcore/asset-delivery/integrate-java) I can access the assets like this:

import android.content.res.AssetManager;
...
Context context = createPackageContext("com.example.app", 0);
AssetManager assetManager = context.getAssets();
InputStream is = assetManager.open("asset-name");

where I chane the package name to my package name. But what is the asset name?!? It's not the name of the files in my models asset folder. I tried assetManager.list(p) with p as anything I could think of, but I could not find where my assets are stored.

For p='' the result of assetManager.list(p) is

 hw_pc_white_apps.xml
    hw_pc_white_apps_pad.xml
    images
    permission_grant_policy.xml
    permission_grant_policy_oversea.xml
    pfw
    sfpconfig.json
    ukeyapp.xml
    water.frag
    water.vert
    webkit
    wifi_policy.xml
    wifipro_regexlist.xml

which also makes no sense to me. How can I access assets from asset packs?

GenError
  • 885
  • 9
  • 25
  • Of course I tried accessing my assets with `assetManager.open("modelfile.dat")` but this raises a `FileNotFoundExeption` – GenError Jun 29 '20 at 21:14

1 Answers1

9

Ok, I found the solution: the Android Studio does not deliver the asset packs by default, the configuration needs to be adjusted under Run -> Edit configuration -> Deliver APK from app bundle (https://developer.android.com/guide/app-bundle/test) to deliver assets and the app.

Now the assets are accessible as if they were assets of the main app.

GenError
  • 885
  • 9
  • 25
  • so how do you access it in testing, means iam using 'fast_follow' asset-pack, so do I need to download ad described in docs because then it shows pack not found, and if Edit configuration thing already delivered it then how to access it while testing, because using file path not working because we did not downloaded it as we will do in release....please help me in this – kunal Aug 07 '20 at 18:23
  • Sorry, I don't have an answer for that. Maybe open a question so someone who knows more details can help you. – GenError Aug 10 '20 at 10:13
  • @GenError can you please answer this https://stackoverflow.com/questions/67119885/file-access-problem-from-asset-pack-in-android-from-the-testing-app-downloaded-f – rafi Apr 16 '21 at 09:27
  • So createPackageContext has the name of the APPLICATION not the name of the ASSET PACK? not `models`, but I your application's package name as listed in the `AndroidManifest.xml` `` and the file you wanted to open is in `models\modelfile.dat`? Do I have both of those correct? – Paul Hill Jan 11 '22 at 08:09
  • Yes, as far as I understand it, the asset packs are merely for splitting the data "outside" of the application, e.g. for distributing via the play store. Within the application, all assets are directly accessible as if they were delivered with the application. – GenError Jan 15 '22 at 11:48