Proguard google play services jar

2019-06-04 21:26发布

I'm trying to obfuscate google play services jar with proguard. I tried two versions of the proguard config file.

  1. First one contains

    -keep class ** {
        public protected *;
    }
    

And the jar stays not obfuscated. It looks ok.

  1. Second one contains

    -keep class com.** {
        public protected *;
    }
    

And proguard deletes everithing. I get an error:

    Error: The output jar is empty. Did you specify the proper '-keep' options?

Why is it empty, as the main google play services package is com.google.android.gms?

1条回答
男人必须洒脱
2楼-- · 2019-06-04 22:08

The following ProGuard configuration shrinks the Google Play Services jar, without optimization or obfuscation, keeping only the ads-related API:

-injars  android-sdk/extras/google/google_play_services/libproject/google-play-services_lib/libs/google-play-services.jar
-outjars google-play-services-ads.jar

-libraryjars android-sdk/extras/android/support/v4/android-support-v4.jar
-libraryjars android-sdk/platforms/android-20/android.jar

-verbose
-forceprocessing
-dontoptimize
-dontobfuscate
-dontwarn com.google.**.R
-dontwarn com.google.**.R$*
-dontnote

-keep public class com.google.ads.** {
    public protected *;
}

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

-keep class com.google.android.gms.common.internal.safeparcel.SafeParcelable {
    java.lang.String NULL;
}

It reduces the original jar from 2819 classes to 409 classes (2.7M to 476K). I haven't tested the result yet. If any removed classes are accessed by reflection, they need to be kept in the configuration as well.

查看更多
登录 后发表回答