您现在的位置是:首页 > 前端 > UnityUnity

Unity安卓打包混淆代码

Tdou2021-08-02【Unity】人已围观

简介User Proguard File
用户混淆文件
在启用的情况下,可以使用混淆文件来缩小和优化应用程序。
文件位置:Assets/Plugins/Android/proguard-user.txt。

# Add project specific

User Proguard File
用户混淆文件
在启用的情况下,可以使用混淆文件来缩小和优化应用程序。
文件位置:Assets/Plugins/Android/proguard-user.txt。

 
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
#   http://developer.android.com/guide/developing/tools/proguard.html

# 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 *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile

#-----------基本配置--------------
# 代码混淆压缩比,在0~7之间,默认为5,一般不需要改
-optimizationpasses 5

# 混淆时不使用大小写混合,混淆后的类名为小写
-dontusemixedcaseclassnames

# 指定不去忽略非公共的库的类
-dontskipnonpubliclibraryclasses

# 指定不去忽略非公共的库的类的成员
-dontskipnonpubliclibraryclassmembers

# 不做预校验,可加快混淆速度
# preverify是proguard的4个步骤之一
# Android不需要preverify,去掉这一步可以加快混淆速度
-dontpreverify

# 不优化输入的类文件
-dontoptimize

# 把混淆的类放入默认包名中
-repackageclasses

# 混淆时生成日志文件,即映射文件
-verbose

# 指定映射文件的名称
-printmapping proguardMapping.txt

