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
}
}
Related
the event log say
5:11:08 PM Gradle sync started
5:11:35 PM Gradle sync failed: Process 'command '/usr/local/android-studio/jre/bin/java'' finished with non-zero exit value 2
Consult IDE log for more details (Help | Show Log)
delete .gradle file (fail)
restart android studio/pc (fail)
offline work (fail)
use local gradle distro (fail)
reinstall (fail)
update android studio (fail)
for more information : this is the first time im using android studio.
edit : sorry for my formatting
I did this in Android studio 2.3:
Download new version of gradle from http://services.gradle.org/distributions/ and extract it. Open your project go to file>settings choose build, execution, deployment select gradle choose 'use local gradle distribution' and set the path to the updated gradle. Import project again (make sure you're connected to the internet).
I have found the answer for me on askubuntu, but since I found this thread first, I'll post it here for others:
The problem is there in the error report:
/usr/local/android-studio/jre/bin/java
It tries to find a java runtime in its own folder, while you probably have java installed elsewhere. Simply go to File -> Other Settings -> Default Project Structure, and set the JDK folder to the root folder of your JDK. (e.g. C:\Program Files\jdk1.8.0_111)
I just wish it was more clear on what its problem was...
Try below codes in your app level build.gradle file
multiDexEnabled = true
dexOptions {
preDexLibraries = false
incremental true
javaMaxHeapSize "4g"
}
This issue is quite possibly due to exceeding the 65K methods dex limit imposed by Android. This problem can be solved either by cleaning the project, and removing some unused libraries and methods from dependencies in build.gradle, OR by adding multidex support.
So, If you have to keep libraries and methods, then you can enable multi dex support by declaring it in the gradle config.
defaultConfig {
// Enabling multidex support.
multiDexEnabled true
}
Also it is possible that two or more liabraries conflict (same library but different versions). Check your app build.gradle in dependencies block.
Here are possibility of mulitple reasone for Gradle Sync Failed.
1) You have same library or jar file included several places and some of them conflicting with each other.
2) Check if you have 2 classes with same name.
Solutions
1) Remove unnecessary complie library code in build.gradle
dependencies { compile 'com.google.android.gms:play-services:7.5.0' } which was causing over 65k methods, so removed it,gradle sync, cleaned project, and then ran again and then this error stopped. I needed just maps and gcm so i put these lines and synced project
compile 'com.google.android.gms:play-services-gcm:7.5.0' compile 'com.google.android.gms:play-services-location:7.5.0'
2) Add below code to your build.gradle file.It may manage duplication of libraries
packagingOptions { exclude 'META-INF/NOTICE' exclude 'META-INF/notice.txt' exclude 'META-INF/NOTICE.txt' }
defaultConfig { ... ... multiDexEnabled true }
For Reference Java finished with non-zero exit value 2 - Android Gradle
I'm having some strange issue with Android Studio recently. I'm trying to build a project after few modification in code. But the APK got installed is of old code. (I found this by debugging. When I debugged it was going to empty lines) But all my latest code are saved and it's there. I have tried the following steps which I know.
Delete the build folders of Project and Module manually > Restart Studio > Clean Project > Rebuild Project
Restart Android Studio and (I don't know why I restarted but I did that too)
Invalidate and Cache Restart
At some point I found a issue in XML related to style attribute for button which was like style:attr/buttonBarButtonStyle I later corrected to style:"?android:attr/buttonBarButtonStyle"I hope this change is correct because it don't show any more error.
And finally it doesn't give me any error in stacktrace. Project always shows BUILD SUCCESSFUL
Nothing above helped me.
EDIT 1 : I have updated my Android Support Library to 22.1.1 latest version which released a couple of days ago
EDIT 2 : I uninstalled Android Studio. Deleted Android Studio related folders in C:\Program Files\Android\Android Studio and also deleted C:\Users\MyUserName\.android & .AndroidStudio & .gradle folders. And did fresh install of Android Studio. Later I imported a same project and build it. Again it happens in same way! I have also tried running the same project in other lap and it runs without any problem. I Don't know what else I'm missing here
EDIT 3 : Updating my build.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 22
buildToolsVersion "22.0.0"
signingConfigs {
debug {
storeFile file("./debugkeystore/MyAppDebug.keystore")
}
}
defaultConfig {
applicationId "com.example.myapp"
minSdkVersion 14
targetSdkVersion 22
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:22.0.0'
compile 'com.google.android.gms:play-services:6.1.+'
compile 'com.android.support:recyclerview-v7:+'
compile 'com.android.support:support-v4:22.0.+'
compile 'com.android.support:cardview-v7:21.0.+'
}
I just again uninstalled AndroidStudio and clear the registery and made it like a fresh install for the 3rd time and I don't know how but this time it worked! But didn't get what exactly happened!
I solved it by rebuilding the project. Go to the build tab
you should configure Run/Debug Configuration again and add to "Before launch" section "Gradle-aware Make"
that's it
I'm working on an Android Studio project of which I write while constantly move back and forth from laptop to desktop using usb stick. There has been no problem for couple of months I tried this since Android Studio went stable, until today this message keeps showing up no matter how many times I sync the gradle:
Gradle files have changed since last project sync. A project sync may be necessary for the IDE to work properly.
Gradle Console indicates that the build is successful. I also tried cleaning and rebuilding the project, even reinstalling Android Studio, still the message pops out.
What seems to be the problem? Is it not recommended to write a project on multiple Android Studios?
Here's a look of my build.gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
defaultConfig {
applicationId "com.simplifyinc.prodigy"
minSdkVersion 16
targetSdkVersion 21
versionCode 1
versionName "0.3.2"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:21.0.3'
compile 'de.hdodenhof:circleimageview:1.2.1'
compile 'com.oguzdev:CircularFloatingActionMenu:1.0.2'
compile 'net.the4thdimension:audio-wife:1.0.3'
compile project('libraries:android-crop')
}
in build.gradle(module:app)
change
build tool,( in my case its 23.0.1)
targetSdkVersion (23) and
in dependency
compile version
("com.android.support:appcompat-v7:23.1.0")
to latest
This happens due to gradle updates
*****Check your PC date*****
You must check your PC or laptop date and time. Correct your date and time will resolve your issue.
each IDE(even if it is the same build number) uses its own metadata. an example would be the location of the Android sdk.when shuffling files between different systems, you would have to make sure that none of the system generated files are copied.
the safest way would be to delete the all the files and folders mentioned in the . gitignore file.
and as in this particular case, the .idea folder.
The modified date for some of my files were set to a future date/time (still havent figured out the cause). Updating the modified time of each file in the project using touch -mt YYYYMMDDhhmm ./* and then the same for those with a . prefix touch -mt YYYYMMDDhhmm ./.* fixed this for me.
this error had happened to me when I changed my computer time carelessly
configer my computer time,and reset the time,this error solved
this error happen when android studio 2.3.3 available and i ignore it, upgrade your android studio to 2.3.3
For Me Below Steps Worked:
1) Delete .idea folder
2) Delete build folder
3) opened each file mentioned in .ignore with notepad and add a space , remove a space and saved file again. this will not effects the file but the trick is notepad changes the Date modified attribute of file.
I want to build an app in Android Studio with the support library but I get the following error when adding the dependency for the support library:
Error:Failed to find: com.android.support:support-v4:19.1.0
Here is my build.gradle file
apply plugin: 'com.android.application'
android {
compileSdkVersion 19
buildToolsVersion '20'
defaultConfig {
applicationId "sample.myapplication"
minSdkVersion 15
targetSdkVersion 19
versionCode 1
versionName "1.0"
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:support-v4:19.1.0'
}
I have downloaded the support library via the sdk manager.
Ok, found the problem. The Android support repository was missing. After installing and restarting Android Studio it worked.
If you are using Android Studio, then as an addition to changing the build.gradle file manually, you can also lookup the dependency via the library dependencies under the Project Structure menu item.
Double clicking that dependency will generate this line in build.gradle:
dependencies {
compile 'com.android.support:support-v13:+'
}
And also, if you are wondering what this library is about, it's described at the developer pages at developer.android.com; Support Library.
My Android Studio version is 1.1. I select tools->Android->SDK Manager, check the Android Support Library then click Install packages, solved this issue.
In my case the solution was as simple as running Build:Make Project. No amount of gradle syncing or clearing caches would do it. Of course, that required getting my project into a state where it would build successfully.
In my case I needed to add Google Maven repository.
It shows as part of the error in Android Studio and only needed to click on it to add itself.
Then Gradle built the project on its own.
Following the instruction here helped me. For whatever reason when I had to reinstall the latest version of android studio the initial download of the extras section android support library failed. I simply retried it. Followed the steps mentioned and verified it was added to the build.gradle file and did a rebuild project and good to go.
http://developer.android.com/tools/support-library/setup.html
Sorry for my poor English. I'm trying to migrate my project to Gradle with Android Studio, but currently the build fails during processDebugResources.
error info:
Execution failed for task ':app:processAdultDebugResources'.
java.io.FileNotFoundException: C:\Projects\YYM\app\build\symbols\adult\debug\R.txt (系统找不到指定的文件。)(That Chinese means "System cannot find the file")
In addition, I found that in the build path of my project there was a R.java file under a strange path: build/source/r/debug/--output-text-symbols.
Here is a part of my build.gradle:
apply plugin: 'android'
android {
compileSdkVersion 19
buildToolsVersion '19.0.1'
defaultConfig {
minSdkVersion 10
targetSdkVersion 19
versionCode 78
versionName "1.7.72"
ndk {
abiFilters "armeabi"
}
}
productFlavors {
weightloss {
packageName "com.yesudoo.yymweightloss"
}
adult {
packageName "com.yesudoo.yymadult"
}
}
buildTypes {
debug {
packageNameSuffix ".dev"
versionNameSuffix "-dev"
}
}
lintOptions {
abortOnError false
}
}
I'm new in Gradle, and thanks in advance for any pointers on how to solve this problem.
So the way I fixed this was:
inside my androidTest folder, I had a java folder with my test files. But gradle requires you to have some resources inside test so that it generates the R.txt file. So what I did was created a res folder inside androidTest and added a values/strings.xml folder with one string resource.
This allowed my tests to build and run!
I had the same problem, beginning when I fumbled around adding a second sub-subfolder to my assets directory. Removing the folder (basically undoing what I did to cause the problem) didn't help, which indicated it may be a problem with caches. The accepted answer may work, if by changing the manifest file you trigger Android Studio to invalidate its caches (apparently this is more than clean and rebuild, as I tried that several times).
Simple thing to try: go to File->Invalidate Caches and Restart.
This worked for me, maybe this helps someone
build.gradle:
classpath 'com.android.tools.build:gradle:2.3.2'
gradle/wrapper/gradle-wrapper.properties:
distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip
Sync Now.
Solved. The reason is that the AndroidManifest.xml file had something wrong, but gradle(or lint?) didn't figure it out. Thus the R.txt file couldn't be generated. As soon as I amended the AndroidManifest.xml file, the problem was gone.
Sorry again for my poor English.