[英]How to change the apk filename in Android Studio with gradle-plugin 7.2.2 gradle version 7.3.3
i'm using Android Studio Version 2021.2.1 Gradl 7.3.3 and the gradle-plugin 7.2.2我正在使用 Android Studio 版本 2021.2.1 Gradl 7.3.3 和 gradle-plugin 7.2.2
When i try to change the apk-filename in the same way as i have done it in earlier projects i recieve the following error.当我尝试以与在早期项目中相同的方式更改 apk 文件名时,我收到以下错误。
Build file '...\app\build.gradle' line: 34构建文件 '...\app\build.gradle' 行:34
A problem occurred configuring project ':app'.配置项目 ':app' 时出现问题。
com.android.build.gradle.internal.dsl.AgpDslLockedException: It is too late to add new build types They have already been used to configure this project.
com.android.build.gradle.internal.dsl.AgpDslLockedException:添加新的构建类型为时已晚他们已经用于配置此项目。 Consider moving this call to finalizeDsl or during evaluation.
考虑将此调用移至 finalizeDsl 或在评估期间。
I cannot find out what i have to change to give the apk-file a new filename.我找不到我必须更改的内容才能给 apk 文件一个新的文件名。 Everything i found is for older gradle versions where my build.gradle is working.
我发现的所有内容都适用于我的 build.gradle 工作的旧 gradle 版本。 Is there a tutorial or howto that helps me to solve the problem.
是否有教程或方法可以帮助我解决问题。
apply plugin: 'com.android.application'
android {
compileSdkVersion 32
defaultConfig {
applicationId "..."
minSdkVersion 19
targetSdkVersion 32
versionCode 1205
versionName '1.2.05'
testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
}
signingConfigs {
config {
keyAlias 'alias'
keyPassword 'pass'
storeFile file(mykeystore.jks')
storePassword '12345'
}
}
buildTypes {
release {
shrinkResources true
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
applicationVariants.all { variant ->
variant.outputs.all { output ->
project.ext { appName = 'myAppname' }
def formattedDate = new Date().format('yyyyMMdd_HHmmss')
// NEXT IST LINE 34 where the ERROR points to
def newName = "${globalScope.project.name}-${output.baseName-${variant.versionName}}.apk"
newName = newName.replace("app-", "$project.ext.appName-")
newName = newName.replace("-release", "-release-" + formattedDate + "_" + versionName.replace(".",""))
outputFileName = new File("../../../../release/" + newName)
}
}
signingConfig signingConfigs.config
zipAlignEnabled true
pseudoLocalesEnabled true
}
debug {
minifyEnabled false
//useProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
zipAlignEnabled true
pseudoLocalesEnabled true
debuggable true
signingConfig signingConfigs.config
}
}
productFlavors {
}
}
buildTypes {
debug {
debuggable true
}
release {
// minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.release
android.applicationVariants.all { variant ->
variant.outputs.all {
def date = new Date()
def formattedDate = date.format('yyyy-MM-dd')
outputFileName = "${variant.productFlavors[0].name}" + formattedDate + "_${variant.name}_${variant.versionName}.apk"
}
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.