带有proguard的Android应用程序在发布时崩溃
Posted
技术标签:
【中文标题】带有proguard的Android应用程序在发布时崩溃【英文标题】:Android App crashes on release with proguard 【发布时间】:2019-09-25 19:31:54 【问题描述】:当我创建 发布版本 时,我的 应用程序 崩溃。该应用程序正常运行,突然之间发生了这种情况。我在BaseActivity.java
MultiDex.install(this);
中有这条线我已经尝试了 SO 的多个选项,但没有一个有效。该错误也没有提供足够的详细信息,或者我无法找到发生此问题的点。任何帮助将不胜感激。
这里是堆栈跟踪。
E/androidRuntime: FATAL EXCEPTION: main
Process: com.packagename, PID: 10136
java.lang.VerifyError: Verifier rejected class android.support.multidex.MultiDex: void android.support.multidex.MultiDex.<init>() failed to verify: void android.support.multidex.MultiDex.<init>(): [0x0] Constructor returning without calling superclass constructor (declaration of 'android.support.multidex.MultiDex' appears in /data/app/com.packagename-4uitso2MKAahWwylc8ZTtA==/base.apk!classes2.dex)
at android.support.multidex.MultiDex.install(MultiDex.java:95)
at com.packagename.baseactivity.BaseActivity.attachBaseContext(BaseActivity.java:43)
at android.app.Application.attach(Application.java:224)
at android.app.Instrumentation.newApplication(Instrumentation.java:1128)
at android.app.LoadedApk.makeApplication(LoadedApk.java:1162)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6607)
at android.app.ActivityThread.access$2000(ActivityThread.java:268)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1995)
at android.os.Handler.dispatchMessage(Handler.java:109)
at android.os.Looper.loop(Looper.java:207)
at android.app.ActivityThread.main(ActivityThread.java:7539)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:524)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:958)
这是我的 build.gradle
apply plugin: 'com.android.application'
android
signingConfigs
release
keyAlias 'packagename'
keyPassword 'packagename'
storeFile file('E:/Projects/packagenameFile')
storePassword 'packagename'
debug
keyAlias 'packagename'
keyPassword 'packagename'
storeFile file('E:/Projects/packagenameFile')
storePassword 'packagename'
compileSdkVersion 28
defaultConfig
applicationId "com.packagename"
minSdkVersion 14
targetSdkVersion 28
versionCode 15
versionName "4.2.3.5"
multiDexEnabled true
manifestPlaceholders = [onesignal_app_id : "d4d1ertet4339b4f3b96",
// Project number pulled from dashboard, local value is ignored.
onesignal_google_project_number: "10434356698637306"]
dexOptions
javaMaxHeapSize "4g"
buildTypes
release
multiDexEnabled true
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
debuggable false
jniDebuggable false
signingConfig signingConfigs.release
renderscriptDebuggable false
pseudoLocalesEnabled false
debug
multiDexEnabled true
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.release
dependencies
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.google.android.gms:play-services-maps:16.1.0'
implementation 'com.android.support:recyclerview-v7:28.0.0'
implementation 'com.android.support:design:28.0.0'
// below 3 libs are for one Signal
implementation 'com.onesignal:OneSignal:3.+@aar'
implementation 'com.google.android.gms:play-services-gcm:16.1.0'
implementation 'com.google.android.gms:play-services-location:16.0.0'
//SMS auto retriever API
implementation "com.google.android.gms:play-services-auth:16.0.1"
//firebase analytics
implementation "com.google.firebase:firebase-core:16.0.8"
//Network calls
implementation 'com.squareup.okhttp3:okhttp:3.12.1'
//PDF Reader
implementation 'com.github.barteksc:android-pdf-viewer:2.4.0'
//for creating demos.
implementation 'uk.co.samuelwall:material-tap-target-prompt:2.0.1'
//displays charts.
implementation project(':MPChartLib')
//Kotlin
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
// Sql Cipher
implementation 'net.zetetic:android-database-sqlcipher:4.1.3@aar'
apply plugin: 'com.google.gms.google-services'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
更新了 Proguard 规则
# 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 fqcn.of.javascript.interface.for.webview
# 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.
-dontpreverify
-repackageclasses ''
-allowaccessmodification
-optimizations !code/simplification/arithmetic
-keepattributes *Annotation*
-keepattributes EnclosingMethod
-keepattributes InnerClasses
-dontwarn org.xmlpull.v1.**
-dontwarn android-support-v4.**
-dontwarn com.crashlytics.**
-keep class com.google.android.gms.** *;
-dontwarn com.google.android.gms.**
-keep public class com.google.** *;
-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
-keepattributes Signature
-keepattributes SourceFile,LineNumberTable
-dontwarn android.support.v7.**
-keep class android.support.v7.** *;
-keep interface android.support.v7.** *;
-dontwarn android.support.design.**
-keep class android.support.design.** *;
-keep interface android.support.design.** *;
-keep public class android.support.design.R$* *;
-keep class android.support.design.widget.** *;
-keep interface android.support.design.widget.** *;
-dontwarn android.support.design.**
-keep class yourpakganame.itemdecorator
-keep public class * extends android.support.v7.widget.RecyclerView.ItemDecoration
-keep class android.support.v7.widget.RecyclerView
-assumenosideeffects class android.util.Log*;
#1 to
-assumenosideeffects class * implements Interface
public <init>();
public Object interfacemethod(); # May concern methods with same signature in other Objects
#end
-keep class net.sqlcipher.** *;
-dontwarn net.sqlcipher.**
-dontwarn OneSignalSDK.**
-dontwarn com.amazon.**
-dontwarn com.crashlytics.**
-keep class android.support.** *;
-dontnote android.support.**
-dontwarn android.support.**
-keep class com.firebase.** *;
-keep class org.apache.** *;
-keepnames class com.fasterxml.jackson.** *;
-keepnames class javax.servlet.** *;
-keepnames class org.ietf.jgss.** *;
-dontwarn okhttp3.**
-dontwarn okio.**
-keep class okhttp3.** *;
-dontwarn org.apache.**
-dontwarn org.w3c.dom.**
-dontwarn org.joda.time.**
-dontwarn org.shaded.apache.**
-keep class com.crashlytics.** *;
-keep class com.shockwave.**
-keepclassmembers class com.shockwave.** *;
-keep class com.google.firebase.example.fireeats.model.** *;
-keepclassmembers class com.getbase.floatingactionbutton.FloatingActionsMenu$RotatingDrawable
void set*(***);
*** get*();
【问题讨论】:
在 gradle 依赖中添加implementation 'com.android.support:multidex:1.0.3'
已经尝试但同样的问题。
按照下面的android官方文章,你很高兴。 developer.android.com/studio/build/multidex>
我已经用 multidex 尝试了所有选项。
在此处发布您的proguard
【参考方案1】:
来自here
从你的 proguard 文件中删除以下行
#1 to
-assumenosideeffects class * implements Interface
public <init>();
public Object interfacemethod(); # May concern methods with same signature in other Objects
#end
然后替换
-assumenosideeffects class android.util.Log*;
有
-assumenosideeffects class android.util.Log
public static *** v(...);
public static *** d(...);
public static *** i(...);
public static *** w(...);
public static *** e(...);
public static *** wtf(...);
【讨论】:
以上是关于带有proguard的Android应用程序在发布时崩溃的主要内容,如果未能解决你的问题,请参考以下文章
带有 proguard 的 Android ant build.xml 未在发行版中构建
带有外部 jar 的 Proguard 错误 - 返回错误代码 1