android - 如何为我的 Android 应用程序添加代码混淆

标签 android

如何为 android apk 添加代码混淆。我使用了 proguard 但仍然看到来自应用 decompiler 的代码。

我这样添加了progruad

release {
      debuggable true
      minifyEnabled true
      proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}

它在反编译后看到了我所有的代码和类。 After decomplie

我的 Proguard 文件 enter image description here

最佳答案

使用以下代码获取您的解决方案。

android {
    buildTypes {
            debug {
                minifyEnabled false
                proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
                zipAlignEnabled true
                shrinkResources false
            }
            release {
                debuggable false
                // Enables code shrinking, obfuscation, and optimization for only
                // your project's release build type.
                minifyEnabled true

                // Includes the default ProGuard rules files that are packaged with
                // the Android Gradle plugin. To learn more, go to the section about
                // R8 configuration files.
                proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'

                zipAlignEnabled true

                // Enables resource shrinking, which is performed by the
                // Android Gradle plugin.
                shrinkResources true
            }
        }
     }

TODO 更新混淆器

#Specifies not to ignore non-public library classes.
-dontskipnonpubliclibraryclasses

#Specifies not to ignore package visible library class members
-dontskipnonpubliclibraryclassmembers

-optimizationpasses 5
#Specifies that the access modifiers of classes and class members may have become broad during processing. This can improve the results of the optimization step.
-allowaccessmodification
#Specifies that interfaces may be merged, even if their implementing classes don't implement all interface methods. This can reduce the size of the output by reducing the total number of classes.
-mergeinterfacesaggressively

#Specifies to apply aggressive overloading while obfuscating. Multiple fields and methods can then get the same names, This option can make the processed code even smaller
#-overloadaggressively

#Specifies to repackage all packages that are renamed, by moving them into the single given parent package
-flattenpackagehierarchy

#Specifies to repackage all class files that are renamed, by moving them into the single given package. Without argument or with an empty string (''), the package is removed completely.
-repackageclasses

#For example, if your code contains a large number of hard-coded strings that refer to classes, and you prefer not to keep their names, you may want to use this option
-adaptclassstrings
#Specifies the resource files to be renamed, all resource files that correspond to class files are renamed
-adaptresourcefilenames

#Specifies the resource files whose contents are to be updated. Any class names mentioned in the resource files are renamed
-adaptresourcefilecontents

#Specifies not to verify the processed class files.
#-dontpreverify

-verbose

#Specifies to print any warnings about unresolved references and other important problems, but to continue processing in any case.
-ignorewarnings

# ADDED
#-dontobfuscate
#-useuniqueclassmembernames

# For enumeration classes, see http://proguard.sourceforge.net/manual/examples.html#enumerations
-keepclassmembers enum * {
    public static **[] values();
    public static ** valueOf(java.lang.String);
}

-assumenosideeffects class android.util.Log {
    public static boolean isLoggable(java.lang.String, int);
    public static *** d(...);
    public static *** v(...);
    public static *** i(...);
    public static *** w(...);
    public static *** e(...);
}

关于android - 如何为我的 Android 应用程序添加代码混淆,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57156648/

相关文章:

android - 带有推荐码的 Facebook 应用邀请

android - Selenium 和 Appium 有什么区别?

android - 使用 android :debuggable ="false" 调试 Ionic 应用程序

android - 仿真器无法加载 "libGLES_emulation"驱动程序

Android:监听 Activity onDestroy()

java - 安卓。使用 Java 测试 Wordpress 登录成功。

android - 以编程方式设置稀松布颜色

Android Studio 无法解析 aar 中的类,即使它们位于 arr/classes.jar 中

android - 如果没有互联网可用,如何将 ContentView 设置为另一个 Fragment,如果连接可用,如何设置 Resume Fragment

java - 比较字符串时忽略正则表达式