Finished with non-zero exit value - java

I get this error when I try to run the app
Error:Execution failed for task ':app:transformClassesWithDexForDebug'.
com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Program Files\Java\jdk1.7.0_25\bin\java.exe'' finished with non-zero exit value 2
Gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
applicationId "com.dusanp.passer"
minSdkVersion 19
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard- android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:design:23.1.1'
compile 'com.parse.bolts:bolts-android:1.+'
compile 'com.parse:parse-android:1.+'
compile fileTree(include: 'Parse-*.jar', dir: 'libs')
compile 'com.android.support:support-v4:23.+'
compile fileTree(include: ['*.jar'], dir: 'libs')
compile files('libs/sinch-android-rtc-3.7.1.jar')
}

Android application (APK) files contain executable bytecode files in the form of Dalvik Executable (DEX) files, which contain the compiled code used to run your app. The Dalvik Executable specification limits the total number of methods that can be referenced within a single DEX file to 65,536, including Android framework methods, library methods, and methods in your own code. Getting past this limit requires that you configure your app build process to generate more than one DEX file, known as a multidex configuration
This might be 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.
Setting up your app development project to use a multidex configuration requires that you make a few modifications to your app development project. In particular you need to perform the following steps:
Change your Gradle build configuration to enable multidex
Modify your manifest to reference the MultiDexApplication class
Here is the complete details: https://developer.android.com/tools/building/multidex.html

Related

Edit / Delete classes in external third party library jar files in android?

I am using external third party libraries in my project, but the problem I am facing is, two different jar files contains a class with the same name.
Following are the libs I am using
jaxen-1.1-beta-2.jar
jaxen-core.jar
The above given jar files share a class with the same name called "DefaultNavigator.class" so because of this i am getting the following duplicate class error.
com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: org/jaxen/DefaultNavigator.class
I need to know whether i can edit/delete unused classes or repeated classes given in the external third party jar files or please guide me whether i can copy only the classes that i required from all the jars and put them up in a single jar file and use. if this is possible please tell me how to do this. I am a beginner to android. Below I am attaching my build.gradle file.
build.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.3"
defaultConfig {
applicationId "com.xxx.xxx.yyy"
minSdkVersion 14
targetSdkVersion 22
versionCode 1
versionName "1.0"
multiDexEnabled true
}
configurations {
all*.exclude group: 'com.android.support', module: 'support-v4'
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'),'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.4.0'
compile 'com.google.android.gms:play-services-appindexing:8.1.0'
compile 'com.android.support:support-v4:23.4.0'
compile 'com.android.support:multidex:1.0.1'
compile files('libs/xsdlib-1.5.jar')
compile files('libs/relaxngDatatype-2.2.jar')
compile files('libs/javax.xml.stream.jar')
compile files('libs/pull-parser-2.jar')
compile files('libs/javax.xml.bind.jar')
compile files('libs/java-rt-jar-stubs-1.5.0.jar')
compile files('libs/jaxen-core.jar')
compile files('libs/jaxen-dom4j.jar')
compile files('libs/jaxen-1.1-beta-2.jar')
}

java.util.zip.ZipException: duplicate entry: javax/inject/Inject.class

