Error:java.lang.RuntimeException: java.lang.RuntimeException: com.android.builder.dexing.DexArchiveMergerException: Unable to merge dex
Error:java.lang.RuntimeException: com.android.builder.dexing.DexArchiveMergerException: Unable to merge dex
Error:com.android.builder.dexing.DexArchiveMergerException: Unable to merge dex
Error:com.android.dex.DexException: Multiple dex files define Lcom/google/zxing/integration/android/IntentResult;
I have same problem with Android Studio 3.0 beta 4. I found a solution.
1. From the Build menu, press the Clean Project button.
2. After task completed, press the Rebuild Project button from the Build menu.
For Android Studio 3.0 what I did was to add this to my gradle:
multiDexEnabled true
And it worked!
Example
android {
compileSdkVersion 25
buildToolsVersion '26.0.2'
defaultConfig {
applicationId "com.xx.xxx"
minSdkVersion 15
targetSdkVersion 24
versionCode 9
versionName "1.0"
multiDexEnabled true //Add this
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
shrinkResources true
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
So I solved this issue by doing the following:
Delete the ./gradle folder inside your project
Delete all the build folders and the gradle cache. I ran the following command:
How ?
cd ~/[your project root folder] && find . -name build -exec rm -rf {} \; && rm -rf $HOME/.gradle/caches/
Assuming your gradle config files are in the $HOME/.gradle folder.
Inside Android Studio, went to File > Invalidate caches / Restart... and invalidated the caches and restarted it.
You should be able to get to the cause of this error by inspecting your dependencies with gradle and looking for duplicates like this:
./gradlew -q app:dependencies
In my case, the following error was happening at build time:
Duplicate zip entry [httpcore-4.4.1.jar
and it was resolved by doing this in my build.gradle:
implementation ('me.dlkanth:stetho-volley:1.0') {
exclude group: 'org.apache.httpcomponents'
}
If your minSdkVersion is 21 or higher
android {
defaultConfig {
multiDexEnabled true
}
}
if your minSdkVersion is 20 or lower
1) you must add the following library in dependencies
dependencies {
compile 'com.android.support:multidex:1.0.1'
}
2) Create a java class then extend it from Application and override attachBaseContext method.
public class MyApplication extends Application {
#Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
MultiDex.install(this);
}
}
3) Mention the created class inside manifest in application tag.
<application
android:name=".MyApplication"
.
.
.
</application>
Check your dependencies for latest version usually it is inconsistency with the version of any of your dependencies.
1.Build > Clean Project
2. Rebuild your project
Check the verbose log for the dependency causing the merge issue and update the same. Repeat the same for each dependencies.
I faced same issue in Android Studio 3.0.1, I tried all possible cases nothing worked for me as mentioned above, finally I solved it by
Solution1:
Close Android Studio
Delete .gradle folder located at C:\Users\YourComputerName\.gradle not from app's .gradle
Restart android studio
It will download all the necessary jars and add to your build path
Solution2:
Delete duplicate jar from libs folder in app/libs
Rerun the app again
Because if there is duplicate jar file which already defined in build.gradle file it causes issue.
This solved the issue for me. It may help others..
This error can have multiple reasons.
No clean and rebuild or anythging like that did the job for me.
For me the problem was the dependency:
compile 'org.jetbrains:annotations-java5:15.0'
I removed it and everything worked fine.
Change "compile" to "compileOnly"
this is what worked for me.
In my case the culprit was SendGrid lib, added this and it got fixed:
compile 'com.github.danysantiago:sendgrid-android:1',{
exclude group: 'org.apache.httpcomponents', module: 'httpclient'
}
I am using Studio 3.0.0 release. In my case there was the only solution: I have removed old JARs from the "libs" folder in my project: it was "ksoap2" package with dependencies. Packages obtained with gradle usually do not conflict with each other, at least if you are using the most popular ones. But an old JAR in libs folder may crush your build if it includes all own dependencies.
I have tried other comments from removing gradle and bla bla bla, but adding multiDexEnabled true solving my problem, I investigate that my apk has reached Over 64K Method.
Ref: https://developer.android.com/studio/build/multidex.html)
I am using
Android Studio 3.0.1
Build #AI-171.4443003, built on November 9, 2017
I delete jar file from libs folder. And that work fine for me
I am using Android Studio 3.0.1 and was facing the same problem. If others answer doesn't works try this:
Tools -> Android -> Sync Project with Gradle Files
It worked for me Sync Project with Gradle Files
Sometime it can happens due to same library (jar file) present two times or your project has reached 64k methods limit.
Solution:
1) Remove Databinding if your project use this
2) Remove same type library from lib folder or, delete .gradle file from c//user//your_pc//.gradle
3) apply this in your build.gradle
android {
defaultConfig {
multiDexEnabled true
}
}
I am trying to run an app that has a Google Maps Activity on my phone. My phone's running on Android 4.1.3 and the Minimum SDK for my project is API 15: Android 4.0.3
I just created the project on Android Studio and tried to run it on my phone. But it won't run and I am keep getting this error. Can someone tell me how to solve this?
That error probably means that you are using too much libraries. And because you are trying to use google maps I'm guessing you included everything google.
Try to just use the libraries you need.
For maps use this:
dependencies {
com.google.android.gms:play-services-maps:9.2.1
}
Reading material:
https://developers.google.com/android/guides/setup
You need to configure your gradle for multidex.
Modify the module-level build.gradle file configuration to include the support library and enable multidex output, as shown in the following code snippet:
android {
compileSdkVersion 21
buildToolsVersion "21.1.0"
defaultConfig {
...
minSdkVersion 14
targetSdkVersion 21
...
// Enabling multidex support.
multiDexEnabled true
}
...
}
dependencies {
compile 'com.android.support:multidex:1.0.0'
}
See more on same link which you are refering : https://developer.android.com/studio/build/multidex.html#mdex-gradle
You can also see some related question for same error:
How to enable multidexing with the new Android Multidex support library
Android java.exe finished with non-zero exit value 1
I am new in android app development, and this a month that I am working with android studio. Before, I created lots of project without any problem. This is two days that I received this strange error when I create a new project:
Error:Unable to find method 'org.apache.http.impl.client.DefaultHttpClient.setRedirectStrategy(Lorg/apache/http/client/RedirectStrategy;)V'.
Possible causes for this unexpected error include:<ul><li>Gradle's dependency cache may be corrupt (this sometimes occurs after a network connection timeout.)
Re-download dependencies and sync project (requires network)</li><li>The state of a Gradle build process (daemon) may be corrupt. Stopping all Gradle daemons may solve this problem.
Stop Gradle build processes (requires restart)</li><li>Your project may be using a third-party plugin which is not compatible with the other plugins in the project or the version of Gradle requested by the project.
</li></ul>In the case of corrupt Gradle processes, you can also try closing the IDE and then killing all Java processes.
I also uninstall android studio and install it again but still doesn't work well, and also my previous projects don't work with this new android studio.
this is how my build.gradle looks like:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.5.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
android {
compileSdkVersion 22
buildToolsVersion '19.1.0'
defaultConfig {
minSdkVersion 21
targetSdkVersion 21
}
productFlavors {
}
}
dependencies {
}
and this is the screen shot:
I suppose that, you're trying to use already unsupported library
HttpClient is not supported any more in sdk 23.
You have to use URLConnection or downgrade to sdk 22 (compile 'com.android.support:appcompat-v7:22.2.0')
If you need SDK version 23, add this to your build.gradle:
android {
useLibrary 'org.apache.http.legacy'
}
You also may try to download and include HttpClient jar directly into your project or use OkHttp instead.
If you need more information, please check also related topics:
Android libraries not found
HttpClient won't import in Android Studio
How to use the legacy Apache HTTP client on Android Marshmallow?
EDIT: According to How to exclude libraries from all dependencies in Gradle
configurations {
compile.exclude group:'ch.qos.logback'
}
or
configurations {
// to avoid double inclusion of support libraries
all*.exclude group: 'com.android.support', module: 'support-v4'
}
Check this: android studio: gradle dependency error
Hope it help
Based on these explanations, the solution is to remove httpClients libraries from java exra libraries for me (on mac) form following dir:
/Library/Java/JavaVirtualMachines/jdk1.7.0_67.jdk/Contents/Home/jre/lib/ext
I'm sure this is simple, but since I just started using Android Studio today, I can't find it. I have also googled for the past hour and found no posts that specify:
how to change an existing application project to a library.
Everything I found was about how to create a new library project. Not how to convert one.
A sub-question, is how can I see if a project is configured as an application or a library? I would hope that the answer to both of these questions is the same.
Open your build.gradle of your app (inside your app directory) and modify :
apply plugin: 'com.android.application'
with
apply plugin: 'com.android.library'
If you have an applicationId in your build.gradle remove it :
defaultConfig {
applicationId "com.your.application.id"
}
then clean your project and rebuild or just sync your gradle from Android Studio
If you have added some extra gradle properties like applicationVariants.all you must replace with libraryVariants.all and vice-versa if you convert a library to application
If you want to add a new step to your reconversion you can change the module name "app" created by default by Android-Studio with a name more adapted to a library module. You can rename the directory app with <your_module_name>. open settings.gradle file (at the root of your project) and replace app with <your_module_name>. Then Go to Menu Build > Make module <your_module_name> and there you are, your module is renamed.
Changing to Library
Goto android project, where you need to change as Library module.
In build.gradle(:app) file,
change this line to
plugins {
id 'com.android.application'
}
to
plugins {
id 'com.android.library'
}
Delete the line for the applicationId in same build.gradle(:app) file
defaultConfig {
applicationId "com.project.example" //remove this line
minSdk 21
targetSdk 31
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
Now Sync Project with Gradle Files.
I'm developing an App in Android studio. And I want use a Google maps API, but I can't use UI to configure project settings. I tried some different instruction to add maps, but it didn't work. I have to modify somehow build.gradle file? Can you tell me how? Does someone have experience with that?
Thanks for every advice.
If you are on 0.2 it means that you already have Google Repository and Android Repository installed(from Android SDK: terminal$ android sdk).
One of them, has the Google Play services.
Here is a full build.gradle for your module:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.5.+'
}
}
apply plugin: 'android'
dependencies {
compile 'com.google.android.gms:play-services:3.1.36'
}
android {
compileSdkVersion 17
buildToolsVersion "17.0.0"
defaultConfig {
minSdkVersion 8
targetSdkVersion 16
}
}
Notice how(easily) the play services can be included.
Also gradle version is 0.5.+ so it can be auto updated!
Also another VERY important thing, that wasted me a lot of time is the minimum sdk version!
It must be 8 or above, since google play services aren't supported for lower versions!