在Android studio 3.0 之前 我们自定义apk名称使用如下方式:
applicationVariants.all { variant ->
variant.outputs.each { output ->
output.outputFile = new File(output.outputFile.parent, variant.applicationId + "-" + buildType.name+"-" +defaultConfig.versionName + "-" + defaultConfig.versionCode + "-${releaseTime() }.apk" );
}
}
但是更新到as3.0以后,会同步失败。stackoverflow上有人(http://stackoverflow.com/questions/44044031/grade-plugin-3-alpha1-outputfile-causes-error)说:
This build error occurs because variant-specific tasks are no longer created during the configuration stage.
This results in the plugin not knowing all of its outputs up front, but it also means faster configuration times.
As an alternative, we will introduce new APIs to provide similar functionality.
查询官网介绍:https://developer.android.com/studio/preview/features/new-android-plugin-migration.html#variant_api
API change in variant output
解决方案:
applicationVariants.all { variant ->
variant.outputs.all { output ->
outputFileName=" ${variant.applicationId}- ${ buildType.name}- ${defaultConfig.versionName}-${ defaultConfig.versionCode }-${releaseTime() }.apk"
}
}
本文介绍如何在Android Studio 3.0及之后版本中自定义apk文件名。由于API变更,旧方法不再适用。文中提供了一种新的实现方式。
2733

被折叠的 条评论
为什么被折叠?