I have seen similar responses to the below question. Sorry but i could not fixed it out trying multiple things so I am asking it again.
Whenever I am trying to build my app, the gradle build throws me the below error stating ...due to duplicate entry of javax/Inject class.
This only occurred when I am trying to put compile 'org.glassfish.jersey.containers:jersey-container-jdk-http:2.9' in my build.gradle file; This package is necessary for javax.ws.rs.* services.
I tried running the gradlew clean command in my root directory, it says that build is successful but when I am building my application again it started throwing the error again.
Can you please help on the below error:
*Error:Execution failed for task ':app:transformClassesWithJarMergingForDebug'.
> com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: javax/inject/Inject.class*
Below is my app gradle file:
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.3"
defaultConfig {
applicationId "com.usfca.studentrecordsverifycation"
minSdkVersion 17
targetSdkVersion 23
versionCode 1
versionName "1.0"
// Enabling multidex support.
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
repositories {
maven { url 'http://repo1.maven.org/maven2' }
maven { url 'http://maven.restlet.com' }
maven { url 'https://maven.java.net/content/repositories/releases/' }
maven { url 'http://download.java.net/maven/2/' }
maven { url 'http://download.java.net/maven/1' }
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.3.0'
compile 'com.android.support:design:23.3.0'
compile 'com.android.support:multidex:1.0.1'
compile 'log4j:log4j:1.2.17'
compile 'com.google.code.gson:gson:2.2.4'
compile 'com.madgag:sc-light-jdk15on:1.47.0.3'
compile 'com.cloudinary:cloudinary-http44:1.4.5'
compile 'org.glassfish.jersey.containers:jersey-container-jdk-http:2.9'
compile 'commons-lang:commons-lang:2.6'
}
Below is my Project gradle:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.1.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
}
Ok so I created a sample project with all those dependencies and I got a different error.
So if you are still getting the ZipException error, you have some jars in your lib folder that we are not aware of?
Here's the error I got:
Execution failed for task ':app:transformResourcesWithMergeJavaResForDebug'.
> com.android.build.api.transform.TransformException: com.android.builder.packaging.DuplicateFileException: Duplicate files copied in APK META-INF/LICENSE
If you are getting a similar error, all you need to do is add the following to your build.gradle:
android {
defaultConfig {
...
}
buildTypes {
....
}
packagingOptions {
exclude 'META-INF/LICENSE'
}
}
If this doesn't make any difference, do you have any jar libraries in your project? If so, we need to see the list.
EDIT:
I can't know for sure if it will work because I am not getting the same error. In your dependencies, change to this:
compile ('org.glassfish.jersey.containers:jersey-container-jdk-http:2.9') {
exclude group: 'javax.inject', module: 'javax.inject'
}
This error means that the class javax.inject.Inject is being included twice in your apk when the dexer runs. That is, this exact same class is coming from 2 different dependencies. One of them is probably org.glassfish.jersey.containers:jersey-container-jdk-http:2.9 because it happens after you added it.
If you CMD+O (jump to class) on Android Studio, you should be able to see the 2 versions of this class and see where they are coming from. Make sure you select the checkbox that allows it to show classes included from your dependencies. Once you open them, hover over the file tab and you'll see a tooltip with the artifact name. That is gonna be the dependency that's including that class.
Hope it makes sense.

Error while compling the android application - Execution failed for task :app:transformClassesWithDexForDebug

