0

In my application I enabled progurad by minifyEnabled true and progurad rules I didn't added,I build the signed in apk then it is crashing in the lauching only then I thought that, I have to add the classes which has not to be minfied. then I added progurd rules like -keep public class * extends android.app.Activity, then also it is not working, I don't know why, becuase it depends on other files like views and R files all. So my doubt is When I enabled progurad I have to add all my classes and libraries in progurad rules,or it will minify other classes and made as will not work.So how can I add all the classes without crashing app when it build signed in apk After adding in proguard rules also it is crashing the app Add project specific ProGuard rules here.

> -keep public class * extends android.app.Activity
> -keep public class * extends android.app.Application
> -keep public class * extends android.support.v7.app.AppCompatActivity
> -keep public class * extends android.content.BroadcastReceiver
> -keep public class * extends android.content.ContentProvider
> -keep public class * extends android.preference.Preference
> -keep public class android.os.AsyncTask
> -keep public class * extends android.view.View {
>     public <init>(android.content.Context);
>     public <init>(android.content.Context, android.util.AttributeSet);
>     public <init>(android.content.Context, android.util.AttributeSet, int); }
> -keepclasseswithmembers class * {
>     public <init>(android.content.Context, android.util.AttributeSet); }
> -keepclasseswithmembers class * {
>     public <init>(android.content.Context, android.util.AttributeSet, int); }
> -keepclassmembers class * extends android.content.Context {
>     public void *(android.view.View);
>     public void *(android.view.MenuItem); }
> # The official support library.
> -keep class android.support.v4.app.** { *; }
> -keep interface android.support.v4.app.** { *; }
> -keep class android.support.v7.app.** { *; }
> -keep interface android.support.v7.app.** { *; }
> -dontwarn android.support.**

How can I test an app with proguard release build, is there anything to check direclty signed in apk or I have to add any mapping files.How can I test direct release apk or If that apk upload into playstore then it will work based on mapping files

Hanuman
  • 958
  • 13
  • 35
  • 1
    this question has the answers you need: http://stackoverflow.com/questions/18259632/should-i-use-proguard – Bill Jul 15 '16 at 12:41

3 Answers3

1

I found some solution kind of, when we direct install direct release apk with minified then the code will be minified(obfuscated), so app will not know what is these kind of code, so it will crash when directly install release apk.

So what my solution is after releasing the apk upload into playstore and upload the mappings file under the build\outputs\mapping\release\mapping.txt file into the playstore so download the app from playstore then it may works, in mapping file all the mapping classes will be there.so that time it will not crash.uploading mapping file into playstore https://support.google.com/googleplay/android-developer/answer/6295281?hl=en I didn't tried, but if anyone tries then let me know to edit the answer

Hanuman
  • 958
  • 13
  • 35
0

In my proguard file everything is commented out and it works just fine with minifyEnabled true. Have you tried something like this:

proguard-rules.pro:

# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in C:\Users\<yourUser>\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 *;
#}

And my gradle looks like:

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

Edit: Other solutions: https://stackoverflow.com/a/6492478

Community
  • 1
  • 1
AZOM
  • 265
  • 5
  • 15
  • have u created any signedin apk like release build, then in that build it is crashing – Hanuman Jul 15 '16 at 13:04
  • after releasing build just check whether is it working or not(install and check) and check the debug apk and release apk size it will differ very much – Hanuman Jul 15 '16 at 13:29
0

This is what documentation simply said about Proguard.

To make your APK file as small as possible, you should enable shrinking to remove unused code and resources in your release build. This page describes how to do that and how to specify what code and resources to keep or discard during the build.

Code shrinking is available with ProGuard, which detects and removes unused classes, fields, methods, and attributes from your packaged app, including those from included code libraries (making it a valuable tool for working around the 64k reference limit). ProGuard also optimizes the bytecode, removes unused code instructions, and obfuscates the remaining classes, fields, and methods with short names.

I have read a nice post about it so you should also read it from here

If you want to know about how practically use it then this answer may be helpful to you and if you want suggestion about when to use it then see this answer.

Community
  • 1
  • 1
TapanHP
  • 5,969
  • 6
  • 37
  • 66