How to Solve Error:Unable to merge dex - android

I'm following an Tutorial from youtube and now I ran into an problem. When I sync the build File. Build Completes without any Error but when I run app connecting my Device it give me error of
Error:Execution failed for task ':app:transformDexArchiveWithExternalLibsDexMergerForDebug'.
java.lang.RuntimeException: java.lang.RuntimeException: com.android.builder.dexing.DexArchiveMergerException: Unable to merge dex
But when I remove the line
implementation 'com.theartofdev.edmodo:android-image-cropper:2.6.+'
It works Fine, but I need this library. So How can I resolve it.
My app build.gradle file is
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
buildToolsVersion "26.0.2"
defaultConfig {
applicationId "com.nepalpolice.cdp"
minSdkVersion 21
targetSdkVersion 26
versionCode 2
versionName "2.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation 'com.google.firebase:firebase-auth:11.0.4'
implementation 'com.google.firebase:firebase-storage:11.0.4'
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'
})
implementation 'com.android.support:appcompat-v7:26.+'
implementation 'com.android.support:support-v4:26.+'
implementation 'com.android.support:cardview-v7:26.+'
implementation 'com.google.firebase:firebase-messaging:11.0.4'
implementation 'com.google.gms:google-services:3.1.0'
implementation 'com.android.support:design:26.+'
implementation 'de.hdodenhof:circleimageview:2.2.0'
implementation 'com.android.support:multidex:1.0.1'
implementation 'com.theartofdev.edmodo:android-image-cropper:2.6.+'
implementation 'com.android.support:gridlayout-v7:26.+'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
testCompile 'junit:junit:4.12'
implementation 'com.google.android.gms:play-services-maps:11.0.4'
}
apply plugin: 'com.google.gms.google-services'
and inside my lib folder , I have volley jar file.
I tried below solution but it didn't work for me.
One
android {
defaultConfig {
multiDexEnabled true
}
}
and also using
compile 'com.android.support:multidex:1.0.1'
and also I deleted .gradle file and clean and rebuild project but didn't help either.
How can I solve this?? Thanks in advance.

This issue happened to me and the solution was about the release of the image cropper library.
In my case and as well yours, the SDK is 26 so you need to compile 2.5.1 version, not 2.6.0:
implementation 'com.theartofdev.edmodo:android-image-cropper:2.5.1'
Android Image Cropper releases

Related

Errors with the gradle file and the Imports on my Project

