How to set a custom assets location for Android Asset Pack (not Android apk module) in gradle?

Viewed 1275

I have an Android education app with very large assets so I use Android bundle (.aab) and put the major part of asset (book data) into an asset pack. Here is the build.gradle file I made by following Android PLay Asset Delivery.

apply plugin: 'com.android.asset-pack'
assetPack {
    packName = "BookAssets"
    dynamicDelivery {
        deliveryType = "on-demand"
    }
}

It works well except that I have to use the hard-coded path src/main/assest to host my asset pack data. Since the project is cross-platform, I'd like to host the book data in a centeal place for all platforms (iOS, Android, Windows, mac).

For Android base APK, we can easily set custom assets path in build.gradle by sourcesets.main.assets.srcDirs, however when I try to use it on an Assest Pack module, the Android asset pack plugin report error and complains that it can not find definition assets.srcDirs.

So is there a way to set a custom assets location for Android Assets Pack module?

UPDATE

My current work around is creating a hard symbolic link under src/main/assets folder to let gradle find the assets hosted at other location. It works but I stil would like to know if there is an official way to customize assets location in gradle for Asset Pack.

1 Answers

I was able to solve this way:

apply plugin: 'com.android.asset-pack'

assetPack 
{
    packName = "InstallPack" // Directory name for the asset pack
    dynamicDelivery 
    {
        deliveryType = "install-time"
    }
}

project.afterEvaluate 
{
    generateAssetPackManifest.dependsOn copyFiles
}

task copyFiles(type: Sync)

copyFiles 
{
    description = 'sync assets'
    from [path_to_assets]
    into './src/main/assets'
    include('**/*')
}
Related