android studio 打包重命名

  • A+
所属分类:移动前端

自定义apk名称含版本号信息 今天更新了as后发现之前的重命名APP包名失效了,报错如下:

WARNING: API 'variantOutput.getPackageApplication()' is obsolete and has been replaced with 'variant.getPackageApplicationProvider()'.
It will be removed at the end of 2019.
For more information, see https://d.android.com/r/tools/task-configuration-avoidance.
To determine what is calling variantOutput.getPackageApplication(), use -Pandroid.debug.obsoleteApi=true on the command line to display a stack trace.
Affected Modules: app

解决方案:

3.2.0之前写法:

 applicationVariants.all { variant ->
        variant.outputs.all { output ->
            def outputFile = output.outputFile
            def fileName = outputFile.name
            def flavorName = "app"
            def buildType = variant.buildType.name

            if (outputFile != null && outputFile.name.endsWith('.apk')) {
                fileName = "${flavorName}-${buildType}-${defaultConfig.versionName}.apk"
            }
            outputFileName = fileName
        }
    }

更新至Android Studio 3.3 gradle 4.10.1之后

android.applicationVariants.all { variant ->
        variant.outputs.all {
            outputFileName = "app-app_${variant.buildType.name}-${variant.versionName}.apk"
        }
    }
avatar