使用Proguard时出错

时间:2017-02-07 06:44:52

标签: android android-gradle build.gradle

我试图在我的应用中实现proguard,但我无法做到。我启用了minifyEnabled和shrinkResources。这是我的build.gradle文件:

buildscript {
repositories {
    maven { url 'https://maven.fabric.io/public' }
}

dependencies {
    classpath 'io.fabric.tools:gradle:1.+'
}
}
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
apply plugin: 'android-apt'

repositories {
maven { url 'https://maven.fabric.io/public' }
}

apply plugin: 'com.neenbedankt.android-apt'

android {
signingConfigs {
    testSigned {
        keyAlias 'test'
        keyPassword 'testing123'
        storePassword 'testing123'
        //storeFile file('C:/Users/Motobeans/Desktop/testSignedArchitecture.jks')
    }
}
compileSdkVersion rootProject.ext.compileSdkVersion
buildToolsVersion rootProject.ext.buildToolsVersion
defaultConfig {
    applicationId "in.mylo.pregnancy.baby.app"
    minSdkVersion rootProject.ext.minSdkVersion
    targetSdkVersion rootProject.ext.targetSdkVersion
    versionCode rootProject.ext.versionCode
    versionName rootProject.ext.versionName
    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    multiDexEnabled true
}
buildTypes {
    debug {
        shrinkResources false // This must be first
        minifyEnabled false   // This must be after shrinkResources
        multiDexEnabled true
        proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
    }
    release {
        shrinkResources false
        minifyEnabled false
        multiDexEnabled true
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}

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/LICENSE.txt'
    exclude 'META-INF/NOTICE.txt'
    exclude 'META-INF/DEPENDENCIES'
    exclude 'META-INF/notice.txt'
    exclude 'META-INF/license.txt'
    exclude 'META-INF/dependencies.txt'
    exclude 'META-INF/LGPL2.1'
}
compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_7
    targetCompatibility JavaVersion.VERSION_1_7
}

}

dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
    exclude group: 'com.android.support', module: 'support-annotations'
})
testCompile 'junit:junit:4.12'
// Multidex support
compile 'com.android.support:multidex:1.0.1'
// Android Support Libraries
compile "com.android.support:appcompat-v7:$rootProject.supportLibraryVersion"
compile "com.android.support:cardview-v7:$rootProject.supportLibraryVersion"
compile "com.android.support:support-v4:$rootProject.supportLibraryVersion"
compile "com.android.support:design:$rootProject.supportLibraryVersion"
compile "com.android.support:recyclerview-v7:$rootProject.supportLibraryVersion"
compile "com.android.support:palette-v7:$rootProject.supportLibraryVersion"
/*
 * Guava is a set of core libraries that includes new collection types (such as multimap and multiset),
 * immutable collections, a graph library, functional types, an in-memory cache, and APIs/utilities for concurrency,
 * I/O, hashing, primitives, reflection, string processing, and much more!
 */
compile "com.google.guava:guava:$rootProject.guavaVersion"
// BugFender (logging to server)
compile 'com.bugfender.sdk:android:0.6.2'
// Timber (Logging library)
compile 'com.jakewharton.timber:timber:4.3.1'
// Dagger Dependency
compile 'com.google.dagger:dagger:2.7'
apt 'com.google.dagger:dagger-compiler:2.7'
compile 'javax.annotation:javax.annotation-api:1.2'
// Retrofit
compile 'com.squareup.retrofit2:retrofit:2.1.0'
compile 'com.squareup.retrofit2:converter-gson:2.1.0'
compile 'com.squareup.retrofit2:adapter-rxjava:2.1.0'
//RxAndroid
compile 'io.reactivex:rxandroid:1.2.1'
compile 'io.reactivex:rxjava:1.1.6'
// Logging Interceptor
compile 'com.squareup.okhttp3:logging-interceptor:3.4.1'
// Crash Handler : Show custom activity
compile 'cat.ereza:customactivityoncrash:1.5.0'
// EasyImage - Image picker from Gallery or Camera
compile 'com.github.jkwiecien:EasyImage:1.3.1'
//Marshmallow Permission Library
compile('com.github.afollestad:assent:0.2.0') {
    transitive = true
}
// jakewharton butterknief library
compile 'com.jakewharton:butterknife:8.1.0'
apt 'com.jakewharton:butterknife-compiler:8.1.0'

// Jakewharton byte library
compile 'com.jakewharton.byteunits:byteunits:0.9.1'
// Glide - Image Loading Library
compile 'com.github.bumptech.glide:glide:3.7.0'