My app was compiling properly, before i added an google maps activity. Then i get this error
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:transformClassesWithDexForDebug'.
> com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command '/usr/lib/jvm/java-8-openjdk-amd64/bin/java'' finished with non-zero exit value 2
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
Error:The number of method references in a .dex file cannot exceed 64K.
Learn how to resolve this issue at https://developer.android.com/tools/building/multidex.html
:app:transformClassesWithDexForDebug FAILED
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.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command '/usr/lib/jvm/java-8-openjdk-amd64/bin/java'' finished with non-zero exit value 2
build.gradle
android {
compileSdkVersion 24
buildToolsVersion "23.0.3"
useLibrary 'org.apache.http.legacy'
defaultConfig {
applicationId "zupportdesk.desk.zupport.chatsystem"
minSdkVersion 15
targetSdkVersion 24
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:24.2.0'
compile 'com.android.support:recyclerview-v7:24.2.0'
compile 'com.android.support:design:24.2.0'
compile 'com.android.support:cardview-v7:24.2.0'
compile 'org.java-websocket:Java-WebSocket:1.3.0'
compile 'com.google.android.gms:play-services:9.4.0'
compile 'br.com.liveo:navigationdrawer-material:2.5.1'
compile files('libs/gson-2.2.2.jar')
compile files('libs/signalr-client-sdk-android.jar')
compile files('libs/signalr-client-sdk.jar')
}
Can someone help me to fix this issue. tnx
After adding the google maps, the method and references count exceed 64K:
Error:The number of method references in a .dex file cannot exceed 64K.
This is a big problem that every big project encounter such a problem. But the Google gave a solution : Configure Apps with Over 64K Methods.
Hope this can help you.
According to your question
Instead of
compile 'com.google.android.gms:play-services:9.4.0'
Use this
com.google.android.gms:play-services-maps:9.4.0
This will only include play service required for maps only.Your code will import all packages of play services which will cause your app to cross 64K method limits
Add this to your build.gradle after the buildTypes{ ... }:
dexOptions {
javaMaxHeapSize "4g"
}
Add this dependency in gradle... your app has reached the 64k reference limit. More of it here
compile 'com.android.support:multidex:1.0.0'
also add this
android {
defaultConfig {
// Enabling multidex support.
multiDexEnabled true
}
}
According to Google's suggestion: Selectively compiling APIs into your executable, you can try to replace the following line in your build.gradle file:
compile 'com.google.android.gms:play-services:9.6.1'
with what you need:
compile 'com.google.android.gms:play-services-maps:9.6.1'
compile 'com.google.android.gms:play-services-xxx2:9.6.1'
compile 'com.google.android.gms:play-services-xxx3:9.6.1'

Gradle error when importing mongoDB jar driver

I have an issue with gradle when importing this mongoDB jar driver in android studio. I am getting this error:
Error:Execution failed for task ':app:dexDebug'.
com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Program Files\Java\jdk1.8.0_25\bin\java.exe'' finished with non-zero exit value 2
When i import the mongo-java-driver-2.13.0-rc0.jar driver i have no issue with this. I do not know if this is relevant but first i imported this driver and then any other mongoDB driver is having this error except from this one that i added first. Here is my gradle file
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
useLibrary 'org.apache.http.legacy'
repositories {
mavenCentral()
jcenter()
}
defaultConfig {
applicationId "com.example.irakl_000.maps"
minSdkVersion 19
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.0'
compile 'com.google.android.gms:play-services:8.3.0'
compile 'com.android.support:design:23.1.0'
compile 'com.android.support:percent:23.1.0'
compile 'com.facebook.android:facebook-android-sdk:4.7.0'
compile 'de.hdodenhof:circleimageview:2.0.0'
compile 'com.isseiaoki:simplecropview:1.0.13'
compile files('libs/mongo-java-driver-3.2.0-SNAPSHOT.jar')
Any answers to similar questions in stackoverflow did not help, so any help is much appreciated!
EDIT: I created a new project and there are no errors, so obviously something is wrong with the project and not with the grandle file or jar
EDIT:
When i run gradle compileDebug --stacktrace i get the following
* Exception is:
org.gradle.execution.TaskSelectionException: Task 'compileDebug' is ambiguous in root project 'Maps'. Candidates are: 'compileDebugAidl', 'compileDebugAndroidTestAidl', 'compileDebu
gAndroidTestJavaWithJavac', 'compileDebugAndroidTestNdk', 'compileDebugAndroidTestRenderscript', 'compileDebugAndroidTestSources', 'compileDebugJavaWithJavac', 'compileDebugNdk', 'c
ompileDebugRenderscript', 'compileDebugSources', 'compileDebugUnitTestJavaWithJavac', 'compileDebugUnitTestSources'.
at ...
You may have a problem with the limit of 65k methods allowd on an android studio project. Google announced a solution to this problem. You can find more information here. I had a similar problem and this was the solution for me so you could give a try.
UPDATE
I should mention that this could seriously reduce your gradle build time so you should use it only if there is no other way. The best think you can do is to reduce the libraries you use to the ones you need.
You can also refer to this answer to reduce your google-play-services to the ones you actually need.
It looks like you're depending on a single jar twice between these two dependencies:
compile fileTree(include: ['*.jar'], dir: 'libs')
compile files('libs/mongo-java-driver-3.2.0-SNAPSHOT.jar')
The first line is declaring a dependency on everything in the libs directory. The second line is then adding another dependency on a specific jar in the libs folder, which was already covered in the first line. You're effectively telling gradle to use that jar twice, which could cause problems. You're probably also getting a message from gradle to run the build again with different command line flags to see more detailed errors, so do that as well.
Consider removing one or the other. If you have other jars in the libs folder, you'll probably want to remove the second line.

java.lang.NoClassDefFound error javax Gmail API

I'm running into an exception in a gmail client I'm working on. The exception is the
java.lang.NoClassDefFound that is triggered on the getDefaultInstance line
Properties props = new Properties();
Session session = Session.getDefaultInstance(props, null);
I've included the javax jar as follows:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:22.2.0'
compile 'com.google.android.gms:play-services:7.3.0'
compile 'com.google.api-client:google-api-client:1.20.0'
compile 'com.google.api-client:google-api-client-android:1.20.0'
compile 'com.google.api-client:google-api-client-gson:1.20.0'
compile 'com.google.apis:google-api-services-gmail:v1-rev29-1.20.0'
compile 'javax.mail:javax.mail-api:1.5.2'
}
I've googled this but not quite sure how to fix this. I've tried clean and rebuild and in both cases the exception is still thrown. Any help would be appreciated.
Exeception detail Message:
Didn't find class "com.sun.mail.util.MailLogger" on path: DexPathList[[zip file "/data/app/com.android.application.androidgmailclient-2/base.apk"],nativeLibraryDirectories=[/vendor/lib, /system/lib]]
UPDATE
I found that the missing class "MailLogger" is not a part of the javax.mail-api rather it is a part of the 'javax.mail:mail:1.5.0-b01' jar with 1.5.0-b01 being the latest version:
http://mvnrepository.com/artifact/javax.mail/mail/1.5.0-b01
So I included the compile 'javax.mail:mail:1.5.0-b01' into my gradle file and then I found the jar in the external libraries. I copied the jar into app/libs and then hit "Add as Library". I can see that the MailLogger class is now present which is what was bombing in the exception. My gradle file now looks like this:
apply plugin: 'com.android.application'
android {
compileSdkVersion 22
buildToolsVersion "23.0.0 rc2"
packagingOptions{
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
}
defaultConfig {
applicationId "com.android.app.androidgmailclient"
minSdkVersion 16
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.2.0'
compile 'com.google.android.gms:play-services:7.3.0'
compile 'com.google.api-client:google-api-client:1.20.0'
compile 'com.google.api-client:google-api-client-android:1.20.0'
compile 'com.google.api-client:google-api-client-gson:1.20.0'
compile 'com.google.apis:google-api-services-gmail:v1-rev29-1.20.0'
compile 'javax.mail:mail:1.5.0-b01'
compile files('libs/mail-1.5.0-b01.jar')
}
However, when I go to build the project now I get this build error:
Error:Execution failed for task ':app:dexDebug'.
com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command '/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home/bin/java'' finished with non-zero exit value 2
Any ideas?
Not sure if you solved this already, but I found you need to use an Android specific Java Mail library.
compile 'com.sun.mail:android-mail:1.5.5'
compile 'com.sun.mail:android-activation:1.5.5'
I was running into your error and other similar ones using the latest Java Mail libraries but switching to these fixed all of them.
https://java.net/projects/javamail/pages/Android
Android Studio: NoClassDefFoundError
This error occurred because you are adding same library twice.
compile 'javax.mail:mail:1.5.0-b01'
compile files('libs/mail-1.5.0-b01.jar')
delete one of these line then I think it should work fine.
I assume you have compiled your code successfully, but got a runtime exception. You need to include the jar files in the final package. Have a look at this one, and this one.

Categories