I just add a module to my android project. Android Studio builds the project correctly, but when I attempt to launch the app, I getting this error.
Error:Execution failed for task ':app:transformDexArchiveWithExternalLibsDexMergerForDebug'. > com.android.builder.dexing.DexArchiveMergerException: Unable to merge dex
My project gradle:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext.kotlin_version = '1.2.21'
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.1'
classpath 'com.apollographql.apollo:apollo-gradle-plugin:0.4.4'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
// 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
}
My module gradle:
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'com.apollographql.android'
android {
compileSdkVersion 26
defaultConfig {
applicationId "com.yamblet.smartliving"
minSdkVersion 21
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 project(':openpayandroid')
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
implementation 'com.android.support:design:26.1.0'
implementation 'com.jakewharton:butterknife:8.8.1'
implementation 'com.airbnb.android:lottie:2.0.0'
implementation 'org.apache.commons:commons-lang3:3.4'
implementation 'com.android.support:support-v4:26.1.0'
implementation 'com.apollographql.apollo:apollo-runtime:0.4.4'
implementation "com.apollographql.apollo:apollo-android-support:0.4.4"
implementation 'com.apollographql.apollo:apollo-http-cache:0.4.4'
implementation 'com.github.bumptech.glide:glide:3.7.0'
implementation 'jp.wasabeef:glide-transformations:2.0.1'
implementation 'com.master.android:permissionhelper:1.1'
implementation 'com.iamhabib:easy-preference:1.0.1'
implementation 'com.android.support:recyclerview-v7:26.1.0'
implementation 'com.github.jkwiecien:EasyImage:2.0.2'
//RETROFIT
implementation 'com.squareup.retrofit2:retrofit:2.1.0'
//JSON PARSING
implementation 'com.google.code.gson:gson:2.6.1'
implementation 'com.squareup.retrofit2:converter-gson:2.1.0'
implementation 'com.android.support:cardview-v7:26.1.0'
implementation 'com.master.android:permissionhelper:1.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'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1'
implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
}
repositories {
maven { url "https://jitpack.io" }
mavenCentral()
}
apply plugin: 'kotlin-android-extensions'
Module gradle that I added
apply plugin: 'com.android.library'
android {
compileSdkVersion 19
buildToolsVersion "26.0.2"
defaultConfig {
minSdkVersion 7
targetSdkVersion 19
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
dependencies {
compile 'com.android.support:support-v4:19.+'
compile files('libs/devicecollector-sdk-2.5.jar')
compile files('libs/google-http-client-1.17.0-rc.jar')
compile files('libs/google-http-client-android-1.17.0-rc.jar')
compile files('libs/google-http-client-jackson2-1.17.0-rc.jar')
compile files('libs/jackson-core-2.1.3.jar')
compile files('libs/jackson-core-asl-1.9.11.jar')
compile files('libs/jsr305-1.3.9.jar')
compile files('libs/junit-4.10.jar')
}
I clean and rebuild the project but, the error persists in the build process. Also I add multiDexEnabled true but didnt work. Thanks for your help.
I executed this gradle, and it works only problem I can see here is implementation project(':openpayandroid'), i didn't included it as its your private library, but on my understanding openpayandroid is also including some same dependencies which is causing the problem, so solution can be to exclude that group from it, eg implementation project(':openpayandroid')
{
exclude group 'the dex error causing lib group'
}
if above does'nt work try this
in your project build.gradle try use same version of all the groups e.g.
if (details.requested.group == 'com.android.support'
&& !details.requested.name.contains('multidex')) {
details.useVersion "26.1.0" // your version
}
I think this might help but if this doesn't work try to check which file is responsible for this dex error and edit your question
One more thing you have include permission helper twice, remove (but it might not be the problem )
Make sure you have multiDexEnabled true ie. multidex enabled in your app gradle under android section
In build.gradle in default config use
multiDexEnabled true
and add dependency like compile 'com.android.support:multidex:1.0.3'
and extend your application file with MultidexApplication and rebuild your project. This will help you.
If you update the dependencies recently try this answer
Just clean the project & re-build the project
Build -> Clean project
Build -> Rebuild project
Related
I have an One year old code, which I worked so hard on, this code uses picasso library in some places to download images and use them. Today I try to improve my code, migrate to androidx and upgrade Gradle to the latest version, but it doesn't seem to sync gradle file anymore, when I comment the implementation for picasso library, the sync goes smoothly again.
Google recommends migrating to androidx to be able to serve the latest android versions, the latest play services and jetpack libraries. What is the problem? and how it can be solved?
This is my Gradle app level file:
apply plugin: 'com.android.application'
android {
compileSdkVersion 29
buildToolsVersion "29.0.2"
defaultConfig {
applicationId "com.ramikabbani.sheikhsouk"
minSdkVersion 19
targetSdkVersion 29
versionCode 1
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'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
// Picasso
implementation 'com.squareup.picasso:picasso:2.71828'
// Glide
implementation 'com.github.bumptech.glide:glide:4.9.0'
implementation 'com.google.android.material:material:1.1.0'
//
}
and this is my top level project 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.6.1'
// 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
}
This is the old project app level gradle file:
apply plugin: 'com.android.application'
android {
compileSdkVersion 29
defaultConfig {
applicationId "com.dalilukom.dalilukom"
minSdkVersion 19
targetSdkVersion 29
versionCode 21
versionName "1.21"
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:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'pl.droidsonroids.gif:android-gif-drawable:1.2.16'
implementation 'com.squareup.picasso:picasso:2.71828'
implementation 'com.github.bumptech.glide:glide:3.8.0'
//implementation 'com.android.volley:volley:1.1.1'
implementation 'com.android.support:design:26.1.0'
implementation 'com.android.support:support-v4:26.1.0'
// implementation 'com.amitshekhar.android:android-networking:1.0.2'
// implementation 'com.android.support:design:26.1.0'
// implementation 'com.android.support:appcompat-v7:27.1.1'
// implementation 'com.android.support:design:27.1.1'
//implementation 'com.nostra13.universalimageloader:universal-image-loader:1.9.5'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}
and this is the top level gradle file for the old project too:
// 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.6.1'
// 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
}
Just migrate to androidx and get the Picasso dependency for androidx on your grade file. You should be fine
Just found a workaround.
In build.gradle (project:..) , of the project gradle file ,downgrade plugin to '7.2.1' and recompile.
plugins {
id 'com.android.application' version '7.2.1' apply false
id 'com.android.library' version '7.2.1' apply false
}
and it works , seems like it unsupported on later versions.
But I think you should change the file gradle.properties( Project properties ) under android.useAndroidX=true
Put:
android.enableJetifier=true
putting whole file content of gradle.properties( Project properties )
org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8
android.useAndroidX=true
android.enableJetifier=true
android.nonTransitiveRClass=true
I am trying to build but it gives me errors. I did research and tried following solutions but cant fix.
https://github.com/objectbox/objectbox-java/issues/386
Unable to merge dex
Error - Android resource linking failed (AAPT2 27.0.3 Daemon #0)
Error: Program type already present: androidx.versionedparcelable.ParcelImpl
Thats the error
Error: Program type already present: androidx.versionedparcelable.NonParcelField
Thats the screen
Thats my code
// 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.3.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.30"
// 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
}
and this one
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-android'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.adultgaming.fantasygameapp"
minSdkVersion 17
targetSdkVersion 27
versionCode 1
versionName "1.0"
multiDexEnabled true
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support:support-v4:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.android.support:recyclerview-v7:28.0.0'
implementation 'com.android.support:multidex:1.0.3'
//Kotlin
implementation "androidx.core:core-ktx:1.0.1"
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.3.30"
//Glide
implementation 'com.github.bumptech.glide:glide:4.9.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.9.0'
//Eventbus
implementation 'org.greenrobot:eventbus:3.1.1'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}
Please let me know if I missed something. And if want to devote let me know why.
First, check inside your gradle.properties, if you have
android.enableJetifier=true
android.useAndroidX=true
Then you do have androidx enabled.
Also, and this may be obvious, but clean your Gradle build with Build -> Clean Project
UPDATE WITH ANSWER
What is happening is one of your other libraries is using androidx, GLIDE FOR SURE, and maybe others.
You have two options...
Easy: Upgrade to androidx... Like why not? Totally worth it.
Hard: Downgrade your dependencies versions to pre androidX versions.
I have problems with the execution of the project, I just downloaded the project from git but it seems that it doesn't work with the version of my Android Studio. The project was created with the 27 SDK compile version of Android.
I have tried a lot of different solutions but nothing had worked. This are the things I had already tried:
Change the compile version
Change the compileSdkVersion to 28
Set the dexOption to false to libraries
Add the dexOption for the libraries
dexOptions {
preDexLibraries = false
}
Execute the androidDependencies test of the gradle and it is build succesfully.
Like I said nothing of these had worked, but I found an issue running the build test.
And the test gave me this error:
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:transformClassesWithMultidexlistForDebug'.
> com.android.build.api.transform.TransformException: Error while generating the main dex list.
So this are my graddle files:
build.gradle
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.4'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
maven { url "https://jitpack.io" }
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
build.gradle (Module: app)
apply plugin: 'com.android.application'
android {
compileSdkVersion 'android-28'
useLibrary 'org.apache.http.legacy'
defaultConfig {
applicationId "myIdApplication"
minSdkVersion 19
targetSdkVersion 28
versionCode 1
versionName "1.0"
multiDexEnabled true
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
repositories {
jcenter()
google()
maven { url 'https://oss.jfrog.org/artifactory/oss-snapshot-local' }
maven { url 'https://jitpack.io' }
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support:support-v4:27.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
implementation 'com.github.chrisbanes:PhotoView:latest.release'
implementation 'com.android.support:animated-vector-drawable:27.1.1'
implementation('com.mikepenz:materialdrawer:5.9.1#aar') { transitive = true }
implementation 'com.github.wseemann:FFmpegMediaMetadataRetriever:1.0.14'
implementation 'com.squareup.retrofit2:retrofit:2.3.0'
implementation 'com.jakewharton:butterknife:8.8.1'
implementation 'com.squareup.retrofit2:converter-gson:2.3.0'
implementation 'com.twitter.sdk.android:twitter:3.1.1'
implementation 'com.twitter.sdk.android:twitter-core:3.1.1'
implementation 'com.twitter.sdk.android:tweet-ui:3.1.1'
implementation 'com.android.support:recyclerview-v7:27.1.0'
implementation 'com.hendraanggrian:recyclerview-paginated:0.6'
implementation 'com.github.bumptech.glide:glide:3.7.0'
implementation 'com.android.support:design:27.1.1'
implementation 'de.hdodenhof:circleimageview:2.2.0'
implementation 'commons-codec:commons-codec:1.11'
implementation 'de.hdodenhof:circleimageview:2.2.0'
implementation 'com.github.barteksc:android-pdf-viewer:2.8.2'
implementation 'com.synnapps:carouselview:0.1.4'
implementation 'bg.devlabs.fullscreenvideoview:library:0.0.8'
implementation 'com.github.halilozercan:BetterVideoPlayer:1.2.alpha1'
implementation 'com.github.ybq:Android-SpinKit:1.1.0'
implementation 'com.mindorks.android:prdownloader:0.4.0'
testImplementation 'junit:junit:4.12'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
implementation 'com.android.support:exifinterface:27.1.1'
}
I have google this issue for days, and nothing worked.
Thanks in advance.
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'
I have updated the firebase-auth dependency version but gradle build always fails. It was working fine for 16.0.1
Error Unable to resolve dependency for ':app#debug/compileClasspath': Could not resolve com.google.firebase:firebase-auth:16.0.2.
app level gradle file
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
defaultConfig {
applicationId "com.example.dell.pitchpls"
minSdkVersion 21
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'
}
}
buildToolsVersion '27.0.3'
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support:design:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.0'
implementation 'com.android.support:support-v4:26.1.0'
implementation 'com.android.support:cardview-v7:26.1.0'
implementation 'com.google.firebase:firebase-auth:16.0.2'
//implementation 'com.google.firebase:firebase-core:16.0.0'
implementation 'com.google.firebase:firebase-database:16.0.1'
implementation 'com.google.firebase:firebase-storage:16.0.1'
implementation 'com.firebaseui:firebase-ui-database:3.0.0'
implementation 'com.squareup.picasso:picasso:2.5.2'
implementation 'com.squareup.okhttp:okhttp:2.5.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}
apply plugin: 'com.google.gms.google-services'
Project level 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.0'
classpath 'com.google.gms:google-services:4.0.1'
// 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
}
The problem is resolved following this question. Just had to uncheck the offline work in setting/gradle
Try These steps:
Open Module setting of the application
Under Dependencies tab click on '+' symbol and add dependency manually a
Click on apply.
Firebase Documentation
If you visit this link and scroll down to add dependency section, you will find out that gradle dependency version is 16.0.1 only
Also, to avoid such errors, let Android Studio do automatically for you.
For this, in Android Studio, go to:
Tools-->Firebase (This will open a Firebase Assistant)
Now choose your category like Authentication,Analytics,Cloud Messaging,etc --> Click on "Setup your category" and proceed with the steps mentioned there. It will automatically add all the gradle files and generated JSON file.