2013-11-21 68 views
16

我已經配置好了的build.gradle方法runProguard()由Proguard Gradle manual搖籃和ProGuard的:無法找到論據[真]

這所建議的是根的build.gradle

buildscript { 
    repositories { 
     flatDir dirs: '/home/username/android-sdks/tools/proguard/lib' 
     mavenCentral() 
    } 
    dependencies {      
     classpath 'com.android.tools.build:gradle:0.5.+' 
     classpath ':proguard' 
    } 
} 

現在這是的build.gradle爲我的項目

apply plugin: 'android' 

dependencies { 
    compile fileTree(dir: 'libs', include: '*.jar') 
    compile project(':SomeLibraryProject') 
} 

android { 
    compileSdkVersion 19 
    buildToolsVersion "19.0.0" 

    sourceSets { 
     ... 
    } 

    task runProguardTask(type: proguard.gradle.ProGuardTask) { 
    } 

    signingConfigs { 
     debug { 
      storeFile file("./keystore/keystore") 
      storePassword "******" 
      keyAlias "******" 
      keyPassword "*******" 
     } 

     release { 
      runProguard true 
      proguardFile 'proguard-android.txt' 
      storeFile file("./releasekey/keystore") 
      storePassword "******" 
      keyAlias "********" 
      keyPassword "*******" 
     } 
    } 

    buildTypes { 
     release { 
      signingConfig signingConfigs.release 
     } 
    } 
} 

這是輸出

$ ./gradlew build 

FAILURE: Build failed with an exception. 

* Where: 
Build file '/home/username/Documents/eclipse/workspace/repo/ProjectName/build.gradle' line: 49 

* What went wrong: 
A problem occurred evaluating project ':ProjectName'. 
> Could not find method runProguard() for arguments [true] on SigningConfigDsl_Decorated{name=release, storeFile=null, storePassword=null, keyAlias=null, keyPassword=null, storeType=null}. 

* Try: 
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. 

BUILD FAILED 

Total time: 9.14 secs 

我也想知道爲什麼storeFile,storePassword,keyAlias和keyPassword爲空?

回答

13

由於錯誤的DSL屬性名稱,這種錯誤很常見。在您的build.gradlehttp://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Running-ProGuard:確保指定了正確的值

android { 
    buildTypes { 
     release { 
      minifyEnabled true 
      proguardFile getDefaultProguardFile('proguard-android.txt') 
     } 
    } 
} 

你可以在這裏找到所有屬性的javadoc(點擊下載DSL參考BTN): http://developer.android.com/tools/building/plugin-for-gradle.html


更新從2014-11- 24:

幾個屬性重命名爲0.14.0 gradle插件。從AléciorunProguard -> minifyEnabled檢查答案,並在此按最近更改:http://tools.android.com/tech-docs/new-build-system

+0

謝謝!有效。 –

+4

runProguard現已被棄用。看下面的正確答案,您需要更改爲minifyEnabled。 –

57

runProguard被棄用(和即將停止工作);更改爲 「minifyEnabled」,而不是

... 

buildTypes { 
    release { 
     minifyEnabled true 
     .... 
+4

謝謝,修正了我在Android Studio 1.0 RC上的gradle錯誤1 – Lemberg

+1

Thanx man!這是一個很好的解決方案! – Armin

3
runProguard is deprecated after gradle build tools version 1.0.0-rc1 
Running ProGuard 



ProGuard is supported through the Gradle plugin for ProGuard version 4.10. The ProGuard plugin is applied automatically, and the tasks are created automatically if the Build Type is configured to run ProGuard through the minifyEnabled property. 

android { 
    buildTypes { 
     release { 
      minifyEnabled true 
      proguardFile getDefaultProguardFile('proguard-android.txt') 
     } 
    } 

    productFlavors { 
     flavor1 { 
     } 
     flavor2 { 
      proguardFile 'some-other-rules.txt' 
     } 
    } 
} 
+0

上面的部分真的讓你的android代碼安全嗎? –