激活proguard时,Gradle无法构建(从eclipse迁移)

时间:2016-03-20 11:00:12

标签: android gradle proguard

当我激活proguard时,我无法生成我的项目:

http://www.pastefile.com/hyEvNK

我的构建文件是:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.2"
    defaultConfig {
        applicationId "com.sh.inv"
        targetSdkVersion 23
        versionCode 66
        versionName "2.5.0"
        multiDexEnabled false
    }
    buildTypes {
        release {
            minifyEnabled true
            proguardFiles 'proguard-project.txt'
        }
    }
    productFlavors {
    }

    productFlavors {
            minSdkVersion 21
    }
}
repositories {
    maven { url "http://jzaccone.github.io/SlidingMenu-aar" }
}


dependencies {
    compile files('libs/ormlite-android-4.48.jar')
    compile files('libs/ormlite-core-4.48.jar')
    compile 'com.android.support:multidex:1.0.1'
    compile 'com.android.support:appcompat-v7:23.2.1'
    compile 'com.android.support:support-v4:23.2.1'
    compile 'com.android.support:support-v13:23.2.1'
    compile 'com.google.code.gson:gson:2.6.2'
    compile 'org.apache.httpcomponents:httpcore:4.4.4'
    compile 'com.android.support:design:23.2.1'
    compile 'com.android.support:preference-v14:23.2.1'
    compile 'com.google.android.gms:play-services-analytics:8.4.0'
    compile 'com.google.android.gms:play-services-identity:8.4.0'
    compile 'com.google.android.gms:play-services-drive:8.4.0'
    compile 'org.apache.commons:commons-io:+'
    compile project(':afilechooser')
    compile project(':simplecropimage')
}

configurations {
    compile.exclude group: "org.apache.httpcomponents", module: "httpclient"
}

和proguard-project.txt是:

-dontwarn android.support.**
-dontwarn com.google.gson.**
-dontwarn com.j256.**
-dontwarn com.actionbarsherlock.**

-assumenosideeffects class android.util.Log {
    public static *** d(...);
    public static *** v(...);
}

-keep class com.j256.**
-keepclassmembers class com.j256.** {*;}
-keep enum com.j256.**
-keepclassmembers enum com.j256.**  {*;}
-keep interface com.j256.**
-keepclassmembers interface com.j256.**  {*;}
-keep interface android.support.**
-keepclassmembers interface android.support.**  {*;}
-keep interface com.mapsaurus.paneslayout.**
-keepclassmembers interface com.mapsaurus.paneslayout.**  {*;}

-keep class com.sh.inv.businessobjects.*
-keepclassmembers class com.sh.inv.businessobjects.* { *; } 

-keep class com.sh.inv.DatabaseHelper
-keepclassmembers class com.sh.inv.inv.DatabaseHelper { *; } 

-keep class com.sh.inv.businessobjects.ws.*
-keepclassmembers class com.sh.inv.businessobjects.ws.* { *; } 

-keep class com.android.vending.billing.*
-keepclassmembers class com.android.vending.billing.* { *; } 

-keep class com.sh.inv.ui.fragment.*
-keepclassmembers class com.sh.inv.ui.fragment.* { *; } 

-keepclassmembers class * { 
  public (android.content.Context); 
} 


-keepattributes Signature
-keepattributes Annotation

-renamesourcefileattribute SourceFile    
-keepattributes SourceFile,LineNumberTable

-keep public class * extends android.app.Fragment
-keep public class * extends android.support.v4.app.DialogFragment
-keep public class * extends com.sh.inv.ui.common.FragmentActivityBase


-keepclassmembers class * extends com.actionbarsherlock.ActionBarSherlock {
    (android.app.Activity, int);
}

#-injars libs

-keep class * extends java.util.ListResourceBundle {
    protected Object[][] getContents();
}

-keep public class com.google.android.gms.common.internal.safeparcel.SafeParcelable {
    public static final *** NULL;
}

-keepnames @com.google.android.gms.common.annotation.KeepName class *
-keepclassmembernames class * {
    @com.google.android.gms.common.annotation.KeepName *;
}

-keepnames class * implements android.os.Parcelable {
    public static final ** CREATOR;
}

它在最后一个版本中运行,但它是一个沉睡的项目,我不得不将它从eclipse迁移到android studio并升级所有引用 也许在导入的库中有一些错误..

此外,我有很多警告,我之前没有关于ormlite或重复定义库的警告

2 个答案:

答案 0 :(得分:0)

添加

android {
    useLibrary 'org.apache.http.legacy'
    lintOptions {
        checkReleaseBuilds false
        abortOnError false
    }
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'
    exclude 'META-INF/ASL2.0'
    exclude 'META-INF/maven/com.squareup.okio/okio/pom.xml'
    exclude 'META-INF/maven/com.squareup.okio/okio/pom.properties'
}
}

答案 1 :(得分:0)

微小的阳光给了我一些线索,最后我找到了答案

我需要删除

compile 'org.apache.httpcomponents:httpcore:4.4.4'

在我的gradle构建配置中,因为它现在集成在android构建工具中(我认为)。我不知道为什么它在调试/发布模式下工作,但在使用proguard进行模糊处理时却不行。