如何正确混淆代码在android工作室?



我试图混淆debug构建在android工作室花栗鼠(buildToolsVersion "30.0.3", compileSdkVersion 32, targetSdkVersion 32, gradle:7.2.1)。我在我的构建中有以下代码。gradle文件,

buildTypes {
release {
minifyEnabled false//todo add proguard rules for every dependencies before setting this to true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
debug {
minifyEnabled true//todo add proguard rules for every dependencies before setting this to true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}

这是我的程序规则。支持文件,

# 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 com.mypackagename.helpers.JavascriptInterface {
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

-printconfiguration /Users/sujith/Desktop/R8/full-r8-config.txt
-dontwarn com.yalantis.ucrop**
-keep class com.yalantis.ucrop** { *; }
-keep interface com.yalantis.ucrop** { *; }

我的项目包含以下库,

implementation 'androidx.appcompat:appcompat:1.4.2'
implementation 'com.google.android.material:material:1.6.1'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation 'androidx.navigation:navigation-fragment-ktx:2.4.2'
implementation 'androidx.navigation:navigation-ui-ktx:2.4.2'
implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.4.1'
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.4.1'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
//added by me
implementation 'androidx.preference:preference-ktx:1.2.0'
implementation "androidx.viewpager2:viewpager2:1.0.0"
implementation 'com.google.android.gms:play-services-auth:20.2.0'
implementation 'com.google.android.gms:play-services-ads:21.0.0'
implementation 'com.google.firebase:firebase-iid:21.1.0'
implementation 'com.google.firebase:firebase-messaging:23.0.5'
implementation "androidx.cardview:cardview:1.0.0"
implementation 'com.github.bumptech.glide:glide:4.12.0'
implementation('io.socket:socket.io-client:2.0.0') {
exclude group: 'org.json', module: 'json'
}
implementation 'com.github.ismaeldivita:chip-navigation-bar:1.3.4'
implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0'
implementation 'androidx.core:core-splashscreen:1.0.0-rc01'
implementation 'com.hbb20:ccp:2.6.0'//country code picker
implementation 'com.google.android.flexbox:flexbox:3.0.0'
implementation 'com.github.yalantis:ucrop:2.2.6-native'
implementation 'com.github.chrisbanes:PhotoView:2.0.0'
//
classpath 'io.realm:realm-gradle-plugin:10.10.1'

当我构建项目时,会生成mapping.txt和full-r8-config.txt。但是,当我用ShowJava android应用程序反编译应用程序时,我仍然可以看到代码中的所有内容。完全没有变化。我想保留所有第三方库,只混淆我的代码。我怎样才能做到这一点呢?谢谢你。

如果你正在创建一个签名的APK构建,你不会遇到这样的问题,但你的代码也需要更新

useProguard真正

buildTypes {
release {
minifyEnabled false//todo add proguard rules for every dependencies 
before setting this to true
useProguard true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 
'proguard-rules.pro'
}
debug {
minifyEnabled true//todo add proguard rules for every dependencies 
before setting this to true
useProguard true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 
'proguard-rules.pro'
}
}

添加到proguard-rules.pro

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

还将这行添加到gradle.properties

android.enableR8 = true

希望这对你有帮助。

相关内容

  • 没有找到相关文章

最新更新