I am developing a project in which I have used Firebase and Google Play service maps and location. Here is my app-level build Gradle file.
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'androidx.cardview:cardview:1.0.0'
implementation 'androidx.gridlayout:gridlayout:1.0.0'
implementation 'com.google.android.material:material:1.0.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation "com.google.android.gms:play-services-location:$playServicesVersion"
implementation "com.google.android.gms:play-services-maps:$playServicesVersion"
implementation 'com.google.android.libraries.places:places:2.0.0'
implementation "com.google.firebase:firebase-core:$firebaseCoreVersion"
implementation "com.google.firebase:firebase-perf:$firebasePerfVersion"
implementation "com.google.firebase:firebase-messaging:$firebaseMessagingVersion"
implementation "com.crashlytics.sdk.android:crashlytics:$crashlyticsVersion"
// Room
implementation 'androidx.room:room-runtime:2.1.0'
annotationProcessor 'androidx.room:room-compiler:2.1.0'
// LiveData and ViewModel
implementation 'androidx.lifecycle:lifecycle-extensions:2.0.0'
implementation 'androidx.lifecycle:lifecycle-common-java8:2.0.0'
implementation "net.danlew:android.joda:$jodaTimeVersion"
// Annotations
implementation 'androidx.annotation:annotation:1.1.0'
implementation "com.squareup.picasso:picasso:$picassoVersion"
dependencies {
implementation 'com.github.TouchBoarder:weekdays-buttons-bar:v1.0.2'
}
Now, this all works fine and the application runs normally. But when I tried to add below line:
implementation 'com.google.android.gms:play-services-ads:17.0.0'
then the following error comes
cannot fit requested classes in a single dex file
I have searched that and found out some solutions like multi dex enabled and minifyenabled for debug but the when these solutions applied then the app runs and crash on start always.
I also applied the solution of removing some libraries just to check whether Google Ads gradle library can be added but it shows the same error. Even if I remove 3-4 libraries and add one Google Ad library then the error still the same.
What to do in this case.
0
Please make sure you are using the same version of all libs of Google Play Services. Also, enable multidex for your application.
implementation "androidx.multidex:multidex:2.0.1"
2
prior approach:
Instead of implementing entire ads library, you should implement only required one…
Check out this link for further info:
Other Approach.
You can follow this link.
Versions of the platform prior to Android 5.0 (API level 21) use the Dalvik runtime for executing app code. By default, Dalvik limits apps to a single classes.dex bytecode file per APK. In order to get around this limitation, you can add the multidex support library to your project:
dependencies {
implementation 'com.android.support:multidex:1.0.3'
}
If your minSdkVersion is set to 21 or higher, all you need to do is set multiDexEnabled to true in your module-level build.gradle file, as shown here:
android {
defaultConfig {
...
minSdkVersion 21
targetSdkVersion 28
multiDexEnabled true
}
...
}
Hope you will have your solution.