#混淆时所采用的算法
-optimizations !code/simplification/arithmetic,!field/*,!class/merging/*

# 保护代码中的Annotation不被混淆
-keepattributes *Annotation*

# 忽略警告
-ignorewarnings

# 保护泛型不被混淆
-keepattributes Signature

# 抛出异常时保留代码行号
-keepattributes SourceFile,LineNumberTable
#重命名抛出异常时的文件名称
-renamesourcefileattribute SourceFile

#-----------需要保留的东西--------------
# 保留所有的本地native方法不被混淆
-keepclasseswithmembernames class * {
    native <methods>;
}
#反射用到的类不混
-keepattributes EnclosingMethod
#内部类
#-keepattributes InnerClasses

# WebView
-keepclassmembers class fqcn.of.javascript.interface.for.Webview {
   public *;
}
-keepclassmembers class * extends android.webkit.WebViewClient {
    public void *(android.webkit.WebView, java.lang.String, android.graphics.Bitmap);
    public boolean *(android.webkit.WebView, java.lang.String);
}
-keepclassmembers class * extends android.webkit.WebViewClient {
    public void *(android.webkit.WebView, jav.lang.String);
}

#去掉System.out.println 和System.out.print输出
 -assumenosideeffects class java.io.PrintStream {
      public *** println(...);
      public *** print(...);
 }
  #去掉log日志
 -assumenosideeffects class android.util.Log {
        public static boolean isLoggable(java.lang.String,int);
        public static int v(...);
        public static int i(...);
        public static int w(...);
        public static int d(...);
       public static int e(...);
 }

# 保留实体类和成员不被混淆(根据具体情况修改entity的路径)

#不混淆所有类名中包含了“model”的类及其成员
#-keep class **.*Model*.** {*;}
#-keep class **.*Bean*.** {*;}
#-keep class **.*Entity*.** {*;}
-keep class **.vo.** {*;}
-keep class **.dao.** {*;}
#-keep class **.bean.**{*;}
-keep class **.db.**{*;}

#----------------常用的第三方类库的混淆------------------------------------
#eventbus
-keepclassmembers class ** {
    @de.greenrobot.event.Subscribe <methods>;
}
-keep enum org.greenrobot.eventbus.ThreadMode { *; }

-keepclassmembers class ** {
    @org.greenrobot.eventbus.Subscribe <methods>;
}
-keep enum de.greenrobot.event.ThreadMode { *; }

#过滤okhttp
-dontwarn com.squareup.okhttp3.**
-keep class com.squareup.okhttp3.** { *;}
-dontwarn okio.**

#过滤glide
-keep public class * implements com.bumptech.glide.module.GlideModule
-keep public class * extends com.bumptech.glide.module.AppGlideModule
-keep public enum com.bumptech.glide.load.ImageHeaderParser$** {
  **[] $VALUES;
  public *;
}

#retrofit
-dontwarn okio.**
-dontwarn javax.annotation.**

# rxjava
-keep class rx.schedulers.Schedulers {
    public static <methods>;
}
-keep class rx.schedulers.ImmediateScheduler {
    public <methods>;
}
-keep class rx.schedulers.TestScheduler {
    public <methods>;
}
-keep class rx.schedulers.Schedulers {
    public static ** test();
}
-keepclassmembers class rx.internal.util.unsafe.*ArrayQueue*Field* {
    long producerIndex;
    long consumerIndex;
}
-keepclassmembers class rx.internal.util.unsafe.BaseLinkedQueueProducerNodeRef {
    long producerNode;
    long consumerNode;
}


#解决使用Retrofit+rxJava联网时,在6.0系统出现java.lang.InternalError奔溃的问题:http://blog.csdn.net/mp624183768/article/details/79242147
-keepclassmembers class rx.internal.util.unsafe.*ArrayQueue*Field* {
    long producerIndex;
    long consumerIndex;
}
-keepclassmembers class rx.internal.util.unsafe.BaseLinkedQueueProducerNodeRef {
    rx.internal.util.atomic.LinkedQueueNode producerNode;
}
-keepclassmembers class rx.internal.util.unsafe.BaseLinkedQueueConsumerNodeRef {
    rx.internal.util.atomic.LinkedQueueNode consumerNode;
}
# Gson
# For using GSON @Expose annotation
-dontwarn sun.misc.**
-keep class com.google.gson.** { *; }
-keep interface com.google.gson.**{*;}
# Gson specific classes
#-keep class sun.misc.Unsafe { *; }
#-keep class com.google.gson.stream.** { *; }
# Application classes that will be serialized/deserialized over Gson
#-keep class com.google.gson.examples.android.model.** { *; }
# Prevent proguard from stripping interface information from TypeAdapterFactory,
# JsonSerializer, JsonDeserializer instances (so they can be used in @JsonAdapter)
#-keep class * implements com.google.gson.TypeAdapterFactory
#-keep class * implements com.google.gson.JsonSerializer
#-keep class * implements com.google.gson.JsonDeserializer



#greendao3.2.0,此是针对3.2.0,如果是之前的,可能需要更换下包名
-keep class freemarker.** { *; }
-dontwarn freemarker.**keepatrributes
-dontwarn org.greenrobot.greendao.**

-keep class org.greenrobot.greendao.**{*;}

-keepclassmembers class * extends org.greenrobot.greendao.AbstractDao {
public static java.lang.String TABLENAME;
}
-keep class **$Properties
 #Keep custom exceptions (opt)
-keep public class * extends java.lang.Exception
-keep class com.crashlytics.** { *; }
-dontwarn com.crashlytics.**
-keep class org.pjsip.pjsua2** {*;}
-keep public class com.anythink.network.admob.*
-keepclassmembers class com.anythink.network.admob.* {
<fields>;
<methods>;
}


-dontwarn com.anythink.**
-keep class com.anythink.**
-keep public class com.anythink.network.**
-keepclassmembers class com.anythink.network.** {
   public *;
}

-keep class com.tiptop.utils.** { *; }
-dontwarn com.tiptop.utils.**


#-----------------------全局混淆-----------------------
#除了项目目录,其他都不混淆,这种写法只能有一行,请自行改成自己的包路径,如果再加一行com.li.*会导致全部都不混淆②
-keep class !encore.money.** {*;}
#-keep class !com.li.** {*;}写2行会导致全部不混淆
-dontwarn **

-keep class com.bun.miitmdid.core.** {*;}

-keepclassmembers class * extends androidx.work.Worker {
    public <init>(android.content.Context,androidx.work.WorkerParameters);
}

#-------------------自定义忽略混淆-------------------------

-keep class com.facebook.** {*;}


代码设置混淆模式
//EditorUserBuildSettings.androidDebugMinification = AndroidMinification.Proguard;
//EditorUserBuildSettings.androidReleaseMinification = AndroidMinification.Proguard;





友情链接

  • https://blog.csdn.net/qq_41973169/article/details/109222387

Tags:

很赞哦! ()

  • 微信收款码
  • 支付宝收款码
打赏

文章评论

站点信息

  • 建站时间:2019-12-11
  • 网站程序:帝国CMS7.5
  • 主题模板《今夕何夕》
  • 文章统计64篇文章
  • 标签管理标签云
  • 统计数据百度统计
  • 微信公众号:扫描二维码,关注我们