5

I am configuring my Android app to use Play Asset Delivery, using the install-time option. I am following the official guide found here

Here are my following configurations:

In the project setup, I have created an asset_pack directory, including the sub directories src/main/assets

In the app gradle I setup my asset pack:

assetPacks = [":asset_pack"]

In the settings.gradle I included my asset pack:

include ':app'
include ':asset_pack'

In the asset pack gradle I added the reference to the asset pack and method of download:

assetPack {
    packName = "asset_pack"
    dynamicDelivery {
        deliveryType = "install-time"
    }
}

Everything seems to be working fine until I try to retrieve assets from this root level directory.

The documentation states that I should be using this method:

val packageContext: Context = createPackageContext("com.example.app", 0)
val assetManager: AssetManager = packageContext.assets
val inputStream: InputStream = assetManager.open("basemap/phil.jpg")

My app crashes when trying to retrieve assets (I have replaced the com.example.app with my app info)

When I look up the assetManager list assetManager.list("") files that show up are all part of the app package. Unfortunately, the folder named asset_pack or any of its content does not show up as an option.

Here is my question: I imagine that the reason why I am not seeing my asset_pack files is because it is at the same level at my app directory, but I don't know how to access that folder using the assetManager. Would anyone know how I access those files?

5 Answers 5

6

The correct answer can be found at How to access assets-pack data in Android (kotlin) Basically edit your run configuration to create the apk to be installed from the app-bundle

2

To test the play asset delivery locally you need to use the bundletool as mentioned here

I created a batch script to automate the process, you can use it as follows:

  • Create file in the project root and name it testOnDevice.bat
  • Copy the script to the file and replace the app package name.
  • Download the bundle tool and place it's folder in the project root.
  • Call the batch file from the android studio console.

It will build the app bundle with asset delivery packages inside, load it to the device using ADB, then run the app.

Here is the script, just make sure to update the bundletool version to the one you have:

Echo "Building the app bundle"
call gradlew.bat :app:bundleDebug

Echo "Deleting the old output.apks"
del /F ".\output.apks"

Echo "Building apks with local tesing flag"
java -jar ".\bundletool\bundletool-all-1.5.0.jar" build-apks --bundle=".\app\build\outputs\bundle\debug\app-debug.aab" --output=output.apks --local-testing

Echo "Installing the apk on the device"
java -jar ".\bundletool\bundletool-all-1.5.0.jar" install-apks --apks=output.apks

Echo "Running the apk on the device"
adb shell monkey -p com.company.packagename -c android.intent.category.LAUNCHER 1
1

It's is unclear how you build & provide that asset pack - switch to "Android" view to see what's there; The "Resource Manager" tool should be able to browse both modules (which it probably won't). And you may need to install it along with the application, while it's not published.

1
  • I did push an internal build to test it, and it does seem to have downloaded during the install. But I just don’t seem to be able to look at the content in Android Studio
    – PhilBlais
    Feb 3, 2021 at 2:07
1

I had the same problem and spent 3 hours trying to find a solution. All in vain. I started experimenting and in my case the only solution I found was to put all my "install-time" asset files into another asset folder, that is into:

app\src\main\assets\

Now assetManager.open() was successful!

But I still don't know why the method described by Google docs (putting "install-time" asset files into a separate asset pack folder) doesn't work...

0
1

I strugguled a lot about this topic and find this solution through Google Play:

  1. build signed aab
  2. enable internal app sharing in play console and setup to your google account/email
  3. upload aab and copy link to your device with same google account
  4. enable internal app sharing in play store app (settings, tap multiple times on app version and switch will appear)
  5. just open link, download app and it should work ;)

Note1: You should have correctly configured assets according documentation

Note2: This approach requires Google play developer account and app created there. Unfortunately I did not find way how to test directly from android studio by installing app directly to device.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.