发布 APK 似乎破坏了 Firebase 功能
Release APK seems to break Firebase functionality
我开发基于 Firebase 的社交应用已有一段时间了。该应用程序运行良好,当我注意到每个人(除了我)都不断出现莫名其妙的崩溃时。我认为这是因为该应用程序是围绕开源代码构建的,所以我从头开始。同样,该应用程序运行良好,但我一发布它,就开始发生类似的莫名其妙的崩溃。此时我意识到崩溃只发生在发布 APK 中。据我所知,所有这些崩溃都与 Firebase 有关。其中大多数是 NullPointerExceptions
,其中一些数据在发布 APK 中为 Null,但在具有完全相同用例的测试版本中不是 Null。
我通过正确实施 multidex 设法解决了这些神秘崩溃之一(我之前没有正确实施,我认为这导致了其中一个问题)。问题仍然存在。我已经完全转向 ProGuard,因为我怀疑这可能是问题之一。 ProGuard 之前被禁用,但现在我添加了这些行,只是为了确定:
-dontoptimize
-dontshrink
-dontusemixedcaseclassnames
-dontskipnonpubliclibraryclasses
-dontpreverify
-verbose
仍然崩溃。
这有点麻烦了。什么可以解决这个问题?
这是我的 Build.gradle。
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion "25.0.0"
defaultConfig {
applicationId "app.id"
minSdkVersion 16
targetSdkVersion 25
versionCode 16
versionName "0.0.16"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
renderscriptTargetApi 24
renderscriptSupportModeEnabled true
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
dataBinding {
enabled = true
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:multidex:1.0.1'
compile 'com.android.support:recyclerview-v7:25.3.1'
compile 'com.android.support:design:25.3.1'
compile 'com.android.support:support-v4:25.3.1'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
compile 'com.google.android.gms:play-services:11.0.1'
compile 'com.google.firebase:firebase-messaging:11.0.1'
compile 'com.google.firebase:firebase-auth:11.0.1'
compile 'com.google.firebase:firebase-database:11.0.1'
compile 'com.google.firebase:firebase-storage:11.0.1'
compile 'com.firebaseui:firebase-ui-auth:2.0.1'
[loads more dependencies]
testCompile 'junit:junit:4.12'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.6.0'
}
apply plugin: 'com.jakewharton.butterknife'
apply plugin: 'com.google.gms.google-services'
这个问题已经在一个新项目上消失了。这是我为避免这种情况所做的事情。
- 切换到 Android Studio 3.0 (Canary 7),包括新的构建工具
- 切换到 Kotlin 作为我的主要项目语言
- 确保我的项目的 build.gradle 没有给出关于不同版本的错误通知(使用项目文件视图)。 Firebase UI 导致了这些错误之一。
- 一起避免了 MultiDex
其中任何一个都可能解决了问题。我不确定我可以避免使用 multidex 多长时间,但如果我发现 MultiDex 是问题所在和/或找到替代解决方案,我会更新此答案。
我开发基于 Firebase 的社交应用已有一段时间了。该应用程序运行良好,当我注意到每个人(除了我)都不断出现莫名其妙的崩溃时。我认为这是因为该应用程序是围绕开源代码构建的,所以我从头开始。同样,该应用程序运行良好,但我一发布它,就开始发生类似的莫名其妙的崩溃。此时我意识到崩溃只发生在发布 APK 中。据我所知,所有这些崩溃都与 Firebase 有关。其中大多数是 NullPointerExceptions
,其中一些数据在发布 APK 中为 Null,但在具有完全相同用例的测试版本中不是 Null。
我通过正确实施 multidex 设法解决了这些神秘崩溃之一(我之前没有正确实施,我认为这导致了其中一个问题)。问题仍然存在。我已经完全转向 ProGuard,因为我怀疑这可能是问题之一。 ProGuard 之前被禁用,但现在我添加了这些行,只是为了确定:
-dontoptimize
-dontshrink
-dontusemixedcaseclassnames
-dontskipnonpubliclibraryclasses
-dontpreverify
-verbose
仍然崩溃。
这有点麻烦了。什么可以解决这个问题?
这是我的 Build.gradle。
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion "25.0.0"
defaultConfig {
applicationId "app.id"
minSdkVersion 16
targetSdkVersion 25
versionCode 16
versionName "0.0.16"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
renderscriptTargetApi 24
renderscriptSupportModeEnabled true
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
dataBinding {
enabled = true
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:multidex:1.0.1'
compile 'com.android.support:recyclerview-v7:25.3.1'
compile 'com.android.support:design:25.3.1'
compile 'com.android.support:support-v4:25.3.1'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
compile 'com.google.android.gms:play-services:11.0.1'
compile 'com.google.firebase:firebase-messaging:11.0.1'
compile 'com.google.firebase:firebase-auth:11.0.1'
compile 'com.google.firebase:firebase-database:11.0.1'
compile 'com.google.firebase:firebase-storage:11.0.1'
compile 'com.firebaseui:firebase-ui-auth:2.0.1'
[loads more dependencies]
testCompile 'junit:junit:4.12'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.6.0'
}
apply plugin: 'com.jakewharton.butterknife'
apply plugin: 'com.google.gms.google-services'
这个问题已经在一个新项目上消失了。这是我为避免这种情况所做的事情。
- 切换到 Android Studio 3.0 (Canary 7),包括新的构建工具
- 切换到 Kotlin 作为我的主要项目语言
- 确保我的项目的 build.gradle 没有给出关于不同版本的错误通知(使用项目文件视图)。 Firebase UI 导致了这些错误之一。
- 一起避免了 MultiDex
其中任何一个都可能解决了问题。我不确定我可以避免使用 multidex 多长时间,但如果我发现 MultiDex 是问题所在和/或找到替代解决方案,我会更新此答案。