Reputation: 1186
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?
Upvotes: 6
Views: 4707
Reputation: 46
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:
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
Upvotes: 2
Reputation: 108
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
Upvotes: 6
Reputation: 137
I strugguled a lot about this topic and find this solution through Google Play:
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.
Upvotes: 1
Reputation: 871
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...
Upvotes: 1
Reputation: 76799
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.
Upvotes: 1