Using APK Splits for Release but not Debug build type

两盒软妹~` 提交于 2019-11-30 01:35:02
Jeff P

You can try a variation on @Geralt_Encore's answer, which avoids the separate gradlew command. In my case, I only cared to use APK splitting to reduce the released APK file size, and I wanted to do this entirely within Android Studio.

splits {
    abi {
      enable gradle.startParameter.taskNames.any { it.contains("Release") }
      reset()
      include 'x86', 'armeabi-v7a', 'mips'
      universalApk false
    }
}

From what I've seen, the Build | Generate Signed APK menu item in Android Studio generates the APK using the assembleRelease Gradle target.

You can set enable based on command line argument. I have solved kinda similar problem when I wanted to use splits only for the release version, but not for regular debug builds.

splits {
    abi {
        enable project.hasProperty('splitApks')
        reset()
        include 'x86', 'armeabi-v7a'
    }
}

And then ./gradlew -PsplitApks assembleProdRelease (prod is a flavor in my case).

I'm a bit late to this party, but having a problem with different flavors and tasks names, I've come with this:

ext.isRelease = { array ->
    array.each { name ->
        if (name.contains("Debug")) {
            return false
        }
    }
    return true
}

android {

...

    splits {
        abi {
            enable isRelease(gradle.startParameter.taskNames)
            reset()
            include "x86_64", "x86", "arm64-v8a", "armeabi-v7a"
            universalApk false
        }
    }

}

It's just a small update to Jeff P's answer but works well with different flavors and build configurations.

Update for @Jeff P's answer to make it more flexible based on app name and to support Android App Bundle (.aab) format

splits {
    abi {
      enable gradle.startParameter.taskNames.any { it.contains("Release") }
      reset()
      include 'x86', 'armeabi-v7a', 'mips'
      universalApk false
    }
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!