KSA
KSA

Reputation: 101

Proguard Obfuscation in Android Studio 3.3.2

Does obfuscation work if minifyEnabled and shrinkResources is kept false?

build.gradle:

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

When I enable the two, I get warnings when building signed apk:

okhttp3.internal.platform.conscryptplatform: can't find referenced class org.conscrypt.OpenSSLProvider

I tried to ignore okhttp in proguard using:

-dontwarn okhttp3.internal.platform.*

which successfully generated an apk but once installed the app crashes multiple times, logcat:

    java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.res.Resources android.content.Context.getResources()' on a null object reference
        at android.widget.Toast.<init>(Toast.java:102)
        at android.widget.Toast.makeText(Toast.java:260)
        at com.example.talks.f$1$1.a_(Unknown Source)
        at com.google.android.gms.d.c.dv.a(Unknown Source)
        at com.google.android.gms.d.c.fr.a(Unknown Source)
        at com.google.android.gms.d.c.fy.run(Unknown Source)
        at android.os.Handler.handleCallback(Handler.java:751)
        at android.os.Handler.dispatchMessage(Handler.java:95)
        at android.os.Looper.loop(Looper.java:154)
        at android.app.ActivityThread.main(ActivityThread.java:6077)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:756)

So I'm thinking of not using minify and shrinkResources!

Upvotes: 0

Views: 353

Answers (1)

straya
straya

Reputation: 5059

Proguard Obfuscation will not be performed if minifyEnabled is set to false. shrinkResources requires proguard, so if you want to shrink resources then you must also have minifyEnabled set to true.

You should aim to have minifyEnabled set to true. You need to customise your proguard-rules.pro file and keep testing until you get the right mix. It can be a daunting task, especially if you are applying it ad-hoc to a complex app, however it is important and shouldn't be avoided (well it depends on the risks associated with your system).

E.g. for OkHttp, you need more rules. Do more searching and reading.

Upvotes: 1

Related Questions