I am developing a project to parse data as JsonObject from the StarWars API (https://swapi.dev/api/). I am using a recyclerView to present the data in the View and some interfaces to have the relevant methods for the loading of data and handling of errors (with a client and server connection service). The project was working correctly, without errors until today where out of the blue I am getting several imports highlighted with red.
My gradle file is as follows:
apply plugin: 'com.android.application'
android {
compileSdkVersion 27
buildToolsVersion "26.0.3"
defaultConfig {
applicationId "com.juangm.bottomnavigationmvp"
minSdkVersion 16
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'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-
core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:27.3.1'
compile 'com.android.support:cardview-v7:27.3.1'
compile 'com.android.support.constraint:constraint-layout:1.1.3'
compile 'com.android.support:design:27.3.1'
compile 'com.android.support:support-v4:27.3.1'
testCompile 'junit:junit:4.12'
compile 'com.jakewharton:butterknife:10.0.0'
implementation 'com.jakewharton:butterknife-compiler:10.0.0'
compile 'com.squareup.retrofit2:retrofit:2.5.0'
compile 'com.squareup.retrofit2:converter-gson:2.5.0'
compile 'com.squareup.okhttp3:okhttp:3.12.0'
compile 'com.squareup.okhttp3:logging-interceptor:3.8.1'
compile 'com.fasterxml.jackson.core:jackson-annotations:2.7.3'
compile 'com.android.support:support-annotations:28.0.0'
implementation 'com.android.support:recyclerview-v7:27.1.1'
}
Errors as they appear in the BottomNavigationActivity class:
Bottom Navigation Activity
Any help is much appreciated. I tried to change some dependencies on my Gradle file, invalidate caches etch. but with no success. Maybe it is somehow related to the Android studio?
Change buildToolsVersion to "27.0.3"
Clean build project
Invalidate cache / Restart Studio
If none of these above not work comment, please.

Dependecies for CardView and RecyclerView in SDK version 28

I am trying to add CardView and RecyclerView dependencies in my Android Studio Project for SDK version 28. Upon building the project, I get the message, "Gradle Project Sync Failed. Basic Functionality will not work properly".
build.gradle(Module:app) file:
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.kavyabarnadhyahazarika.quarterallotmentiocl"
minSdkVersion 16
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
buildToolsVersion '28.0.0'
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
implementation 'com.android.support:appcompat-v7:28.0.0-alpha3'
implementation 'com.android.support:cardview-v7:28.0.0'
implementation 'com.android.support:recyclerview-v7:28.0.0'
implementation 'com.mcxiaoke.volley:library:1.0.19'
testImplementation 'junit:junit:4.12'
}
Error Messages:
Failed to resolve: com.android.support:cardview-v7:28.0.0
Failed to resolve: com.android.support:recyclerview-v7:28.0.0
I have tried both build and clean project.
Also if these dependencies are not supported on SDK version 28, how do I resolve the issue?
There is no 28.0.0 final release as of yet - just like your appcompat-v7 dependency, cardview-v7 and recyclerview-v7 should have a version of 28.0.0-alpha3:
implementation 'com.android.support:appcompat-v7:28.0.0-alpha3'
implementation 'com.android.support:cardview-v7:28.0.0-alpha3'
implementation 'com.android.support:recyclerview-v7:28.0.0-alpha3'
This works for me.
// RecyclerView
implementation 'com.android.support:recyclerview-v7:+'
// CardView
implementation 'com.android.support:cardview-v7:+'
Here's a working solution.
replace the following dependencies
implementation 'com.android.support:cardview-v7:28.0.0-alpha3'
implementation 'com.android.support:recyclerview-v7:28.0.0-alpha3'
or
implementation 'com.android.support:cardview-v7:28.0.0'
implementation 'com.android.support:recyclerview-v7:28.0.0'
with the below implementations
implementation 'androidx.cardview:cardview:1.0.0'
implementation 'androidx.recyclerview:recyclerview:1.0.0'
I hope it helps.

Android Studio fails to build an APK with DexIndexOverflowException

When I run my project in my phone or in the emulator, it works fine. However, when I try to build the APK, it raises an error.
Error: Execution failed for task
':app:transformClassesWithDexForDebug'. >
com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException:
java.util.concurrent.ExecutionException:
com.android.dex.DexIndexOverflowException: method ID not in [0,
0xffff]: 65536
Here is my build.gradle.
apply plugin: 'com.android.application'
android {
useLibrary 'org.apache.http.legacy'
compileSdkVersion 27
buildToolsVersion "27.0.3"
defaultConfig {
applicationId "com.atm_locator.cbe.cbeatmlocator"
minSdkVersion 15
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'
}
}
sourceSets { debug { res.srcDirs = ['src/debug/res', 'src/debug/res/html'] } }
}
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'
})
compile 'com.android.volley:volley:1.0.0'
compile 'com.mcxiaoke.volley:library-aar:1.0.0'
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support:support-v4:25.3.1'
compile 'com.android.support:design:25.3.1'
compile 'com.h6ah4i.android.widget.verticalseekbar:verticalseekbar:0.7.2'
compile 'com.firebase:geofire-android:2.1.2'
compile 'com.google.firebase:firebase-database:11.0.4'
compile 'com.google.android.gms:play-services:11.0.4'
compile 'com.google.android.gms:play-services-vision:11.0.4'
compile 'com.google.android.gms:play-services-location:11.0.4'
compile 'com.google.android.gms:play-services-maps:11.0.4'
compile 'com.android.support:recyclerview-v7:25.3.1'
compile 'com.android.support:cardview-v7:25.3.1'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
compile 'ai.api:libai:1.6.12'
compile 'ai.api:sdk:2.0.7#aar'
compile 'com.google.code.gson:gson:2.3'
compile 'commons-io:commons-io:2.4'
testCompile 'junit:junit:4.12'
compile files('libs/httpclient-4.5.jar')
}
apply plugin: 'com.google.gms.google-services'
What the error is telling you is that you've reached the method count limit in Android. This can be solved two ways: Either you start removing dependencies or you enable multidexing. The latter can be enabled the following way:
android {
defaultConfig {
...
minSdkVersion 15
targetSdkVersion 26
multiDexEnabled true
}
...
}
dependencies {
compile 'com.android.support:multidex:1.0.1'
}
On Android API level >= 21 you don't need the compile dependency, as this is supported natively by ART.
You can read all about this on https://developer.android.com/studio/build/multidex
For release, I'd suggest to enable proGuard to optimize your app and automatically remove not needed code. For debug builds, to simplify debugging, as mentioned above, you can enable multidex.
For proguard, read documentation: https://developer.android.com/studio/build/shrink-code - configuration may be not straightforward

Cannot resolve symbol 'CalligraphyContextWrapper'

