Android - build separate APKs for different processor architectures

后端 未结 3 1848
半阙折子戏
半阙折子戏 2020-11-28 12:20

Is there an easy way to build separate APK files for Android for different processor architectures, with the old ANT or the new Gradle build process? My way of doing this is

3条回答
  •  無奈伤痛
    2020-11-28 12:42

    In this article Android NDK: Version code scheme for publishing APKs per architecture I have found a nice solution to this problem. It consists in adding the following code

     splits {
        abi {
            enable true
            reset()
            include 'x86', 'armeabi', 'armeabi-v7a'
            universalApk true
        }
    }
    
    project.ext.versionCodes = ['armeabi': 1, 'armeabi-v7a': 2, 'arm64-v8a': 3, 'mips': 5, 'mips64': 6, 'x86': 8, 'x86_64': 9]
    
    android.applicationVariants.all { variant ->
        variant.outputs.each { output ->
            output.versionCodeOverride =
                project.ext.versionCodes.get(output.getFilter(
                    com.android.build.OutputFile.ABI), 0) * 10000000 + android.defaultConfig.versionCode
        }
    }
    

    to the android{...} section of the build.gradle script. If you want to understand the details, I highly recommend to read that article, it is really worth reading.

提交回复
热议问题