【发布时间】:2019-11-22 17:31:32
【问题描述】:
我一直在尝试使用具有 Firestore 实现的 Android Studio 构建一个简单的应用程序。当我将以下行添加到我的 build.gradle 文件中时
implementation 'com.google.firebase:firebase-firestore:21.3.0'
应用程序甚至没有构建并引发以下错误:
cannot fit request class in a single dex file
我查看了这个问题,发现 this Stackoverflow page 建议将 MultiDex 添加到应用程序。这允许应用程序构建,但是当我尝试在模拟器中运行它时它会崩溃。我检查了日志文件,但它们不包含有关崩溃的任何信息。
当然,当我删除 Firestore 和 MultiDex SDK 时,应用程序会完美构建和运行。
编辑:这是添加了 Firestore 和 MultiDex 的 app\build.gradle 文件
apply plugin: 'com.android.application'
android {
compileSdkVersion 29
buildToolsVersion "29.0.2"
defaultConfig {
applicationId "com.main.myapp"
minSdkVersion 16
targetSdkVersion 29
versionCode 1
// MultiDex is enabled
multiDexEnabled true
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'com.google.android.material:material:1.0.0'
implementation 'androidx.annotation:annotation:1.1.0'
implementation 'androidx.lifecycle:lifecycle-extensions:2.1.0'
implementation 'com.google.firebase:firebase-auth:16.0.5'
// These two cause the app to crash
implementation 'com.android.support:multidex:2.0.1'
implementation 'com.google.firebase:firebase-firestore:21.3.0'
implementation 'com.google.firebase:firebase-functions:19.0.1'
implementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.3.60'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
implementation 'com.google.android.gms:play-services-ads:18.2.0'
}
apply plugin: 'com.google.gms.google-services'
有人知道问题是什么吗?任何解决方案将不胜感激。
【问题讨论】:
-
向我们展示您添加 MultiDex 的文件。
-
@AlexMamo 我添加了 build.gradle 文件
-
您还需要至少编辑
manifest中的应用程序名称字段,并可选择创建自己的MultiDexApplication类。 -
我怀疑您确实记录了错误,但应用程序正在重新启动并清除您的 logcat。尝试按包而不是“我的应用程序”自定义过滤器(快速破解以禁用 应用重启时擦除行为)
标签: android firebase google-cloud-firestore android-multidex