安卓 gradle 配置生成不同 ABI 版本及不同名字的 APK

应用市场支持分开上传32位包和64位包了
打包相关的代码改一下

android {

    productFlavors {
        tongyong {
            manifestPlaceholders = [APP_CHANNEL: "tongyong"]
        }
    }

    rootProject.ext.env = "release"//自定义的环境配置

    //按abi拆分包
    splits {
        abi {
            enable true
            reset()
            include 'armeabi-v7a', 'arm64-v8a' //支持的ABIs
            universalApk true //要不要一个全量ABIs的包
        }
    }

    android.applicationVariants.all { variant ->
        variant.outputs.all { output ->
            def aid = variant.applicationId.split("\\.")
            def name = aid[aid.length - 1]
            def flavor = variant.productFlavors[0].name
            def buildType = env
            def abi = output.getFilter(com.android.build.OutputFile.ABI)
            if (abi == null) abi = "all"
            def version = variant.versionName
            def versionCode = variant.versionCode
            def date = new Date()
            def formattedDate = date.format('yyyyMMdd_HHmm')
            outputFileName = "${name}" +
                    "${"_"}${flavor}" +
                    "${"_"}${buildType}" +
                    "${"_"}${abi}" +
                    "${"_"}${"v"}${version}" +
                    "${"_"}${"b"}${versionCode}" +
                    "${"_"}${formattedDate}.apk"
            if (variant.buildType.name == "release") {//release环境更换目录位置
                variant.getPackageApplicationProvider().get().outputDirectory = new File(project.rootDir.absolutePath
                        + "/releaseOutputs")
            }
        }
    }
}

你可能感兴趣的:(安卓 gradle 配置生成不同 ABI 版本及不同名字的 APK)