Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to define the obfuscation rules of Android APK packaging code

2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly introduces the Android APK packaging code confusion rules how to define the relevant knowledge, the content is detailed and easy to understand, the operation is simple and fast, has a certain reference value, I believe that after reading this Android APK packaging code confusion rules how to define the article will have a harvest, let's take a look at it.

Step 1: configure custom obfuscation rules in the proguard-rules.pro file under the project directory

# Note: # 1. Referencing external jar packages is best not to confuse them if you don't write them yourself, because external jar packages may have confused # 2. Do not confuse the custom control classes used in the XML layout. Loading the layout after confusion will report that the control error # 3. Do not confuse the component classes configured in Manifests After confusion, the system will find an error because the component cannot be found #-# specify the compression level of the code-optimizationpasses confusion means that mixed case class names are not used in confusion The obfuscated class name is lowercase-dontusemixedcaseclassnames# means no optimization This option is recommended because, as described in proguard-android-optimize.txt, optimization may pose some potential risks and is not guaranteed to work properly on all versions of Dalvik. -output log when dontoptimize# obfuscation-the algorithm used in verbose# obfuscation is generally unchanged, but can be calculated with Google recommendation.-optimizations! codeCompact simplification.output log when obfuscation occurs. ! class/merging/*# does not confuse the subclasses of these classes and does not need to confuse system components, etc.-keep public class * extends android.app.Activity-keep public class * extends android.app.Application-keep public class * extends android.app.Service-keep public class * extends android.content.BroadcastReceiver-keep public class * extends android.content.ContentProvider-keep public class * extends android.app.backup.BackupAgentHelper-keep public class * extends android.preference.Preference-keep public class com.android.vending.licensing.ILicensingService# Indicates that there is no confusion between the class name of any class that contains native methods and the native method name-keepclasseswithmembernames class * {native } # means not to confuse the setXxx () and getXxx () methods in any View, because attribute animation needs to be implemented with corresponding setter and getter methods, so it won't work if you're confused. -keepclassmembers public class * extends android.view.View {void set* (*); * get* ();} # means not to confuse the method that the parameter in Activity is View, because there is a way to configure the android:onClick= "buttonClick" property in XML, and when the user clicks the button, the buttonClick (View view) method in Activity is called, and if this method is confused, it cannot be found. -keepclassmembers class * extends android.app.Activity {public void * (android.view.View);} # means that the values () and valueOf () methods in the enumeration are not confused-keepclassmembers enum * {public static * * [] values (); public static * * valueOf (java.lang.String) } # means not to confuse the CREATOR field in the Parcelable implementation class. There is no doubt that the CREATOR field must not be changed, including case, or the whole Parcelable working mechanism will fail. -keepclassmembers class * implements android.os.Parcelable {public static final android.os.Parcelable$Creator CREATOR;} # does not confuse all the static fields in the R file. We all know that the R file records the id of each resource through fields. If the field name is confused, id will not be able to find it. -keepclassmembers class * * .Renewal * {public static;} # keep custom control classes from being confused-keepclasseswithmembers class * {public (android.content.Context, android.util.AttributeSet);} # keep custom control classes from being confused-keepclasseswithmembers class * {public (android.content.Context, android.util.AttributeSet, int);} # filter out entity classes you write and custom control classes-keepclass com.beacon.supertool.bean.** {* }-keep class com.beacon.supertool.widget.** {*;} # No need to confuse third-party libraries-dontwarn android.support.v4.** # remove warnings-keep class android.support.v4.** {*;} # filter android.support.v4-keep interface android.support.v4.app.** {* }-keep public class * extends android.support.v4.**-keep public class * extends android.app.Fragment# need not confuse butterknife-dontwarn butterknife.**-keep class butterknife.** {*;} # do not need to confuse gson-dontwarn com.google.**-keep class com.google.gson.** {*;} # do not need to confuse glide-dontwarn com.bumptech.glide.**-keep class com.bumptech.glide.** {* } # No need to confuse okhttp3 okio-dontwarn okhttp3.**-keep class okhttp3.** {*;}-dontwarn okio.**-keep class okio.** {*;} # there is no need to confuse third-party libraries or jar. Step 2: modify buildTypes {/ / debug version configuration debug {versionNameSuffix "- debug" minifyEnabled false zipAlignEnabled false shrinkResources false signingConfig signingConfigs.debug} / / release version configuration release {/ / do not display Log buildConfigField "boolean" in the build.gradle file under the project directory "LOG_DEBUG", "false" / / confuse minifyEnabled true / / Zipalign optimized zipAlignEnabled true / / remove useless resource file shrinkResources true proguardFiles getDefaultProguardFile ('proguard-android.txt') This is the end of the article on "how to define the obfuscation rules for Android APK packaging codes" in 'proguard-rules.pro'}}. Thank you for reading! I believe that everyone has a certain understanding of the knowledge of "how to define the confusion rules of Android APK packaging code". If you want to learn more knowledge, you are welcome to follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report