Android app和aar混淆方法
app混淆方法
1.在build.gradle中,将minifyEnabled设置为true以开启混淆。
apply plugin: 'com.android.application'
android {
compileSdkVersion 29
buildToolsVersion "29.0.3"
defaultConfig {
applicationId "com.xxx.xxx"
minSdkVersion 14
targetSdkVersion 29
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
//将minifyEnabled置为true,开启混淆
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
}
2.在proguard-rules.pro中编写混淆规则。
3.编译生成release版的app
aar包生成和混淆方法
1.为了生成aar文件,需要修改build.gradle文件,将com.android.application更改为com.android.library,并注释掉applicationId。另外,需要将minifyEnabled设置为true以开启混淆。
//将com.android.application修改为com.android.library
apply plugin: 'com.android.library'
android {
compileSdkVersion 29
buildToolsVersion "29.0.3"
defaultConfig {
//去掉applicationId
//applicationId "com.xxx.xxx"
minSdkVersion 14
targetSdkVersion 29
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
//将minifyEnabled置为true,开启混淆
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
}
2.在proguard-rules.pro中编写混淆规则。
3.点击android studio右侧的Gradle按钮,双击assembleRelease,开始编译release版的aar包。

4.编译成功后,在build->outputs->aar目录下即可看到混淆过的release版aar包。

2万+



被折叠的 条评论
为什么被折叠?



