android studio 3 build unable to merge dex - android

Hello suddenly my android project shows this error
Error:Execution failed for task ':app:transformDexArchiveWithExternalLibsDexMergerForDebug'.
com.android.builder.dexing.DexArchiveMergerException: Unable to merge dex
Before some days everything worked fine and I just opened it again after some days and shows me this
I have tried all the possible solutions I found here but nothing worked can you help me on this?
Here is my byuild.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
defaultConfig {
applicationId "com.example.fire.stmtfadmin"
minSdkVersion 17
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
allprojects {
repositories {
jcenter()
maven { url 'https://jitpack.io' }
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
//noinspection GradleCompatible
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support:design:26.1.0'
implementation 'com.google.firebase:firebase-storage:11.0.4'
compile 'com.android.support:cardview-v7:+'
implementation 'com.google.firebase:firebase-messaging:11.0.4'
implementation 'com.google.firebase:firebase-database:11.0.4'
implementation 'com.firebaseui:firebase-ui-database:2.3.0'
implementation 'com.google.firebase:firebase-auth:11.0.4'
compile 'com.theartofdev.edmodo:android-image-cropper:2.6.+'
compile 'id.zelory:compressor:2.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
implementation 'com.android.support:support-v4:26.1.0'
compile 'com.yqritc:recyclerview-multiple-viewtypes-adapter:1.1.0'
compile 'com.squareup.picasso:picasso:2.5.2'
compile 'com.github.StevenDXC:DxLoadingButton:2.0'
compile 'com.github.dmytrodanylyk:android-morphing-button:98a4986e56' // commit hash
compile 'de.hdodenhof:circleimageview:2.1.0'
compile 'com.android.support:multidex:1.0.0'
compile 'br.com.simplepass:loading-button-android:1.12.1'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
implementation 'com.google.android.gms:play-services-maps:11.0.4'
}
apply plugin: 'com.google.gms.google-services'
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
classpath 'com.google.gms:google-services:3.1.0'
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}

To use the 11.4.0 version of Firebase, you need to add maven url to your build.gradle file like this:
allprojects {
repositories {
jcenter()
maven {
url "https://maven.google.com" // Google's Maven repository
}
}
}

This is probably because you're using the following dependencies:
compile 'com.android.support:cardview-v7:+'
where it means you want to use the latest version. The latest version 27.1.0.
Try using:
implementation 'com.android.support:cardview-v7:26.1.0'
And never use + for your dependency version. So you can reproduce and debug the same build if there is any problem in the future.

thank you all for your replies but the only solution that worked for me was to add this line to build.gradle(Module:app):
implementation 'android.arch.lifecycle:extensions:1.1.0'
i hope this will help the others

Related

Multi Dex issue with Google AdMobs and Firebase analytics in Android

I am working on Android application where I am integrating Firebase Analytics and Google AdMobs. I am getting Multi Dex issue if I am using both together, independently both are working if I am not using other one Gradle link. I have used many solutions available on this platform, but nothing works for me.
I am putting my Gradle files along with the error which I am getting on compile time.
App Level Gradle:
buildscript {
repositories {
maven { url 'https://maven.fabric.io/public' }
}
dependencies {
classpath 'io.fabric.tools:gradle:1.+'
}
}
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
repositories {
maven { url 'https://maven.fabric.io/public' }
}
android {
compileSdkVersion 28
defaultConfig {
applicationId "fxxxxxipes"
minSdkVersion 21
multiDexEnabled true
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
implementation 'com.android.support:cardview-v7:28.0.0'
compile 'com.parse:parse-android:1.16.3'
compile 'com.parse.bolts:bolts-android:1.4.0'
compile project(':simplecropimagelib_')
compile 'com.squareup.picasso:picasso:2.5.2'
compile 'com.makeramen:roundedimageview:2.3.0'
compile 'cn.ziyeyouhu.android:sweet-alert-dialog:1.0'
compile 'com.karumi:dexter:4.1.0'
implementation 'com.android.support:design:28.0.0'
compile 'com.parse:parsefacebookutils-v4-android:1.10.4#aar'
compile 'com.facebook.android:facebook-android-sdk:4.29.0'
compile fileTree(include: 'ParseFacebookUtilsV4-*.jar', dir: 'libs')
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation 'com.android.support:multidex:1.0.1'
compile 'com.mikhaellopez:circularimageview:3.0.2'
compile('com.crashlytics.sdk.android:crashlytics:2.9.6#aar') {
transitive = true;
}
implementation 'com.google.android.gms:play-services-ads:17.1.1'
implementation 'com.google.firebase:firebase-core:16.0.4'
}
Project Level Gradle File:
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.1'
classpath 'com.google.gms:google-services:4.2.0'
}
}
allprojects {
repositories {
// google()
maven {
url "https://maven.google.com"
}
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
Error which I am getting on Console:
Error:Execution failed for task ':app:transformDexArchiveWithExternalLibsDexMergerForDebug'.
> java.lang.RuntimeException: com.android.builder.dexing.DexArchiveMergerException: Unable to merge dex
Solution which I am currently using to fix this issue but still error is coming, I am using it in my Application Class:
MultiDex.install(this);
For me,
multiDex problem is always version conflict problem.
So in my opinion, don't need to install MultiDex and just try to keep same version of every gradles.
I have solved my problem thats why want to share for others. It was giving me a Dex file issue because for Analytics I was using Firebase and for Admobs I was using Google Libraries. Same features & functionality of Admobs is also available in firebase and integrated also. So now I am using now Firebase libraries only and it is now not giving any Dex issue:
implementation 'com.google.firebase:firebase-ads:17.0.0'
implementation 'com.google.firebase:firebase-core:16.0.4'

ClassNotFoundException: unable to find class "android.support.v4.util.ArrayMap"

The signed apk of my app runs on the android versions higher than 5.0.1 but I am facing this issue that my app crashes immediately after launching the app on version 5.0.1 and this is the error I get -
Caused by: java.lang.ClassNotFoundException: Didn't find class "android.support.v4.util.ArrayMap" on path: DexPathList[[zip file "/data/app/com.*****1/base.apk"],nativeLibraryDirectories=[/vendor/lib, /system/lib]]
please note that the app is not crashing when I run using android studio but it crashes when I run the signed apk.
I don't know what to do, I have gone through a lot of stackoverflow questions but found nothing that can solve my issue. This is my app.gradle file -
**buildscript {
repositories {
maven { url 'https://maven.fabric.io/public' } // for crashlytics
}
dependencies {
classpath 'io.fabric.tools:gradle:1.+'
}
}
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
android {
compileSdkVersion 26
buildToolsVersion '27.0.3'
defaultConfig {
applicationId "*****"
minSdkVersion 21
targetSdkVersion 26
flavorDimensions "default"
packagingOptions {
exclude 'META-INF/rxjava.properties'
}
versionCode 3
multiDexEnabled true
versionName "1.0.3"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
android {
lintOptions {
checkReleaseBuilds false
abortOnError false
}
}
compileOptions {
targetCompatibility 1.8
sourceCompatibility 1.8
}
dexOptions {
javaMaxHeapSize "2g"
}
}
repositories {
mavenCentral()
google()
maven { url 'https://maven.fabric.io/public' }
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
//google 's library
//noinspection GradleCompatible
implementation 'com.android.support:appcompat-v7:26.0.2'
implementation 'com.android.support:design:26.0.2'
implementation 'com.android.support:support-v4:26.0.2'
implementation 'com.android.support:support-v13:26.0.2'
implementation 'com.android.support:cardview-v7:26.0.2'
implementation 'com.android.support:recyclerview-v7:26.1.0'
implementation 'com.google.android.gms:play-services-vision:11.8.0'
//for barcode generation
implementation 'com.google.zxing:core:3.2.0'
implementation 'com.android.support:multidex:1.0.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
compile 'me.dm7.barcodescanner:zxing:1.9'
compile 'com.journeyapps:zxing-android-embedded:3.0.2#aar'
//multidex support
compile 'com.android.support:multidex:1.0.1'
//for fancy dialogs
implementation 'com.google.android.gms:play-services-maps:11.8.0'
implementation 'com.google.android.gms:play-services:11.8.0'
compile 'com.geniusforapp.fancydialog:FancyDialog:0.1.4'
//for home screen carousal view
compile 'com.synnapps:carouselview:0.1.4'
//for bottom navigation
compile 'com.ss.bottomnavigation:bottomnavigation:1.5.2'
//for shaping the image view
compile 'com.github.siyamed:android-shape-imageview:0.9.+#aar'
compile 'com.jackandphantom.android:circularimageview:1.2.0'
//libraries for retrofit and conversion factory GSON
implementation 'com.squareup.retrofit2:retrofit:2.3.0'
implementation 'com.squareup.retrofit2:converter-gson:2.3.0'
implementation 'com.google.code.gson:gson:2.8.0'
implementation 'de.hdodenhof:circleimageview:2.2.0'
//FilePicker Library
compile 'com.droidninja:filepicker:2.0.8'
//for welcome screen
compile 'com.stephentuso:welcome:1.4.1'
compile 'com.squareup.okhttp3:okhttp:3.9.1'
compile 'com.squareup.okhttp3:okhttp-urlconnection:3.0.1'
compile 'com.squareup.retrofit2:converter-scalars:2.3.0'
compile 'com.jakewharton.retrofit:retrofit2-rxjava2-adapter:1.0.0'
compile 'com.squareup.okhttp3:okhttp:3.3.1'
//material calender picker
compile 'com.wdullaer:materialdatetimepicker:3.4.0'
implementation 'com.trello:rxlifecycle:1.0'
implementation 'com.trello:rxlifecycle-components:1.0'
compile 'com.polidea.rxandroidble:rxandroidble:1.4.3'
implementation 'com.android.support:design:26.0.2'
compile 'io.reactivex.rxjava2:rxjava:2.0.7'
compile 'io.reactivex.rxjava2:rxandroid:2.0.1'
//libraries for firebase integration
//for analytics
compile 'com.google.firebase:firebase-core:11.8.0'
//for cloud messenging
compile 'com.google.firebase:firebase-messaging:11.8.0'
//for circular indicator
compile 'com.github.lzyzsd:circleprogress:1.2.1'
compile 'me.biubiubiu.justifytext:library:1.1'
implementation files('libs/imagecapture.jar')
implementation 'com.crashlytics.sdk.android:crashlytics:2.9.5'
}
apply plugin: 'com.google.gms.google-services'**
This is my build.gradle (project level)
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
jcenter()
maven {
url 'https://maven.fabric.io/public'
}
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.0'
classpath 'com.google.gms:google-services:3.1.0'
classpath 'io.fabric.tools:gradle:1.25.4'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
google()
maven { url "https://jitpack.io"
}
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
If the gradle version is 3.x.x try to add maven { url 'https://maven.google.com' } to
allprojects {
repositories {
//add here
}
}
instead of google() and sync gradle. It should help. You can see difference between them using this link.
I found the solution. I tried building the Signed apk for both the signature versions V1(jar signature) and V2(full apk signature) and it worked.

Build.gradle: Failed to resolve: com.android.support

I'm trying to build my Android Studio project, but I keep getting this "Failed to resolve: com.android.support" error.
This is how the build.gradle looks like:
apply plugin: 'com.android.application'
android {
compileSdkVersion 27
defaultConfig {
applicationId "app.training.linus.trainingapp"
minSdkVersion 26
targetSdkVersion 27
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.exercise_card.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support:design:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.1'
implementation 'com.android.support:support-v4:27.1.1'
implementation 'com.android.support:cardview-v7:27.1.1'
implementation 'com.google.android.gms:play-services-plus:15.0.1'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.exercise_card:runner:1.0.2'
androidTestImplementation 'com.android.support.exercise_card.espresso:espresso-core:3.0.2'
}
And the other gradle file:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.3'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
I can't figure out why I can't build properly, I have the correct SDK version downloaded and everything.
Thanks in advance!
Removing
androidTestImplementation 'com.android.support.exercise_card:runner:1.0.2'
androidTestImplementation 'com.android.support.exercise_card.espresso:espresso-core:3.0.2'
Seems to have solved it!
Will You show me the error to know problem decently?
generally, the integration problem occur if you update your studio
reinstall the studio and connect with SDK
you should check
dependency in android studio
'dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support:design:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.1'
implementation 'com.android.support:support-v4:27.1.1'
implementation 'com.android.support:cardview-v7:27.1.1'
implementation 'com.google.android.gms:play-services-plus:15.0.1'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.exercise_card:runner:1.0.2'
androidTestImplementation 'com.android.support.exercise_card.espresso:espresso-core:3.0.2'
}'
you need to add in the project level gradle in allprojects
maven {
url "https://maven.google.com"
}
allprojects {
repositories {
jcenter()
maven {
url "https://maven.google.com"
}
google()
}
}

Unable to resolve dependency for ':app#releaseUnitTest/compileClasspath': Could not resolve com.android.support:appcompat-v7:27.1.1

Note.
This not duplicate of this question but the extension as there are few more error I got and the solution in that question stated was not solving my errors.
Problem:
Recently I am migrating my older project to upper version. I have updated Android Studio to 3.1 and Using API 27 with Gradle 4.4. I have changed the depricated compile to implementation now I am facing a very weird error. I am telling weird as I have tried many solution stated in other question and answers but nothing helped me. Beside the :app#debug/compileClasspath I am getting also the following errors
:app#debugAndroidTest/compileClasspath
:app#debugUnitTest/compileClasspath
:app#release/compileClasspath
:app#releaseUnitTest/compileClasspath
I think all errors are related. I am getting this long list of error with every libraries.
Here is my app build.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 27
defaultConfig {
applicationId "com.epp.app.myproject"
minSdkVersion 19
targetSdkVersion 27
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
repositories {
mavenCentral()
maven { url uri('https://jitpack.io') }
maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
maven {url uri('https://oss.sonatype.org/content/repositories/snapshots/')}
google()
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
implementation 'com.android.volley:volley:1.1.0'
implementation 'com.android.support:cardview-v7:27.1.1'
implementation 'com.android.support:recyclerview-v7:27.1.1'
implementation 'com.github.rey5137:material:1.2.4'
implementation 'com.github.gabrielemariotti.cards:cardslib-core:2.1.0'
implementation 'com.github.gabrielemariotti.cards:cardslib-cards:2.1.0'
implementation 'com.github.gabrielemariotti.cards:cardslib-recyclerview:2.1.0'
implementation 'com.github.gabrielemariotti.cards:cardslib-extra-staggeredgrid:2.1.0'
implementation 'com.github.ksoichiro:android-observablescrollview:1.5.0'
implementation 'devlight.io:navigationtabbar:1.2.5'
implementation('com.mikepenz:materialdrawer:6.0.7#aar') {
transitive = true
}
implementation 'com.android.support:support-annotations:27.1.1'
implementation 'com.android.support:design:27.1.1'
implementation 'com.github.Netural:RemoteAppControl:1.0.0'
implementation 'com.michaelpardo:activeandroid:3.1.0-SNAPSHOT'
implementation 'com.github.PhilJay:MPAndroidChart:v3.0.3'
}
Here is my module build.gradle
buildscript {
repositories {
jcenter()
mavenCentral()
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.1'
}
}
allprojects {
repositories {
jcenter()
mavenCentral()
}
}
repositories {
jcenter()
mavenCentral()
google()
}
task clean(type: Delete) {
delete rootProject.buildDir
}
I have found a solution for this. There was a repository conflict. Removing mavenCentral() from buildScript of module build.gradle works like a wonder.

Android Studio - Updating the Version of com.google.android.gms to 11.6.0

I always get this error in my android studio, and i dont have any idea about this, i've tried to find the solution on the Internet but i still cant find it.
This is my Gradle Image :
this is the Error Image :
In your project the errors comes like you have not add project level google classpath and not apply google plugin in app level gradle so,
Add in project level gradle
classpath 'com.google.gms:google-services:3.1.1'
Add in APP level gradle and google plugin
dependencies {
compile 'com.google.firebase:firebase-core:11.6.0'
compile 'com.google.android.gms:play-services:11.6.0'
}
// ADD THIS AT THE BOTTOM
apply plugin: 'com.google.gms.google-services'
NOTE-: If you want to add more Google gradle for your requirements then add with same version.
For More https://firebase.google.com/docs/android/setup
https://developers.google.com/android/guides/setup
If you are using Google Services your Gradles should look something like this:
App level build.gradle should look like
apply plugin: 'com.android.application'
apply plugin: 'com.google.firebase.firebase-crash'
android {
compileSdkVersion 26
buildToolsVersion "26.0.2"
defaultConfig {
applicationId "com.xxxxxx"
minSdkVersion 15
targetSdkVersion 26
versionCode 11
versionName "1.10"
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.config
}
debug {
signingConfig signingConfigs.config
resValue("string", "PORT_NUMBER", "8081")
}
}
dexOptions {
javaMaxHeapSize "4g"
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
debugCompile project(':debug-db')
compile project(':tracker')
compile 'com.android.support:appcompat-v7:26.1.0'
compile 'com.android.support:design:26.1.0'
compile 'com.android.support:cardview-v7:26.1.0'
compile 'com.android.support:multidex:1.0.2'
compile 'com.google.android.gms:play-services-location:11.6.0'
compile 'com.google.android.gms:play-services-places:11.6.0'
compile 'com.google.android.gms:play-services-maps:11.6.0'
/* compile 'com.google.android.gms:play-services:11.6.0'*/
compile 'com.google.firebase:firebase-core:11.6.0'
compile 'com.google.firebase:firebase-crash:11.6.0'
compile 'com.google.firebase:firebase-messaging:11.6.0'
compile 'com.mcxiaoke.volley:library:1.0.19'
compile 'com.squareup.okhttp3:okhttp:3.8.0'
compile 'de.hdodenhof:circleimageview:2.1.0'
compile 'com.squareup.retrofit2:retrofit:2.3.0'
compile 'com.squareup.retrofit2:converter-gson:2.3.0'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
compile 'com.android.support:recyclerview-v7:26.1.0'
testCompile 'junit:junit:4.12'
}
// Add to the bottom of the file
apply plugin: 'com.google.gms.google-services'
As you could see, no use for build, but it completely depends on your use /* compile 'com.google.android.gms:play-services:11.4.0'*/
And root level gradle.build is:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
mavenCentral()
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.0'
classpath 'com.google.gms:google-services:3.1.1'
classpath 'com.google.firebase:firebase-plugins:1.1.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
maven { url "https://jitpack.io" }
jcenter()
mavenCentral()
google()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
Make sure your Gradle distribution in gradle-wrapper.properties is
distributionUrl=https\://services.gradle.org/distributions/gradle-4.3-all.zip

Categories

Resources