cheng cheng - 5 months ago 80
Android Question

Android - App Crashing With Proguard Enabled

When i using Proguard release app, run apk file then crash.This is my build.grade and Proguard-rules.pro file.

build.grade

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


android {
compileSdkVersion 24
buildToolsVersion "23.0.3"

defaultConfig {
applicationId "cheng.cunghoangdao.cungbachduong"
minSdkVersion 15
targetSdkVersion 24
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}

dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:24.0.0'
compile 'com.android.support:design:24.0.0'
compile 'com.github.noobknight:app:1.0.0'
compile 'com.jakewharton:butterknife:8.1.0'
apt 'com.jakewharton:butterknife-compiler:8.1.0'
compile 'com.android.support:cardview-v7:24.0.0'
compile 'org.jsoup:jsoup:1.9.1'
compile 'com.github.bumptech.glide:glide:3.7.0'
compile 'com.jpardogo.googleprogressbar:library:1.2.0'
compile files('libs/apache-commons-lang.jar')
compile 'com.davemorrissey.labs:subsampling-scale-image-view:3.5.0'
compile 'com.facebook.android:facebook-android-sdk:4.+'
compile 'com.google.android.gms:play-services-analytics:9.2.0'
compile 'com.google.firebase:firebase-messaging:9.2.0'
compile project(':library')
}
apply plugin: 'com.google.gms.google-services'


Proguard-rules.pro

-dontusemixedcaseclassnames
-dontskipnonpubliclibraryclasses
-keepattributes Signature
-optimizationpasses 5
-dontusemixedcaseclassnames
-dontskipnonpubliclibraryclasses
-dontpreverify
-verbose
-dontwarn android.support.**
-dontwarn com.instagram.common.json.**
-dontwarn com.fasterxml.jackson.databind.ext.DOMSerializer
-dontwarn com.squareup.javawriter.JavaWriter
-dontwarn com.google.common.primitives.UnsignedBytes*
-dontwarn sun.misc.Unsafe
-dontwarn javax.annotation.**
-dontwarn com.squareup.picasso.**
-dontwarn okio.Okio.**
-dontoptimize
-dontpreverify
-optimizations !code/simplification/arithmetic,!field/*,!class/merging/*

-keepattributes *Annotation*
-keep public class * extends android.app.Activity
-keep public class * extends android.app.Application
-keep public class * extends android.app.Service
-keep public class * extends android.content.BroadcastReceiver
-keep public class * extends android.content.ContentProvider
-keep public class com.google.vending.licensing.ILicensingService
-keep public class com.android.vending.licensing.ILicensingService
-keep public class * extends android.support.v4.app.Fragment
-keep public class * extends android.app.Fragment

-keep class android.support.v7.internal.** { *; }
-keep interface android.support.v7.internal.** { *; }
-keep class android.support.v7.** { *; }
-keep interface android.support.v7.** { *; }

# Facebook library
-keep class com.facebook.** {
*;
}

-dontwarn com.squareup.okhttp.**


-keep class butterknife.** { *; }
-dontwarn butterknife.internal.**
-keep class **$$ViewBinder { *; }

-keepclasseswithmembernames class * {
@butterknife.* <fields>;
}

-keepclasseswithmembernames class * {
@butterknife.* <methods>;
}

-keepclasseswithmembernames class * {
native <methods>;
}

-keepclasseswithmembernames class * {
public <init>(android.content.Context, android.util.AttributeSet);
}

-keepclasseswithmembernames class * {
public <init>(android.content.Context, android.util.AttributeSet, int);
}

-keepclassmembers public class * extends android.view.View {
void set*(***);
*** get*();
}

-keepclassmembers enum * {
public static **[] values();
public static ** valueOf(java.lang.String);
}

-keep class * implements android.os.Parcelable {
public static final android.os.Parcelable$Creator *;
}

-keepclassmembers class **.R$* {
public static <fields>;
}


I think config missing library in proguard-reles.pro . Please suggest for me...

Answer

Proguard removes classes if they are not explicitly

Use this:

-keep class xxxx, keep class yyyy, etc

Check all classes.