Strip Assets Files in new Android Gradle

Spending 2 hours on this because 1) I don't have experience with Gradle script (its syntax looks funky) 2) DJI sxxks, and they put 50MB of large assets files to their SDK, which is camera distrotion_correction files that I never need, and 3) Android Gradle library upgrades, which deprecating mergeAssets.

Looking at some GitHub projects's Gradle script, it looks like dependsOn is very popular in defining what order the task should be executed, and it works!

android.applicationVariants.all {
        variant ->
            // exclude DJI assets from release builds
            def noDJIAssetsTask = task("delete${variant.name.capitalize()}DJIAssets", type: Delete) {
                delete "${buildDir}/intermediates/merged_assets/${variant.dirName}/out/expansion/internal/distrotion_correction"
            }
            def packageTask = variant.hasProperty("packageApplication")
                    ? variant.packageApplicationProvider.get()
                    : tasks.findByName("package${targetName}")
            if (variant.hasProperty("packageLibrary")) {
                packageTask = variant.packageLibrary
            }
            def mergeDebugAssets = variant.mergeAssetsProvider.get()
            // After mergeDebugAssets, but before packageTask
            noDJIAssetsTask.dependsOn mergeDebugAssets
            packageTask.dependsOn noDJIAssetsTask
    }

Thank you:

https://stackoverflow.com/questions/25910206/gradle-exclude-file-from-android-assets-folder

https://stackoverflow.com/questions/28897450/exclude-assets-for-release-build-type

发表评论

电子邮件地址不会被公开。 必填项已用*标注