Signed apk getting crashed in proguard enable
Asked Answered
D

4

12

I am trying to use proguard in my app set the proguard to true and then the problem starts I am importing lib when I use proguard by following this -keepnames class com.somepackage.* with my package name the app is getting getting crashed when I try to use the signed apk. I know this iS a dumb question but I am stuck at this for last 5 hr not able to find an easy solution as I am using about 20 lib. I followed this also. Plz guide me in this how can I do this?

This is my proguard rule class code

-keepnames class beatbox.neelay.dummybeat.*
-keepnames com.srx.widget.*
-keepnames de.hdodenhof.circleimageview.CircleImageView.*
-keepnames com.bumptech.glide.*
-keepnames com.romainpiel.shimmer.*
-keepnames com.vansuita.gaussianblur.GaussianBlur
-keepnames com.antonyt.infiniteviewpager.InfinitePagerAdapter
-keepnames com.antonyt.infiniteviewpager.InfiniteViewPager
-keepnames com.eftimoff.viewpagertransformers.CubeOutTransformer
-keepnames com.ms.square.android.glassview.GlassView
-keepnames me.alexrs.fontpagertitlestrip.lib.FontPagerTitleStrip

I am not able to generate any signed apk now . the error is.

Error:Execution failed for task ':app:transformClassesAndResourcesWithProguardForRelease'.

Job failed, see logs for details

any hint will be helpful. console output

FAILURE: Build failed with an exception.
  • What went wrong: Execution failed for task ':app:transformClassesAndResourcesWithProguardForRelease'.

    Job failed, see logs for details

  • Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

Editing build.gradle

apply plugin: 'com.android.application'

android {
compileSdkVersion 25
buildToolsVersion "25.0.1"
defaultConfig {
    applicationId "beatbox.neelay.dummybeat"
    minSdkVersion 16
    targetSdkVersion 25
    versionCode 1
    versionName "1.0"
    renderscriptTargetApi 24
    renderscriptSupportModeEnabled true
    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

    vectorDrawables.useSupportLibrary = true
}
lintOptions {
    checkReleaseBuilds false
    abortOnError false
}
buildTypes {
    release {
        shrinkResources true
        minifyEnabled true
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}
}

repositories {
jcenter()
mavenCentral()
maven { url "https://jitpack.io" }
maven { url 'http://Manabu-GT.github.com/GlassView/mvn-repo' }
}

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'
})
compile project(':foldingtabbar')
compile 'com.android.support:appcompat-v7:25.2.0'
compile 'com.android.support.constraint:constraint-layout:1.0.0-alpha7'
compile 'com.android.support:design:25.2.0'
compile 'com.github.bumptech.glide:glide:3.7.0'
compile 'com.intuit.sdp:sdp-android:1.0.4'
compile 'com.leo.simplearcloader:simplearcloader:1.0.1'
compile 'com.ms.square:glassview:0.1.0'
compile 'de.hdodenhof:circleimageview:2.1.0'
compile 'com.romainpiel.shimmer:library:1.4.0@aar'
compile 'com.github.StephenVinouze:ShapeView:1.1.0'
compile 'com.eftimoff:android-viewpager-transformers:1.0.1@aar'
compile 'com.github.antonyt:InfiniteViewPager:v1.0.0'
compile 'me.alexrs:font-pager-titlestrip:1.0.0'
compile 'com.github.florent37:arclayout:1.0.1'
compile 'com.android.support:cardview-v7:25.1.0'
compile 'com.android.support:support-v4:25.1.0'
compile 'com.github.jrvansuita:GaussianBlur:v1.0.2'
compile 'com.google.code.gson:gson:2.7'
compile 'com.android.support:support-vector-drawable:25.2.0'
testCompile 'junit:junit:4.12'
}

another way i tried for proguard-rule.pro

-keepnames class beatbox.neelay.dummybeat.**{*;}
-keepnames class com.srx.widget.**{*;}
-keepnames class de.hdodenhof.circleimageview.CircleImageView.**{*;}
-keepnames class com.bumptech.glide.**{*;}
-keepnames class com.romainpiel.shimmer.**{*;}
-keepnames class com.vansuita.gaussianblur.**{*;}
-keepnames class com.antonyt.infiniteviewpager.**{*;}
-keepnames class com.eftimoff.viewpagertransformers.**{*;}
-keepnames class com.ms.square.android.glassview.**{*;}
-keepnames class me.alexrs.fontpagertitlestrip.lib.FontPagerTitleStrip**{*;}

the dependency tree

