0
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'

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


android {
    compileSdkVersion 22
    buildToolsVersion "22.0.1"

    defaultConfig {
        applicationId "com.android.hello"
        minSdkVersion 9
        targetSdkVersion 21
        compileOptions {
            sourceCompatibility JavaVersion.VERSION_1_7
            targetCompatibility JavaVersion.VERSION_1_7
        }
    }

    buildTypes {
        release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile 'com.android.support:support-v4:22.2.0'
    compile 'com.google.code.gson:gson:2.2.4'
    compile 'com.android.support:appcompat-v7:22.2.0'
    compile 'com.google.android.gms:play-services:+'
    compile files('libs/bolts-android-1.2.0.jar')
    compile files('libs/facebook.jar')
    compile 'de.hdodenhof:circleimageview:1.2.1'
    compile 'com.android.support:recyclerview-v7:21.0.+'
    compile 'com.android.support:cardview-v7:21.0.+'
    compile 'com.github.bumptech.glide:glide:3.5.2'
    compile 'com.android.support:support-v4:22.0.0'
    compile 'com.jakewharton:butterknife:6.1.0'
    compile('com.crashlytics.sdk.android:crashlytics:2.4.0@aar') {
        transitive = true;
    }

    compile project(':gcmv')
    compile 'com.android.support:design:22.2.0'
}

when i signing my app app through a key with "minify true" in gradle it crashes after finishes. but when i set "minify false" it works fine after signing. so tell me is there any addition in the gradle file to release the with "minify true" property. For your reference i add the gradle file and my proguard file.

# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in C:\Users\UMANH\AppData\Local\Android\sdk/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the proguardFiles
# directive in build.gradle.
#
# For more details, see
#   http://developer.android.com/guide/developing/tools/proguard.html

# Add any project specific keep options here:

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
#   public *;
#}
-optimizations !code/simplification/arithmetic,!code/simplification/cast,!field/*,!class/merging/*
-optimizationpasses 5
-allowaccessmodification
-dontpreverify

# The remainder of this file is identical to the non-optimized version
# of the Proguard configuration file (except that the other file has
# flags to turn off optimization).

-dontusemixedcaseclassnames
-dontskipnonpubliclibraryclasses
-verbose

-keepattributes *Annotation*
-keepattributes Signature
-keep public class com.google.vending.licensing.ILicensingService
-keep public class com.android.vending.licensing.ILicensingService

# For native methods, see http://proguard.sourceforge.net/manual/examples.html#native
-keepclasseswithmembernames class * {
    native <methods>;
}

# keep setters in Views so that animations can still work.
# see http://proguard.sourceforge.net/manual/examples.html#beans
-keepclassmembers public class * extends android.view.View {
   void set*(***);
   *** get*();
}

# We want to keep methods in Activity that could be used in the XML attribute onClick
-keepclassmembers class * extends android.app.Activity {
   public void *(android.view.View);
}

# For enumeration classes, see http://proguard.sourceforge.net/manual/examples.html#enumerations
-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>;
}

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

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

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

-keep public class * implements com.bumptech.glide.module.GlideModule
-keep public enum com.bumptech.glide.load.resource.bitmap.ImageHeaderParser$** {
    **[] $VALUES;
    public *;
}
-keep public class android.support.v7.widget.** { *; }
-keep public class android.support.v7.internal.widget.** { *; }
-keep public class android.support.v7.internal.view.menu.** { *; }

-keep class android.support.v4.app.** { *; }
-keep interface android.support.v4.app.** { *; }

-keep public class * extends android.support.v4.view.ActionProvider {
    public <init>(android.content.Context);
}

-keepattributes EnclosingMethod

# Gson specific classes
-keep class sun.misc.Unsafe { *; }
-keep class com.google.gson.stream.** { *; }

-keep class android.support.v7.widget.RoundRectDrawable { *; }

-keepclassmembers class fqcn.of.javascript.interface.for.webview { public *;}

-keep class com.crashlytics.** { *; }
-dontwarn com.crashlytics.**

-dontwarn android.support.design.**
-keep class android.support.design.** { *; }
-keep interface android.support.design.** { *; }
-keep public class android.support.design.R$* { *; }

-keep public class android.** {*;}
-keep public class com.google.android.** {*;}


-keep class com.facebook.** {*;}
# The support library contains references to newer platform versions.
# Don't warn about those in case this app is linking against an older
# platform version.  We know about them, and they are safe.
-dontwarn android.support.**
-dontwarn com.facebook.**
-dontwarn com.squareup.okhttp.**
Umang
  • 63
  • 10

1 Answers1

1

You need to configure your rules for proguard

For Example ButterKnife

Butter Knife generates and uses classes dynamically which means that static analysis tools like ProGuard may think they are unused. In order to prevent them from being removed, explicitly mark them to be kept. To prevent ProGuard renaming classes that use @Bind on a member field the keepclasseswithmembernames option is used.

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

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

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

For Glide

-keep public class * implements com.bumptech.glide.module.GlideModule

-keep public enum com.bumptech.glide.load.resource.bitmap.ImageHeaderParser$** {
    **[] $VALUES;
    public *;
}

For gson

https://google-gson.googlecode.com/svn/trunk/examples/android-proguard-example/proguard.cfg

Similarly do this for all other external libraries which requires defining these rules. You can check their websites or github project home page

Where to add all the above

The getDefaultProguardFile('proguard-android.txt') method obtains the default ProGuard settings from the Android SDK tools/proguard/ folder.

The proguard-android-optimize.txt file is also available in this Android SDK folder with the same rules but with optimizations enabled.

proguard-rules.pro refers to the one under your project structure.

Having the rules defined will prevent obfuscating class names which will avoid crash.

Raghunandan
  • 132,755
  • 26
  • 225
  • 256
  • Look @ proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' in your gradle file – Raghunandan Jul 31 '15 at 07:15
  • okk if i change it proguard-rules.pro to proguard-android-optimize.txt it will work for me or not – Umang Jul 31 '15 at 07:19
  • @Umang that is not the problem . You just need to define rules so that proguard will not obfuscate your class names. Do you have the rules defined for all your libraries mentioned? – Raghunandan Jul 31 '15 at 07:20
  • no i dont have rules for the above mentioned libraries. Can you please provide me the rules of these libraries. – Umang Jul 31 '15 at 07:23
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/84766/discussion-between-umang-and-raghunandan). – Umang Jul 31 '15 at 07:26
  • not woking added all the rules but still my problem as it is. – Umang Jul 31 '15 at 08:25