Till yesterday everything was working fine but today i have updated my Android studio from 2.3 to 3.1 and i am getting this error now. But even i am getting Cannot resolve symbol CalligraphyContextWrapper, still project is successfully clean and build and the font is changing fine. I am surprised if everything is working fine then why this error appears. You can see the error in image and also i am adding my gradle code below. Please let me know if i am doing something wrong.
build.grade:
apply plugin: 'com.android.application'
android {
compileSdkVersion 27
buildToolsVersion "27.0.3"
defaultConfig {
applicationId "com.package"
minSdkVersion 19
targetSdkVersion 27
versionCode 1
versionName "1.2"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
allprojects {
repositories {
jcenter()
maven {
url "https://maven.google.com"
}
}
}
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
implementation 'com.android.support:appcompat-v7:27.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
testImplementation 'junit:junit:4.12'
implementation 'com.android.support:design:27.0.0'
implementation 'com.android.support:cardview-v7:27.0.0'
/* Retrofit */
implementation 'com.squareup.retrofit2:retrofit:2.3.0'
implementation 'com.squareup.retrofit2:converter-gson:2.3.0'
implementation 'com.squareup.okhttp3:logging-interceptor:3.4.1'
implementation 'com.squareup.retrofit2:adapter-rxjava2:2.3.0'
implementation 'com.google.code.gson:gson:2.7'
implementation 'com.squareup.okhttp3:okhttp:3.4.2'
//multi dex
implementation 'com.android.support:multidex:1.0.1'
//Picasso
implementation 'com.squareup.picasso:picasso:2.5.2'
//Buimplementationtter knife
implementation 'com.jakewharton:butterknife:8.8.1'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1'
//planet payment gateway
implementation 'com.google.android.gms:play-services-wallet:11.0.4'
//font
implementation 'uk.co.chrisjenx:calligraphy:2.3.0'
implementation 'io.card:android-sdk:5.5.1'
}
I have also raised the issue in github but there is no response from Calligraphy team.
https://github.com/chrisjenx/Calligraphy/issues/449#issuecomment-386390551
Any help or clue will be appreciated.
You can Downgrade version. Use 2.2.0 instead of 2.3.0.
implementation 'uk.co.chrisjenx:calligraphy:2.2.0'
Then Clean-Rebuild-Run.
I am not sure if it is related but I've resolved a similar issue by doing the following;
Remove the dependency from gradle build file
Sync the gradle file
Put the same dependency and sync it again.

Unable to merge dex this error keeps getting everytime

The error is Error
:Execution failed for task
':app:transformDexArchiveWithExternalLibsDexMergerForDebug'. >
java.lang.RuntimeException: java.lang.RuntimeException:
com.android.builder.dexing.DexArchiveMergerException: Unable to merge dex
I have tried all the solutions given on stackoverflow but none of them worked for me.
This is app level gradle file. I think I am using all the latest dependencies.
app level build.gradle file is uploaded here. help me to solve this problem
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
defaultConfig {
applicationId"com.example.pratikrathi.registerapp"
minSdkVersion 20
targetSdkVersion 26
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'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support:design:26.1.0'
implementation 'com.android.support.constraint:constraintlayout:1.0.2'
implementation 'com.android.support:cardview-v7:26.1.0'
implementation 'com.google.firebase:firebase-auth:11.8.0'
compile 'com.google.firebase:firebase-core:11.8.0'
compile 'com.google.firebase:firebase-database:11.8.0'
compile 'com.google.firebase:firebase-storage:11.8.0'
compile 'com.google.firebase:firebase-firestore:11.8.0'
compile 'com.google.firebase:firebase-crash:11.8.0'
implementation 'com.android.support:support-v4:26.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'
compile 'de.hdodenhof:circleimageview:2.2.0'
compile 'com.theartofdev.edmodo:android-image-cropper:2.6.+'
implementation 'com.github.bumptech.glide:glide:4.6.1'
annotationProcessor 'com.github.bumptech.glide:compiler:4.6.1'
}
apply plugin: 'com.google.gms.google-services'
You are mixing old firebase dependencies with the new firebase dependencies.
You need to remove the following from your root build.gradle dependencies:
classpath 'com.firebase:firebase-client-android:2.3.1'
Then check and remove old firebase depedencies from your module build.gradle. Please read https://firebase.google.com/support/guides/google-android
UPDATE
You also have a duplicated support library.
'com.theartofdev.edmodo:android-image-cropper:2.6.+' library implicitly using support library version 27+, which you can check from its root build.gradle.
You can fix it by exclude support library from image-cropper like this:
implementation ("com.theartofdev.edmodo:android-image-cropper:2.6.+") {
exclude group: 'com.android.support'
exclude module: 'appcompat-v7'
}
Or updating all of your support library to version 27.1.0.

Categories

Resources