proguard

2019-05-28  本文已影响0人  米米1498

参考资料:
https://mp.weixin.qq.com/s?src=11&timestamp=1559011203&ver=1633&signature=cJ77-Tq4Ff7D8XgEXRUv3VE8L4t-LKfYRenM69nV72taW15NmYFeP7U8aKmRgJqQ7ZvOFrMBk4lpLfGexuEOjThCHZ62IZU91aEVU5ZFCVUp6gj01xmp-I0ybOfRffD9&new=1
https://www.zhihu.com/question/24027474/answer/370741770
https://www.zhihu.com/question/33184477#answer-17942697

image.png
    buildTypes {
        release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            signingConfig signingConfigs.eros
            manifestPlaceholders = [
                    GETUI_APP_ID    : GETUI_APPID,
                    GETUI_APP_KEY   : GETUI_APPKEY,
                    GETUI_APP_SECRET: GETTUI_APPSECRET,
                    APP_ID          : APPLICATION_ID
            ]
        }

        debug {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            signingConfig signingConfigs.eros
            manifestPlaceholders = [
                    GETUI_APP_ID    : GETUI_APPID,
                    GETUI_APP_KEY   : GETUI_APPKEY,
                    GETUI_APP_SECRET: GETTUI_APPSECRET,
                    APP_ID          : APPLICATION_ID
            ]
        }

    }
混淆内容

这些类的名字不能混淆,混淆后xml文件中相关的类找不到它们了。类里面的一些方法,变量是可以混淆的。

-keep public class * extends android.view.View {
    *** get*();
    void set*(***);
    public <init>(android.content.Context);
    public <init>(android.content.Context, android.util.AttributeSet);
    public <init>(android.content.Context, android.util.AttributeSet, int);
}

混淆文件

比如xx*匹配xx222、xx2,但是不匹配xx2.2,而xx**则匹配

# This is a configuration file for ProGuard.
# http://proguard.sourceforge.net/index.html#manual/usage.html
#
# This file is no longer maintained and is not used by new (2.2+) versions of the
# Android plugin for Gradle. Instead, the Android plugin for Gradle generates the
# default rules at build time and stores them in the build directory.

-dontusemixedcaseclassnames
-dontskipnonpubliclibraryclasses
-verbose

# Optimization is turned off by default. Dex does not like code run
# through the ProGuard optimize and preverify steps (and performs some
# of these optimizations on its own).
-dontoptimize
-dontpreverify
# Note that if you want to enable optimization, you cannot just
# include optimization flags in your own project configuration file;
# instead you will need to point to the
# "proguard-android-optimize.txt" file instead of this one from your
# project.properties file.

-keepattributes *Annotation*
-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);
}

-keepclassmembers class * implements android.os.Parcelable {
  public static final android.os.Parcelable$Creator CREATOR;
}

-keepclassmembers class **.R$* {
    public static <fields>;
}

# 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.**

# Understand the @Keep support annotation.
-keep class android.support.annotation.Keep

-keep @android.support.annotation.Keep class * {*;}

-keepclasseswithmembers class * {
    @android.support.annotation.Keep <methods>;
}

-keepclasseswithmembers class * {
    @android.support.annotation.Keep <fields>;
}

-keepclasseswithmembers class * {
    @android.support.annotation.Keep <init>(...);
}

上一篇 下一篇

猜你喜欢

热点阅读