我正在使用Android版本2021.2.1 Gradl 7.3.3和gradle-plugin 7.2.2
当我试图更改apk-文件名时,与我在早期项目中所做的相同,我会收到以下错误。
构建文件'...\app\build.gradle‘行: 34
配置项目':app‘时出现问题。
com.android.build.gradle.internal.dsl.AgpDslLockedException:--添加已用于配置此项目的新构建类型为时已晚。考虑将此调用转移到finalizeDsl或评估期间。
我找不出需要更改什么才能给apk文件一个新的文件名。我发现的所有东西都是用于我的build.gradle正在工作的旧版本的。有没有帮助我解决问题的教程或方法?
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 {
}
}发布于 2022-09-01 11:05:47
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"
}
}
}
}https://stackoverflow.com/questions/73351357
复制相似问题