提问人:abaci 提问时间:11/22/2014 最后编辑:Mahozadabaci 更新时间:5/4/2022 访问量:172296
未找到 Gradle DSL 方法:“runProguard”
Gradle DSL method not found: 'runProguard'
问:
从上一个项目更新后出现错误。我的代码没有问题,但我在使用 build.gradle 时遇到了问题。我该如何解决?
build.gradle 代码:
apply plugin: 'android'
android {
compileSdkVersion 21
buildToolsVersion '20.0.0'
packagingOptions {
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/LICENSE'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/license.txt'
exclude 'META-INF/NOTICE'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/notice.txt'
exclude 'META-INF/ASL2.0'
}
defaultConfig {
applicationId 'com.xxx.axxx'
minSdkVersion 14
targetSdkVersion 19
versionCode 6
versionName '1.0'
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
productFlavors {
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:19.+'
compile files('libs/commons-codec-1.8.jar')
compile files('libs/asmack-android-8-4.0.4.jar')
compile 'com.android.support:support-v4:21.0.0'
compile 'com.google.code.gson:gson:2.2.4'
compile 'com.jakewharton:butterknife:5.1.1'
}
Gradle Sync 消息输出:
Error:(27, 0) Gradle DSL method not found: 'runProguard()'
**Possible causes:
The project 'Atomic4Mobile' may be using a version of Gradle that does not contain the method.
**Gradle settings**
The build file may be missing a Gradle plugin.
**Apply Gradle plugin**
答:
如果您使用的是 0.14.0 或更高版本的 gradle 插件,则应在 build.gradle 文件中将“runProguard”替换为“minifyEnabled”。
runProguard 在 0.14.0 版本中重命名为 minifyEnabled。有关详细信息,请参阅 Android 构建系统
评论
使用而不是正常工作。'minifyEnabled'
'runProguard'
Previous code:
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
Current code:
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
如果要迁移到 1.0.0,则需要更改以下属性。
在项目的 build.gradle 文件中,您需要替换 minifyEnabled。
因此,您的新构建类型应为
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
还要确保 gradle 版本是 1.0.0 喜欢的
classpath 'com.android.tools.build:gradle:1.0.0'
在 build.gradle 文件中。
这应该可以解决问题。
来源:http://tools.android.com/tech-docs/new-build-system/migrating-to-1-0-0
通过将 runProguard 更改为 minifyEnabled,部分问题得到修复。
但是该修复可能会导致“库项目无法设置应用程序 ID”(您可以在此处找到修复程序 Android Studio 1.0 和错误“库项目无法设置应用程序 Id”)。
通过删除 build.gradle 文件中的应用程序 ID,您应该可以开始了。
评论
runProguard 已在 Gradle 中重命名为 minifyEnabled 版本 0.14.0 (2014/10/31) 或更高版本。
要解决此问题,您需要在项目的 build.gradle 文件中将 runProguard 更改为 minifyEnabled。
这是针对 Kotlin DSL (build.gradle.kts) 的:
buildTypes {
getByName("release") { // or simply release { in newer versions of Android Gradle Plugin (AGP)
isMinifyEnabled = true
isShrinkResources = true
proguardFiles(
// "proguard-android-optimize.txt" reduces size more than "proguard-android.txt"
getDefaultProguardFile("proguard-android-optimize.txt"),
"proguard-rules.pro"
)
signingConfig = signingConfigs.getByName("mySigningConfig")
}
}
我在顶级构建文件中使用 Android Gradle 插件 (AGP) 版本 7:
buildscript {
// ...
dependencies {
classpath("com.android.tools.build:gradle:7.0.4")
// ...
}
}
评论
minifyEnabled
runProguard