Google Play发布后应用异常:R8混淆及release分支问题求助
Google Play发布后应用异常问题排查记录
无法理解为何代码在release分支发布至Google Play后无法正常运行,具体排查过程如下:
- 步骤1:开启
minifyEnabled true并配置proguard-rules.pro文件,添加-keep public class myClassName规则保留指定类,本地debug和release构建均正常,但上传至Google Play内部测试分支后应用失效。 - 步骤2:设置
minifyEnabled false,上传至内部测试分支后应用恢复正常;将该版本同步至release分支发布后,应用再次失效,表现为仿佛混淆仍在启用,出现变量加密异常、函数参数错误导致崩溃等问题,尽管proguard-rules.pro规则配置无误。 - 步骤3:直接将关闭混淆的版本上传至release分支,问题依旧。
相关配置文件代码
<1> app模块build.gradle
plugins { id 'com.android.application' } apply plugin: 'com.android.application' apply plugin: 'com.google.gms.google-services' // Apply the Crashlytics Gradle plugin apply plugin: 'com.google.firebase.crashlytics' repositories { mavenCentral() } android { compileSdkVersion 33 buildToolsVersion "30.0.3" defaultConfig { applicationId "com.my.app" minSdkVersion 23 targetSdkVersion 33 versionCode 40 versionName "1.0" setProperty("archivesBaseName", applicationId + "-v" + versionCode + "(" + versionName + ")") testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" } buildTypes { release { minifyEnabled true proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' } debug { minifyEnabled true proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' } } compileOptions { sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 } buildFeatures { viewBinding true } packagingOptions { resources { excludes += ['META-INF/DEPENDENCIES', 'META-INF/LICENSE', 'META-INF/LICENSE.txt', 'META-INF/license.txt', 'META-INF/NOTICE', 'META-INF/NOTICE.txt', 'META-INF/notice.txt', 'META-INF/ASL2.0'] } } namespace 'com.my.app' } dependencies { //firebase auth implementation platform('com.google.firebase:firebase-bom:29.1.0') implementation 'com.google.firebase:firebase-auth:21.1.0' // google implementation 'com.google.android.play:core:1.10.3' implementation 'com.google.android.gms:play-services-games:23.0.0' implementation 'com.google.android.gms:play-services-auth:20.3.0' //firebase-crashlytics implementation 'com.google.firebase:firebase-crashlytics:18.3.1' implementation 'com.google.firebase:firebase-analytics:21.2.0' //google billing implementation "com.android.billingclient:billing:5.0.0" implementation "com.android.volley:volley:1.2.1" //default implementation 'com.google.code.gson:gson:2.8.9' implementation 'com.nex3z:flow-layout:1.3.3' implementation 'androidx.recyclerview:recyclerview:1.2.1' implementation 'androidx.preference:preference:1.2.0' implementation 'androidx.appcompat:appcompat:1.5.1' implementation 'com.google.android.material:material:1.7.0' implementation 'androidx.constraintlayout:constraintlayout:2.1.4' implementation 'org.jetbrains:annotations:16.0.1' implementation 'androidx.legacy:legacy-support-v4:1.0.0' //JUnit 4 Test testImplementation 'org.junit.jupiter:junit-jupiter:5.8.2' androidTestImplementation 'androidx.test.ext:junit:1.1.3' androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0' implementation "androidx.lifecycle:lifecycle-viewmodel:2.5.1" implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:2.5.1" }
<2> 根目录build.gradle
buildscript { repositories { google() mavenCentral() } dependencies { classpath 'com.android.tools.build:gradle:7.3.1' classpath 'com.google.gms:google-services:4.3.14' classpath 'com.google.firebase:firebase-crashlytics-gradle:2.9.2' classpath 'com.google.android.libraries.mapsplatform.secrets-gradle-plugin:secrets-gradle-plugin:2.0.1' } } allprojects { repositories { mavenCentral() google() } task clean(type: Delete) { delete rootProject.buildDir }
<3> proguard-rules.pro
-keep public class myClassName
内容的提问来源于stack exchange,提问作者user238664
相关产品推荐
相关产品推荐

