Using APK Splits for Release but not Debug build type

我怕爱的太早我们不能终老 提交于 2019-11-28 22:21:49

问题


I've successfully implemented APK Splits so that separate APKs are generated for different ABIs.

However, for efficiency (and since I have no need for non-armeabi-v7a APKs in Debug), I would like to limit Debug builds to only generate armeabi-v7a APKs.

How can this be done?

One idea is with this:

abi {
    enable true
    reset()
    include 'x86', 'armeabi-v7a', 'mips'
    universalApk false
}

Maybe there is some way to set enable based on the Build type?


回答1:


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.




回答2:


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).




回答3:


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.




回答4:


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
    }
}


来源:https://stackoverflow.com/questions/34592507/using-apk-splits-for-release-but-not-debug-build-type

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!