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
Related
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 have error when building project. Anybody have this error before. I updated to Android Studion2.3 and build normally, but now I don't know why having this error. Clean, Rebuild but still have this error.
My gradle
compileSdkVersion 25
buildToolsVersion '25'
Error:Execution failed for task
':app:transformClassesWithDexForDebug'.
com.android.build.api.transform.TransformException: java.lang.RuntimeException:
com.android.ide.common.process.ProcessException:
java.util.concurrent.ExecutionException:
com.android.ide.common.process.ProcessException: Error while executing
java process with main class com.android.dx.command.Main with
arguments {--dex --force-jumbo --num-threads=4 --multi-dex --output
D:\GIT
TECHUB\pocca_android.git\app\build\intermediates\transforms\dex\debug\folders\1000\5\slice_2
D:\GIT
TECHUB\pocca_android.git\app\build\intermediates\transforms\instantRunSlicer\debug\folders\1\5\slice_2}
add multiDexEnabled true in default config file of build.gradle like this
defaultConfig {
multiDexEnabled true
}
I found the reason, a file error log created in my app -- insufficient memory. I restart my computer and now I worked. But my computer 16Gb ram, Android Studio only use nearly 2Gb ram, but error still happen
hs_err_pid4936.log
There is insufficient memory for the Java Runtime Environment to continue.
Native memory allocation (malloc) failed to allocate 604656 bytes for Chunk::new
Possible reasons:
The system is out of physical RAM or swap space
In 32 bit mode, the process size limit was hit
Possible solutions:
Reduce memory load on the system
Increase physical memory or swap space
Check if swap backing store is full
Use 64 bit Java on a 64 bit OS
Decrease Java heap size (-Xmx/-Xms)
Decrease number of Java threads
Decrease Java thread stack sizes (-Xss)
Set larger code cache with -XX:ReservedCodeCacheSize=
This output file may be truncated or incomplete.
Out of Memory Error (allocation.cpp:390), pid=4936, tid=0x000000000000156c
JRE version: Java(TM) SE Runtime Environment (8.0_101-b13) (build 1.8.0_101-b13)
Java VM: Java HotSpot(TM) 64-Bit Server VM (25.101-b13 mixed mode windows-amd64 compressed oops)
Failed to write core dump. Minidumps are not enabled by default on client versions of Windows
You need to ensure that you didn't implement the multiple libraries in the same project. then project conflicted with both libraries.
If you face the problem please read the solution step one by one and apply the process to your error project.
Step 1
Your google play services library is being exported from other dependencies of your project and at the compile time the dex compiler gets confused.
If you're using Gradle then including this in your project's build.gradle should exclude the support library from being exported into your main project.
apply plugin: 'android'
apply plugin: 'crashlytics'
/** Must exclude exported support jars from dependencies, or get dex duplicate class error. **/
configurations {
all*.exclude group: 'com.android.support', module: 'support-v4'
all*.exclude group: 'com.google.android.gms', module: 'play-services'
}
If you're using the android studio build system. Then you should go to File -> project structure and disable -> modules.
Go through each module the and click on the dependency tab, unchecked the export column for for the support library and google play services library.
Step 2
Make sure you have downloaded Support Repository to use support library dependency in build.gradle.
Step 3
Because you may include two same libs in your project. check your build.gradle file.
dependencies {
compile 'com.android.support:appcompat-v7:+'
compile files('libs/android-support-v4.jar')
}
if your file includes compile 'com.android.support:appcompat-v7:+' and compile files*('libs/android-support-v4.jar')*, it will have this problems. delete this sentence: compile files('libs/android-support-v4.jar')
To Change Make it
dependencies {
compile 'com.android.support:appcompat-v7:+'
}
Steep 4
If you are try the way but not solve the problem than this this another way . hope you will solve the problem. Simple go to Project Folder Remove .gradle .idea folder And Go to yourproject\apps\build Remove All Directory in this Build Folder Now go to Android Studio And sync your project with gradle once using the button.
I hope this will help.
Try to disable instant run option, it's worked for me.
This error mostly occurs when you create a new project based on an existing one.
Bellow was how i fixed it:
First make sure you've set multiDexEnabled true
Delete all generated folders like .gradle, .idea and build when your project is still opened in android studio.
And then invalidate cache and restart the project.
I think it should work after that.
it's been a while that I'm using Android Studio, and up until now I was using 1.0.1,
gradle was a bit slow, around 1.5 minute for assembleDebug (my project is really big!)
but today I updated my AS to 1.2 and now same process takes about 7 to 10 minutes, and sometimes even with no result!
is there any setting I have to change to make it faster ?
honestly taking 10 minute for every debug run is a nightmare !
Also most of the time, my cpu usage is arround 10 percent! (it is actually idle!)
cause before when gradle was working it was on 100% almost all the time
had the same problem.
What I did was to change the global gradle settings to offline work which can be done by going to Preferences => Gradle. This did make a difference.
Another method I have seen people use, but which I have not used yet is to create a gradle.properties in the gradle folder like so:
Just create a file named gradle.properties in the following directory:
/home/<username>/.gradle/ (Linux)
/Users/<username>/.gradle/ (Mac)
C:\Users\<username>\.gradle (Windows)
Add this line to the file:
org.gradle.daemon=true
Please check out this link for more options as well as a detailed explanation on speeding up gradle.
Hope this helps!.
I was testing my app with Google+ log in. So I added release signing to debug version. App compiling in ~ 26 seconds.
build.gradle Module: app file
signingConfigs {
debug {
storeFile file(project.property("MyApp.signing"))
storePassword project.property("MyApp.signing.password")
keyAlias project.property("MyApp.signing.alias")
keyPassword project.property("MyApp.signing.password")
}
}
When I remove that ~ 7.5 seconds.
Next I tested offline grade
File - Settings - Build, Execution... - Build Tools - Gradle - Offline work
Now my app compiling in ~ 4.5 seconds.
Of course I also added turn on
- Compile independent modules in parallel (may require larger heap size)
- Make project automatically (only works while not running / debugging)
File - Settings - Build, Execution... - Compiler
Complete answer for this issue is as below:
Upgrade android studio to version 1.3(stable) or above 1.4(beta at the time of writing this).
Upgrade gradle to 1.3.+(+ can be replaced with some positive number) change it in your build.gradle file.
change your gradle-wrapper.properties files and add distributionUrl=https\://services.gradle.org/distributions/gradle-2.4-all.zip in last(you can remove any old entry).
Go to Preference -> Gradle and set it to work offline.
woila!!! I am able to compile and run the code in less then ~5 sec (I really mean it)
The reason could be multiDex,
turn multiDexEnabled to false in your build.gradle file (for debug only, keep it for release).
android {
...
defaultConfig {
...
multiDexEnabled false
...
}
}
In addition you should consider to use the lastest version (2.4 at the moment) by editing the gradle-wrapper.properties file and set gradle-2.4-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-2.4-all.zip
What is MultiDex : https://developer.android.com/tools/building/multidex.html
From settings go to HTTP connection and disable any proxy and you will find speed you want
I know there are 100's of questions/answers around this topic, but none of them seem to give me an answer. I know some(if not all) of my problems are around my lack of understanding of gradle in general. BUT, i'm hoping for some help.
I've got my project working just fine on my desktop. I'm traveling this week, and wanted to work on it some on my laptop. I have all the files, and have the same version of Android Studio on both machines. I kept getting all kinds of gradle errors when opening my project. I think I've went on several wild goose chases at this point.
So I decided to step back and just create a NEW basically blank project in Studio. That ALSO has all kinds of gradle issues. I tried uninstalling Android Studio and re-insatlling, and still no dice even getting a basic project to not give the gradle errors.
I am getting
11:12:27 PM Gradle 'MyApplication' project refresh failed:
A fatal exception has occurred. Program will exit.
: Gradle settings
As the error.
Below is my two gradle files.
Top Level File(which was blank in my actual project, but has something in it in the default one)
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.7.+'
}
}
allprojects {
repositories {
mavenCentral()
}
}
The next build file
apply plugin: 'android'
android {
compileSdkVersion 19
buildToolsVersion "19.0.1"
defaultConfig {
minSdkVersion 7
targetSdkVersion 19
versionCode 1
versionName "1.0"
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
dependencies {
compile 'com.android.support:appcompat-v7:+'
compile 'com.android.support:support-v4:18.0.0'
}
I am using Android Studio 0.4.2
I am at a complete loss of what is going on. I think it could be that Studio is not actually recognizing that this is an android project. I tried some of the gradlew.bat commands and I got an error mentioning that it does not like the "apply plugin: 'android'" entry. But, I have no idea why that would be.
Any thoughts on where I should start would be greatly appreciated. I have no ideas of where to go next, and guessing at it anymore is not an option.
I've got the same issue with IntelliJ IDEA(which Android Studio is based on) on my laptop and found a solution here: https://code.google.com/p/android/issues/detail?id=65219
Set File -> Settings -> Compiler -> Java Compiler -> Additional command line parameters
-Xms256m -Xmx512m
File -> Settings -> Compiler -> Gradle -> VM Options
-XX:MaxHeapSize=256m -Xmx256m
and in YourAppName/build.gradle update dependencies to use newer gradle version
classpath 'com.android.tools.build:gradle:0.9.+'
Then restart Android Studio and everything should be fine. Otherwise you can take a look at full log file by going to Help -> Show Log in Explorer
To add a little more knowledge to the 'Gradle XXXX project refresh failed'
.
Adding following line to
File -> Settings -> Compiler -> Gradle -> VM Options:
-Xmx256m
seems to solve the problem.
.
It is worth noting that it fixes only certain cause of the problem - and there may be many. In my case: the machine I'm using is 32-bit and has very little memory. As a result my compiler couldn't reserve enough memory on the heap and so refused to compile.
Therefore if you don't have much RAM try adding the above line.
If still stuck, try:
https://stackoverflow.com/a/21168562/3508719
Did you verify that you have buildToolsVersion 19.0.1 and compileSdkVersion 19 is available on you machine, since you are working on laptop I believe this is new setup.
Can you go to Tools -> Android -> SDK Manager and see if you need to install any version specified in your gradle script. Or update gradle script as per SDK and build tools you have.
My couple of issue were resolved by updating SDK and tools!
Environment Configuration
com.android.tools.build:gradle:0.4
gradle version 1.6
jdk 1.6 (OSX)
android build tools version 17
compile sdk version 17
The issue that I seem to be having is that I can’t seem to exclude lombok from being added to the apk. I tried to do it by creating a provided configuration like this:
configurations {
provided
}
sourceSets {
main { compileClasspath += configurations.provided }
}
and then adding the dependency like this:
dependencies {
provided ‘org.projectlombok:lombok:0.11.8′
}
But I’m still getting this error:
Error: duplicate files during packaging of APK <myapp>.apk
Path in archive: LICENSE
Origin 1: /<home>/.gradle/caches/artifacts-24/filestore/org.projectlombok/lombok/0.11.8/jar/e43ce2be16d8990568a4182c0bf996ad3ff0ba42/lombok-0.11.8.jar
Origin 2: /<home>/.gradle/caches/artifacts-24/filestore/org.sonatype.sisu.inject/cglib/2.2.1-v20090111/jar/7ce5e983fd0e6c78346f4c9cbfa39d83049dda2/cglib-2.2.1-v20090111.jar
:packageRelease FAILED
I have tried using lombok-api.jar which then causes a different issue regarding some AccessLevel annotation while performing dex.
Which suggests that its including the lombok jar file into the apk. This shouldn't be happening, any suggestions?
You can't use sourceSets because we use custom ones. You'd have to do the following:
android.applicationVariants.each { variant ->
variant.javaCompile.classpath += configurations.provided.
}
However, it should be possible to instead remove the dependency from our "package" config (which replaces the "runtime" one.) I'll look into it.