根据Native ABI生成多个Apk

Generating Multiple Apk according to the Native ABI

我正在基于 ABI 构建发布 apk,因为要在 Play 商店.

上发布的 apk 大小

所以我开始为 ABI = armeabi-v7a 构建 apk,然后构建 ABI = x86 和 ABI = areambi

所以我的 gradle 看起来像这样

应用gradle

android {
    compileSdkVersion 26
    buildToolsVersion "26.0.1"
    defaultConfig {
        applicationId "com.package"
        minSdkVersion 18
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"
        multiDexEnabled true
        ndk {
            abiFilters "armeabi-v7a"
        }
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    externalNativeBuild {
        ndkBuild {
            path 'src/main/jni/Android.mk'
        }
    }
    splits {
        // Configures multiple APKs based on ABI.
        abi {
            // Enables building multiple APKs per ABI.
            enable true
            // By default all ABIs are included, so use reset() and include to specify that we only
            // want APKs for x86, armeabi-v7a, and mips.

            // Resets the list of ABIs that Gradle should create APKs for to none.
            reset()

            // Specifies a list of ABIs that Gradle should create APKs for.
            include "armeabi-v7a"

            // Specifies that we do not want to also generate a universal APK that includes all ABIs.
            universalApk false
        }
    }
}

所以我的问题

  1. 我需要为每个 ABI 在 versionCode 1 中进行更改,因此我应该使用哪个 ABI 的版本代码。
productFlavors{  

    arm{  
        ndk{  
            abiFilters "arm64-v8a" , "armeabi"  , "armeabi-v7a"  
        }  
    }  
    x86{  
        ndk{  
            abiFilters "x86" , "x86_64"  
        }  
    }  
}  

我必须制作 2 个不同的版本

构建 1:用于 armeabi-v7a

versionCode 21614001
splits {
    abi {
        enable true
        reset()
        include "armeabi-v7a"
        universalApk false
    }
}

构建 2:适用于 x86

versionCode 61614001
splits {
    abi {
        enable true
        reset()
        include "x86"
        universalApk false
    }
}

Added native library accordingly to the abi supported.

发布 apk Build 1 和 Build 2 后将显示支持的设备。