TLDR
java.lang.RuntimeException:无法实例化AndroidPlatform类。
minifyEnabled
和shrinkResources
的App Bundle的 release 版本应与 debug 版本相同。按照Android documentation,在应用程序的 build.gradle 文件中仅适用于 release 版本。
应用程序的 release 版本立即崩溃。这是Firebase库构建App Bundle方式的一个新问题。
在没有minifyEnabled
和shrinkResources
的情况下,应用程序可以按预期的生产方式运行,并且应用程序大小从〜4mb到〜10mb。
错误日志表明这是Firebase兼容性问题-What ProGuard configuration do I need for Firebase on Android?
ProGuard存在类似的问题-transformClassesAndResourcesWithProguardForRelease FAILED。
Fatal Exception: java.lang.RuntimeException: Unable to start activity ComponentInfo{app.coinverse/app.coinverse.MainActivity}: java.lang.RuntimeException: Failed to instantiate AndroidPlatform class. Using ProGuard? See http://stackoverflow.com/questions/26273929/what-proguard-configuration-do-i-need-for-firebase-on-android
at android.app.ActivityThread.performLaunchActivity + 2951(ActivityThread.java:2951)
at android.app.ActivityThread.handleLaunchActivity + 3086(ActivityThread.java:3086)
at android.app.servertransaction.LaunchActivityItem.execute + 78(LaunchActivityItem.java:78)
at android.app.servertransaction.TransactionExecutor.executeCallbacks + 108(TransactionExecutor.java:108)
at android.app.servertransaction.TransactionExecutor.execute + 68(TransactionExecutor.java:68)
at android.app.ActivityThread$H.handleMessage + 1816(ActivityThread.java:1816)
at android.os.Handler.dispatchMessage + 106(Handler.java:106)
at android.os.Looper.loop + 193(Looper.java:193)
at android.app.ActivityThread.main + 6718(ActivityThread.java:6718)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run + 493(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main + 858(ZygoteInit.java:858)
应用程序的 build.gradle
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: "androidx.navigation.safeargs"
apply plugin: 'kotlin-kapt'
apply plugin: 'com.google.gms.google-services'
apply plugin: 'com.google.firebase.firebase-perf'
apply plugin: 'io.fabric'
android {
compileSdkVersion 28
defaultConfig {
applicationId "app.coinverse"
minSdkVersion 24
targetSdkVersion 28
versionCode 37
versionName "0.37"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
javaCompileOptions {
annotationProcessorOptions {
arguments = ["room.schemaLocation": "$projectDir/schemas".toString()]
}
}
}
sourceSets { androidTest.assets.srcDirs += files("$projectDir/schemas".toString()) }
buildTypes {
release {
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'),
'proguard-rules.pro', 'proguard.cfg'
minifyEnabled true
shrinkResources true
}
debug {
applicationIdSuffix ".staging"
debuggable true
}
}
compileOptions { targetCompatibility JavaVersion.VERSION_1_8 }
dataBinding.enabled = true
}
dependencies {
def lifecycle_version = "2.0.0"
def paging_version = "2.1.0"
def nav_version = "1.0.0"
def nav_testing_version = "1.0.0-alpha08"
def room_version = "2.1.0"
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.core:core-ktx:1.0.2'
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.2.0-alpha02'
implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.2.0-alpha02'
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.2.0-alpha02'
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.cardview:cardview:1.0.0'
implementation "androidx.lifecycle:lifecycle-extensions:$lifecycle_version"
kapt "androidx.lifecycle:lifecycle-compiler:$lifecycle_version"
implementation "androidx.lifecycle:lifecycle-common-java8:$lifecycle_version"
implementation "androidx.lifecycle:lifecycle-reactivestreams-ktx:$lifecycle_version"
implementation "androidx.paging:paging-runtime:$paging_version"
implementation "androidx.paging:paging-rxjava2:$paging_version"
implementation 'com.google.android.gms:play-services-auth:17.0.0'
implementation 'com.google.android.gms:play-services-location:17.0.0'
implementation 'com.firebase:firebase-client-android:2.5.2'
implementation 'com.google.firebase:firebase-core:17.0.0'
implementation 'com.crashlytics.sdk.android:crashlytics:2.10.1'
implementation 'com.google.firebase:firebase-perf:18.0.1'
implementation 'com.google.firebase:firebase-firestore:20.1.0'
implementation 'com.google.firebase:firebase-functions:18.0.0'
implementation 'com.google.firebase:firebase-auth:18.0.0'
implementation 'com.firebaseui:firebase-ui-firestore:4.2.0'
implementation 'com.firebaseui:firebase-ui-auth:4.2.1'
implementation 'com.google.firebase:firebase-storage:18.0.0'
implementation 'com.google.firebase:firebase-inappmessaging-display:18.0.1'
implementation 'com.google.firebase:firebase-config:18.0.0'
implementation 'com.jjoe64:graphview:4.2.2'
implementation 'com.google.android.exoplayer:exoplayer-core:2.10.1'
implementation 'com.google.android.exoplayer:exoplayer-ui:2.10.1'
implementation files('libs/YouTubeAndroidPlayerApi.jar')
implementation 'io.reactivex.rxjava2:rxjava:2.2.5'
implementation 'io.reactivex.rxjava2:rxandroid:2.1.0'
implementation "android.arch.navigation:navigation-fragment-ktx:$nav_version"
implementation "android.arch.navigation:navigation-ui-ktx:$nav_version"
implementation "androidx.room:room-runtime:$room_version"
kapt "androidx.room:room-compiler:$room_version"
implementation "androidx.room:room-rxjava2:$room_version"
implementation "androidx.room:room-guava:$room_version"
implementation 'com.github.bumptech.glide:glide:4.9.0'
kapt 'com.github.bumptech.glide:compiler:4.9.0'
implementation('com.mopub:mopub-sdk-native-static:5.6.0@aar') { transitive = true }
implementation('com.mopub:mopub-sdk-native-video:5.6.0@aar') { transitive = true }
implementation 'com.facebook.android:audience-network-sdk:5.1.0'
implementation 'com.mopub.mediation:facebookaudiencenetwork:5.1.0.0'
implementation 'com.flurry.android:ads:11.4.0@aar'
implementation 'com.flurry.android:analytics:11.4.0@aar'
implementation 'com.mopub.mediation:flurry:11.4.0.0'
// Testing
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
testImplementation "androidx.arch.core:core-testing:$lifecycle_version"
androidTestImplementation "android.arch.navigation:navigation-testing:$nav_testing_version"
testImplementation "androidx.room:room-testing:$room_version"
testImplementation "android.arch.persistence.room:testing:$room_version"
}
1-Adding proguard.cfg rules for Firebase。
-keep class com.firebase.** { *; }
-keep class org.apache.** { *; }
-keepnames class com.fasterxml.jackson.** { *; }
-keepnames class javax.servlet.** { *; }
-keepnames class org.ietf.jgss.** { *; }
-dontwarn org.w3c.dom.**
-dontwarn org.joda.time.**
-dontwarn org.shaded.apache.**
-dontwarn org.ietf.jgss.**
# Only necessary if you downloaded the SDK jar directly instead of from maven.
-keep class com.shaded.fasterxml.jackson.** { *; }
2-{{3}}用于应用程序的类。
# Add this global rule
-keepattributes Signature
# This rule will properly ProGuard all the model classes in
# the package com.yourcompany.models. Modify to fit the structure
# of your app.
-keepclassmembers class com.yourcompany.models.** {
*;
}
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules-release.txt'
testProguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules-test.txt'
答案 0 :(得分:0)
我遇到了类似的问题,并且从Fabric完全迁移到Firebase Crashlytics为我解决了该问题:https://firebase.google.com/docs/crashlytics/get-started-new-sdk?platform=android&authuser=0
希望这会有所帮助!