2017-01-02 100 views
1

我建立在Android的應用程序,這是的build.gradle文件:執行失敗的任務「:應用程序:transformClassesAndResourcesWithProguardForRelease」的Android

apply plugin: 'com.android.application' 

android { 
    compileSdkVersion 25 
    buildToolsVersion "25.0.1" 
    defaultConfig { 
     applicationId "myApp" 
     minSdkVersion 21 
     targetSdkVersion 25 
     versionCode 1 
     versionName "1.0" 
     testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 
     multiDexEnabled true 
    } 
    buildTypes { 
     release { 
      minifyEnabled true 
      proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 
     } 
    } 
    packagingOptions { 
     packagingOptions { 
      exclude 'META-INF/DEPENDENCIES.txt' 
      exclude 'META-INF/LICENSE.txt' 
      exclude 'META-INF/NOTICE.txt' 
      exclude 'META-INF/NOTICE' 
      exclude 'META-INF/LICENSE' 
      exclude 'META-INF/DEPENDENCIES' 
      exclude 'META-INF/notice.txt' 
      exclude 'META-INF/license.txt' 
      exclude 'META-INF/dependencies.txt' 
      exclude 'META-INF/LGPL2.1' 
     } 
    } 
} 

dependencies { 
    compile fileTree(dir: 'libs', include: ['*.jar']) 
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { 
     exclude group: 'com.android.support', module: 'support-annotations' 
    }) 
    compile project(':geth') 
    compile 'com.android.volley:volley:1.0.0' 
    compile 'com.google.android.gms:play-services-maps:10.0.1' 
    compile 'com.android.support:appcompat-v7:25.1.0' 
    compile 'com.android.support:support-v4:25.1.0' 
    compile 'com.android.support:design:25.1.0' 
    compile 'com.android.support:multidex:1.0.1' 
    compile 'org.web3j:core-android:1.1.0' 
    testCompile 'junit:junit:4.12' 
} 

當我嘗試建立我的應用程序,我得到以下警告這導致一個失敗的構建:

http://pastebin.com/EhMr66Yg

我應該添加-dontwarn規則這些警告?是什麼導致他們?

是否構建失敗,因爲67個警告或者因爲最後一個:

「有圖書館類成員1次分辨的引用 你可能需要更新庫版本。」

謝謝。

+0

檢查事件日誌,看看有什麼失敗。它位於Android Studio的右下角。 –

回答

1

問題在於Proguard的鏈接問題。 ProGuard優化字節碼,刪除未使用的代碼指令,並用短名稱混淆剩餘的類,字段和方法。混淆的代碼,使您的APK難以扭轉工程師,這是特別有價值的,當你的應用程序使用安全敏感功能

對於proguard的看看這裏的更多信息:使用 https://developer.android.com/studio/build/shrink-code.html

ProGuard的每個庫的具體規則在你的build.gradle應該放置在「proguard-rules.pro」文件中,如截圖所示。

enter image description here

注:ProGuard的文件是可以改變的。

即將寫入規則。

-keep class android.support.v4.app.** { *; } 
-keep interface android.support.v4.app.** { *; } 
-keep class com.actionbarsherlock.** { *; } 
-keep interface com.actionbarsherlock.** { *; } 
-keep class com.android.volley.** { *; } 
-keep interface com.android.volley.** { *; } 
-keep class org.apache.commons.logging.** 
-keepattributes *Annotation* 

-dontwarn org.apache.** 

-keepattributes Annotation,EnclosingMethod,Signature 
-keepnames class com.fasterxml.jackson.* { ; } 
-dontwarn com.fasterxml.jackson.databind. 
-keep class org.codehaus.* { ; } 
-keepclassmembers public final enum org.codehaus.jackson.annotate.JsonAutoDetect$Visibility { 
public static final org.codehaus.jackson.annotate.JsonAutoDetect$Visibility *; } 
-keep public class your.class.* { 
public void set_(_); 
public ** get*(); 
} 

注:如需進一步庫proguard的規則,使用https://github.com/krschultz/android-proguard-snippets

0

你必須使用以下。

-dontwarn com.squareup.** 
-dontwarn com.fasterxml.** 

和其導致warning.These類可能是自我混淆,所以你不需要申請親衛隊在them.Hope這會爲你工作其他類。

相關問題