Detach answered 17/5, 2017 at 18:38 Comment(13)
log don't show any thing bro that's the issue otherwise i added almost every thingDetach
the data is getting loaded from the system but then the app crash with no logDetach
Do you have the right console visible?Lorenzo
see the update question sorry i dont getting in the starting now i do know.plz guide meDetach
Run ./gradlew --stacktrace :app:transformClassesAndResourcesWithProguardForRelease and see what you get there.Softa
Can you tell me how to properly set the proguard for the class it will be helpfulDetach
Please show your full proguard and build.gradle files. Generally this issues occurs due to some libraries or classes in your projectPurism
@HarisQureshi see the question nowDetach
Try to change all support lib to same version 25.2.0 or 25.1.0 . you are using both right nowIllbred
Can you provide complete stacktrace as wellIllbred
when i used the first proguard rule it throw an error during apk build but when i run the proguard withe the new rules it dont show any error .But when testing the apk it crash.Detach
You can consider DexGuard, it's more secure & easy to integrate according to them. From makers of proguard.Ecumenism
thx sir let me try that one also .@Ecumenism will i have to set the library like in proguard also??Detach
A
4

Reason : Not every Class or Library are optimized with Proguard enabled , So what Proguard do is that it removes classes if they are not optimize which results crash and bugs in project.

Solution : In your proguard.cfg file keep that classes or library which are not supported by progaurd . Try the catch all described here :
Try adding :

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


Or , if you are using v4 lib :

-dontwarn android.support.v4.**
-keep class android.support.v4.** { *; }
-dontwarn android.support.v7.**
-keep class android.support.v7.** { *; }


If you are using latest android studio you might found this as proguard-rules.pro


In your case try using -dontwarn as well with classname. Like your error show that it can not optimize circleimageview Library . so try to add this as well :

-dontwarn hdodenhof.**
-keep class hdodenhof.**


If still not working than downgrade your circleimageview library :
compile 'de.hdodenhof:circleimageview:1.3.0' This is working for me.

Alkane answered 26/5, 2017 at 10:23 Comment(4)
sir will i have to declare the lib that is used only in xml form like card view lib and other libraryDetach
sir i added the dependency tree can you plz check it nowDetach
@Detach Yes you have to if it is not optimized by Proguard .. it will give you some warning about your library in logs .. It doesn't matter you are using it in your xml or classes , it will get compiled along with other classes and library .Alkane
bhai i tried as you said but it is still getting crashes when running as you said can tell me how to declare the lib here is my dependency tree gist.github.com/neelayak/ef0fa83f9397c34eac0ac9cf60aa02a3Detach
S
2

1) Keep all annotations

-keepattributes SourceFile,LineNumberTable,*Annotation*,EnclosingMethod,Signature,Exceptions,InnerClasses

2) Keep if you have any pojos or models and classes which are using for network call

Ex:

-keep class com.example.android.models.**
-keepclassmembers class com.example.android.models.** {
      *;
}
-keepclassmembers class com.example.android.network.** {
  public void set*(***);
  public *** get*();
  public *** is*();
}

3) For all the libraries you are using keep below proguard rules

Ex:

-dontwarn com.zl.reik.dilatingdotsprogressbar.**
-keep class com.zl.reik.dilatingdotsprogressbar.**{*;}
-keep interface com.zl.reik.dilatingdotsprogressbar.**{*;}

You even need to keep similar proguard rules for "foldingtabbar", as It is also a library

If the above solution does not solve, run ./gradlew app:dependencies in your repository and Send me the list of dependencies

Since answered 25/5, 2017 at 3:34 Comment(1)
sir i added the dependency tree can you plz check it nowDetach
M
1

Having the same version for all the support libraries is also very important. Sometimes libraries have recursive dependencies, where each has a different version which can lead to this error. Run:

./gradlew app:dependencies

to see the dependencies for each library and check whether they all have the same version. I already see, that you use 25.1.0 and 25.2.0 versions of support libraries. In addition, some of your libraries are old, thus, they probably use old versions.

Try to use:

-keep class beatbox.neelay.dummybeat.**{*;}
-dontwarn beatbox.neelay.dummybeat.**

instead of:

-keepnames beatbox.neelay.dummybeat.**{*;}
Multiple answered 23/5, 2017 at 12:28 Comment(3)
Sir where i have to use ./gradlew app:dependencies i tried to find it in console gradel but not able to findDetach
navigate to your project folder with cmd (command line) and run the commandMultiple
Sir i tried but it is still getting crashed can you give me a sample from my dependency tree gist.github.com/neelayak/ef0fa83f9397c34eac0ac9cf60aa02a3Detach
E
0

Proguard removes classes which are part of dependencies added the app. Try to keep them using:

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

Disable warning for dependency classes:

-dontwarn hdodenhof.**
-dontwarn android.support.v4.**
-dontwarn android.support.v7.**
Eldridgeeldritch answered 29/5, 2017 at 5:35 Comment(3)
Where should I add this?Ivoryivorywhite
@Ivoryivorywhite You should add these in app/proguard-rules.pro fileEldridgeeldritch
I did but I still get this error Execution failed for task ':app:transformClassesAndResourcesWithProguardForRelease'. The error has started to occur after I added maven { url "jitpack.io" } to build.gradle which is required for react-native-spark-button. Can you please guide how I can resolve this?Ivoryivorywhite

© 2022 - 2024 — McMap. All rights reserved.