I have been trying to build a simple app with Android Studio which has a Firestore implementation. When I add the following line to my build.gradle
file
implementation 'com.google.firebase:firebase-firestore:21.3.0'
the app does not even build and throws the following error:
cannot fit request class in a single dex file
I have looked this issue up and found this Stackoverflow page which reccomends adding MultiDex to app. This allows the app to build, but it crashes when I try to run it in the emulator. I've checked the log files but they don't contain any information on the crash.
Of course, when I remove the Firestore and MultiDex SDKs, the app builds and runs perfectly.
Edit: Here is the app\build.gradle
file with Firestore and MultiDex added in
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'
Does anyone have any idea on what the problem is? Any solutions would be very much appreciated.