// Leak canary (A memory leak detection library for Android and Java)
debugCompile 'com.squareup.leakcanary:leakcanary-android:1.5'
releaseCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.5'

// EventBus
compile 'org.greenrobot:eventbus:3.0.0'

// Marshmallow Permission Library
compile('com.github.afollestad:assent:0.2.0') {
    transitive = true
}

// Ripple Layout Activity Transition
compile 'com.liuguangqiang.ripplelayout:library:0.1.0'

// Fabric Crashlytics
compile('com.crashlytics.sdk.android:crashlytics:2.6.6@aar') {
    transitive = true;
}

// Circular ImageView
compile 'de.hdodenhof:circleimageview:1.2.1'

// View pager
compile 'com.ogaclejapan.smarttablayout:library:1.6.1@aar'

// Crescento Curve container
compile 'com.github.developer-shivam:crescento:1.0.1'

// Shape Image View
compile 'com.github.siyamed:android-shape-imageview:0.9.+@aar'
//compile 'com.github.siyamed:android-shape-imageview:0.9.+@aar'

// Fonts
compile 'me.anwarshahriar:calligrapher:1.0'

//Google Sign In
/*  compile 'com.google.android.gms:play-services-auth:9.8.0'
compile 'com.google.android.gms:play-services:9.8.0'*/
/*
    compile 'com.google.android.gms:play-services-auth:10.0.1'
*/

// Branch.io
compile 'io.branch.sdk.android:library:2.+'

// Branch + Segment Integration library
compile 'com.weiwangcn.betterspinner:library:1.1.0'

//segment and clevertap
compile 'com.segment.analytics.android:analytics:4.+'
compile 'com.clevertap.android:clevertap-segment-android:+'

//segment and branch
compile 'io.branch.segment.analytics.android.integrations:branch:+'

// Loader View
compile 'com.elyeproj.libraries:loaderviewlibrary:1.2.2'

// Animation
compile 'com.eftimoff:androidplayer:1.0.3@aar'
compile 'com.nineoldandroids:library:2.4.0'

compile 'com.ogaclejapan.smarttablayout:library:1.6.1@aar'

//Custom Chrome tab
compile 'com.android.support:customtabs:25.0.1'

// Epoxy Adapter
compile 'com.airbnb.android:epoxy:1.5.0'

//mixpanel
compile "com.mixpanel.android:mixpanel-android:4.+"

// firebase//Add this line
compile 'com.google.firebase:firebase-core:9.6.1'
compile 'com.google.firebase:firebase-messaging:9.6.1'
compile 'com.google.android.gms:play-services:9.6.1'
compile 'com.thefinestartist:ytpa:1.2.1'
compile 'com.caverock:androidsvg:1.2.1'

// Flow layout
compile 'org.apmem.tools:layouts:1.10@aar'
// Text Drawable
compile 'com.amulyakhare:com.amulyakhare.textdrawable:1.0.1'
compile 'pl.bclogic:pulsator4droid:1.0.3'

//Tune
compile 'com.tune:tune-marketing-console-sdk:4.9.0'

// Pug notification
compile 'com.github.halysongoncalves:pugnotification:1.8.1'

compile 'com.facebook.android:facebook-android-sdk:4.+'
}
apply plugin: 'com.google.gms.google-services'

以下是我得到的错误图片: enter image description here

enter image description here

错误代码太大,以至于我决定发布图片而不是代码。感谢任何帮助,提前谢谢

2 个答案:

答案 0 :(得分:2)

首先纠正您的 debug release 部分。

 buildTypes
 {
    debug {
     shrinkResources true // This must be first 
     minifyEnabled true   // This must be after shrinkResources 
      proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
    }
    release {
     shrinkResources true // This must be first 
     minifyEnabled true   // This must be after shrinkResources 
      proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
    }

 }

有关详细信息,请 Read Errors while building APK Android Studio

答案 1 :(得分:0)

将每个依赖项的例外添加到proguard-rules.pro文件中。但是,某些依赖项不需要proguard规则。

例如,因为您使用retrofit,所以您需要添加以下内容:

# Platform calls Class.forName on types which do not exist on Android to determine platform.
-dontnote retrofit2.Platform
# Platform used when running on RoboVM on iOS. Will not be used at runtime.
-dontnote retrofit2.Platform$IOS$MainThreadExecutor
# Platform used when running on Java 8 VMs. Will not be used at runtime.
-dontwarn retrofit2.Platform$Java8
# Retain generic type information for use by reflection by converters and adapters.
-keepattributes Signature
# Retain declared checked exceptions for use by a Proxy instance.
-keepattributes Exceptions

到你的proguard文件