Android gradle execution fails on :myapp:dexDebug - java

My gradle execution fails with the error message listed below. I have searched a number of other answers on SO that suggest doing this:
dexOptions {
preDexLibraries = false
}
Some say it may be a memory error, some say it may be that a dependency may already include one of the dependencies I'm trying to compile. I've included the error message below along with my build.gradle file where you'll e able to see what dependencies I'm using. Any help is much appreciated!
buildscript {
repositories {
jcenter()
maven { url 'https://maven.fabric.io/public' }
}
dependencies {
classpath 'com.android.tools.build:gradle:0.13.3'
// The Fabric Gradle plugin uses an open ended version to react
// quickly to Android tooling updates
classpath 'io.fabric.tools:gradle:1.+'
}
}
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
repositories {
jcenter()
maven { url 'https://maven.fabric.io/public' }
}
android {
compileSdkVersion 21
buildToolsVersion '20.0.0'
defaultConfig {
applicationId "com.dreamengine.shout"
minSdkVersion 13
targetSdkVersion 21
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
dexOptions {
preDexLibraries = false
}
}
dependencies {
//compile 'com.android.support:support-v4:+'
compile files('libs/Parse-1.7.1.jar')
compile 'com.squareup.picasso:picasso:2.3.4'
compile 'com.firebase:firebase-client-android:2.0.3'
compile 'com.squareup.okio:okio:1.0.0'
compile 'com.squareup.okhttp:okhttp-urlconnection:2.1.0'
compile 'com.squareup.okhttp:okhttp:2.1.0'
compile 'com.squareup.retrofit:retrofit:1.8.0'
compile 'com.android.support:appcompat-v7:21.+'
compile 'com.google.android.gms:play-services:6.5.+'
compile 'com.google.code.gson:gson:2.2.4'
compile 'com.github.asne.facebook:facebook:3.17.2'
compile 'com.braintreepayments.api:braintree:1.+'
compile "com.mixpanel.android:mixpanel-android:4.4.1#aar"
// Crashlytics Kit
compile('com.crashlytics.sdk.android:crashlytics:2.1.0#aar') {
transitive = true
}
// Twitter Kit
compile('com.twitter.sdk.android:twitter:1.1.0#aar') {
transitive = true
}
// MoPub Kit
compile('com.mopub.sdk.android:mopub:3.2.2#aar') {
transitive = true
}
//Foursquare
compile fileTree(dir: 'libs', include: ['*.jar'])
compile project(':Libraries:easyFoursquare4Android')
}
FAILURE: Build failed with an exception.
What went wrong:
Execution failed for task ':app:dexDebug'.
com.android.ide.common.internal.LoggedErrorException: Failed to run command:
/Applications/Android Studio.app/sdk/build-tools/android-4.4W/dx --dex --num-threads=4 --output ...
Error Code:
137

Running of dx requires spawning a new VM. Creating fails, check if you have enough memory and/or set defaultXmx=-Xmx512m (or lower). Please also check out the answers here Android gradle build script returns error 137 in preDexDebug

Related

Gradle - Couldn't expand zip cardview-v7-23.3.0.aar

I try to implement firebase into my app. But there is an interference between firebase and google play service.
Here is my build.gradle for the module:
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
defaultConfig {
applicationId "com.example.nefrin.client"
minSdkVersion 19
targetSdkVersion 25
versionCode 1
versionName "1.0"
// Enabling multidex support.
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
dexOptions {
incremental true
javaMaxHeapSize "4g"
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.google.android.gms:play-services:11.0.4'
compile 'com.github.tajchert:nammu:1.1.3'
compile 'gun0912.ted:tedpermission:1.0.3'
compile 'com.github.jksiezni.permissive:permissive:0.2'
compile 'com.github.arimorty:floatingsearchview:2.0.3'
//compile 'net.sf.sprockets:sprockets-android:4.0.0'
compile 'com.github.michael-rapp:android-material-dialog:4.0.2'
compile 'com.github.bumptech.glide:glide:3.5.2'
compile 'com.google.firebase:firebase-auth:11.2.0'
}
apply plugin: 'com.google.gms.google-services'
And here is build.gradle for the project:
// 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:2.1.2'
classpath 'com.google.gms:google-services:3.1.0' // google-services plugin
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
maven {
url "https://jitpack.io"
}
maven {
url 'https://oss.sonatype.org/content/repositories/snapshots'
}
maven {
url "https://maven.google.com" // Google's Maven repository
}
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
When I try to run the app I get eventhough I didn't use cardview in my app:
Error:Execution failed for task ':app:prepareComAndroidSupportCardviewV72330Library'.
> Could not expand ZIP 'C:\Users\Nefrin\.gradle\caches\modules-2\files-2.1\com.android.support\cardview-v7\23.3.0\abdf83a0192c03ff190f941c6c885af18d257a2c\cardview-v7-23.3.0.aar'.
Android Studio is underlining the compile 'com.google.android.gms:play-services:11.0.4' and says:
All com.google.android.gms libraries must use the exact same version specification (mixing versions can lead to runtime crashes). Found versions 11.2.0, 11.0.4. Examples include com.google.android.gms:play-services-basement:11.2.0 and com.google.android.gms:play-services:11.0.4 less... (Ctrl+F1)
There are some combinations of libraries, or tools and libraries, that are incompatible, or can lead to bugs. One such incompatibility is compiling with a version of the Android support libraries that is not the latest version (or in particular, a version lower than your targetSdkVersion.)
As the error says all the google libraries should use the same version.
So you should update the play-services library and use the same version as firebase:
compile 'com.google.android.gms:play-services:11.2.0'
compile 'com.google.firebase:firebase-auth:11.2.0'
You need to change this line of code:
compile 'com.google.android.gms:play-services:11.0.4'
with
compile 'com.google.android.gms:play-services:11.2.0'
Hope it helps.

Unable to generate signed APK - duplicate entry: javax/annotation/CheckForNull.class

Error:Execution failed for task ':app:transformClassesWithJarMergingForRelease'. > com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: javax/annotation/CheckForNull.class
Below is my app level gradle file. I tried removing appcompat, support v4, but it was no help. The app is working fine otherwise, I'm getting the error only when I'm trying to generate a signed apk.
buildsript {
repositories {
maven { url 'https://maven.fabric.io/public' }
}
dependencies {
classpath 'io.fabric.tools:gradle:1.+'
}
}
apply plugin: 'com.google.gms.google-services'
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
android {
compileSdkVersion 25
buildToolsVersion "25.0.1"
defaultConfig {
applicationId "com.aubergine.resqv1"
minSdkVersion 16
targetSdkVersion 25
versionCode 10109
versionName "1.2.0"
// Enabling multidex support.
multiDexEnabled true
// Flag to tell aapt to keep the attribute ids around
aaptOptions {
additionalParameters "--no-version-vectors"
}
}
buildTypes {
release {
minifyEnabled false
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
repositories {
mavenCentral()
//For Mint bug reporter
maven { url "https://mint.splunk.com/gradle/" }
//For bug report and crash report
maven { url "https://jitpack.io" }
maven { url 'https://maven.fabric.io/public' }
maven { url 'http://maven.localytics.com/public' }
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
// libs for Material design
// libs for dependency Injection
// libs for Common font for Application
//libs for calling api using Retrofit
//For calling api using retrofit
//For Mint bug reporter
//For graph
//libs for MaterialDesign EditText
//For Circle Image
//for universal image loader
//For Number Picker in Estimated Time https://github.com/KasualBusiness/MaterialNumberPicker
compile('com.crashlytics.sdk.android:crashlytics:2.6.6#aar') {
transitive = true;
}
compile('com.digits.sdk.android:digits:2.0.5#aar') {
transitive = true;
}
compile 'com.android.support:appcompat-v7:25.1.0'
compile 'com.android.support:design:25.1.0'
compile 'com.android.support:support-v4:25.1.0'
compile 'com.jakewharton:butterknife:7.0.1'
compile 'uk.co.chrisjenx:calligraphy:2.1.0'
compile 'com.squareup.retrofit:retrofit:1.9.0'
compile 'com.squareup.okhttp:okhttp-urlconnection:2.0.0'
compile 'com.squareup.okhttp:okhttp:2.0.0'
compile 'com.github.PhilJay:MPAndroidChart:v2.1.5'
compile 'com.rengwuxian.materialedittext:library:2.1.4'
compile 'com.squareup.okhttp3:logging-interceptor:3.0.1'
compile 'de.hdodenhof:circleimageview:2.0.0'
compile 'com.nostra13.universalimageloader:universal-image-loader:1.9.5'
compile 'biz.kasual:materialnumberpicker:1.2.0'
compile 'com.google.android.gms:play-services-analytics:10.0.1'
compile 'com.google.firebase:firebase-appindexing:10.0.1'
compile 'com.facebook.stetho:stetho:1.4.2'
compile 'com.facebook.stetho:stetho-okhttp3:1.4.2'
compile 'com.shawnlin:number-picker:2.4.1'
compile 'com.google.android.gms:play-services-ads:10.0.1'
compile 'com.localytics.android:library:4.2.+'
compile 'com.google.firebase:firebase-core:10.0.1'
compile 'com.google.firebase:firebase-messaging:10.0.1'
testCompile 'junit:junit:4.12'
}
Also, there are two CheckForNull class, infact there are duplicate classes in jsr-305. The screenshot:
What would be a wise solution to this problem?
Please do clean for gradle build using command ./gradlew clean.

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.

Duplicate files copied in APK META-INF

hi im new in android development, i am trying to build my apk but i got this erorr. and i update my gradle and i got duplicate copy. how can i fix this error?
Error:Execution failed for task ':app:transformResourcesWithMergeJavaResForDebug'.
> com.android.build.api.transform.TransformException: com.android.builder.packaging.DuplicateFileException: Duplicate files copied in APK META-INF/maven/com.squareup.okhttp/okhttp/pom.properties
File1: C:\Users\Toshiba\.gradle\caches\modules-2\files-2.1\com.squareup.okhttp\okhttp\2.0.0\4c8d1536dba3812cc1592090dc20c47a4ed3c35e\okhttp-2.0.0.jar
File2: C:\Users\Toshiba\.gradle\caches\modules-2\files-2.1\com.crashlytics.android\crashlytics\1.1.13\e821eafa1bf489a26bdb71f95078c26785b37a1\crashlytics-1.1.13.jar
and here's my build.gradle is this the error comes?
buildscript {
repositories {
maven { url 'http://download.crashlytics.com/maven' }
}
dependencies {
classpath 'com.crashlytics.tools.gradle:crashlytics-gradle:1.+'
}
}
apply plugin: 'com.android.application'
apply plugin: 'crashlytics'
android {
compileSdkVersion 20
buildToolsVersion "20.0.0"
defaultConfig {
applicationId "com.mymonas.ngobrol"
minSdkVersion 14
targetSdkVersion 20
versionCode 1
versionName "0.9.0.68"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
repositories {
mavenCentral()
maven { url 'http://download.crashlytics.com/maven' }
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'], exclude: 'android-support-v4.jar')
compile project('libs:floatlabel')
compile 'com.android.support:support-v4:21.0.0'
compile 'com.android.support:support-v13:21.0.0'
compile 'com.squareup.retrofit:retrofit:1.7.0'
compile 'com.squareup.okhttp:okhttp-urlconnection:2.0.0'
compile 'com.squareup.okhttp:okhttp:2.0.0'
compile 'com.github.dmytrodanylyk.android-process-button:library:1.0.1'
compile 'com.google.android.gms:play-services:6.1.11'
compile 'com.viewpagerindicator:library:2.4.1#aar'
compile 'com.astuetz:pagerslidingtabstrip:1.0.1'
compile 'com.nostra13.universalimageloader:universal-image-loader:1.9.3'
compile 'com.makeramen:roundedimageview:1.3.0'
compile 'com.andreabaccega:android-form-edittext:1.1.0#aar'
compile 'com.crashlytics.android:crashlytics:1.+'
}
I had the same or at least a very similar problem today with our React Native app. The problem was only on my Mac though. The only plausible explanation we could think of was that I updated a bunch of Android Studio tools and then gradle couldn't build properly with our dependencies. Anyways after excluding the pom.properties and pom.xml from okhttp I kept getting the same error but it turns out that I just had to exclude even more files. This is my complete packagingOptions in build.gradle:
packagingOptions {
exclude 'META-INF/maven/com.squareup.okhttp3/okhttp/pom.properties'
exclude 'META-INF/maven/com.squareup.okio/okio/pom.xml'
exclude 'META-INF/maven/com.squareup.okhttp3/okhttp/pom.xml'
exclude 'META-INF/maven/com.squareup.okio/okio/pom.properties'
}
to solve your problem please add this to your build gradle
packagingOptions {
exclude 'META-INF/pom.properties' /*OR*/ 'META-INF/maven/com.squareup.okhttp/okhttp/pom.properties
}
It seems like okhttp and crashlytics don't work together in newer gradle versions (2.10 in my case). I fixed this by updating the crashlytics to a newer version (which is now called Fabric).
packagingOptions
{
exclude 'META-INF/maven/com.squareup.okhttp/okhttp/pom.properties
exclude 'META-INF/maven/com.squareup.okhttp/okhttp/pom.xml'
}
Please check for correct path "com.squareup.okhttp/okhttp/pom.properties" in your errorlog.

Execution failed for process app:dexDebug after adding BaseGameUtils

I just imported baseGameUtils to my android game in order to add a Google play Leaderboard however, when I press play I get this error: `Error:Execution failed for task ':app:dexDebug'.
com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command '/usr/lib/jvm/java-7-openjdk-amd64/bin/java'' finished with non-zero exit value 2`
I tried following the instructions from these two pages: Stackoverflow question 1, Stackoverflow question 2.
I tried setting the google support libraries to 22.2.1 and 8.1.0 in the basegameutils build.gradle, but then I get missing dependencies in the .java files in that library.
I'm all out of ideas and in need of help.
Thank you all in davance.
app:build.gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 22
buildToolsVersion "22.0.1"
defaultConfig {
applicationId "com.honeycomb.touchtycube"
minSdkVersion 14
targetSdkVersion 22
versionCode 11
versionName "1.1.6"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
//compile project(':facebook');
compile 'com.android.support:appcompat-v7:22.2.1'
compile 'com.google.android.gms:play-services-ads:8.1.0'
compile 'com.google.android.gms:play-services-games:8.1.0'
compile project(':BaseGameUtils')
//compile project(':libs:basegameutils')
//compile 'com.purplebrain.adbuddiz.sdk:AdBuddiz-Java:3.0.15'
compile files('src/main/java/com/honeycomb/touchtycube/testapp/libs/AdBuddiz-3.0.15.jar')
}
repositories {
maven {
url 'http://repository.adbuddiz.com/maven'
}
}
BaseBuildUtils:build_gradle:
apply plugin: 'com.android.library'
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.3.0'
}
}
dependencies {
// Set defaults so that BaseGameUtils can be used outside of BasicSamples
if (!hasProperty('appcompat_library_version')) {
ext.appcompat_library_version = '20.0.+'
}
if (!hasProperty('support_library_version')) {
ext.support_library_version = '20.0.+'
}
if (!hasProperty('gms_library_version')) {
ext.gms_library_version = '7.8.0'
}
compile "com.android.support:appcompat-v7:${appcompat_library_version}"
compile "com.android.support:support-v4:${support_library_version}"
compile "com.google.android.gms:play-services-games:${gms_library_version}"
compile "com.google.android.gms:play-services-plus:${gms_library_version}"
compile "com.google.android.gms:play-services-appstate:${gms_library_version}"
}
android {
// Set defaults so that BaseGameUtils can be used outside of BasicSamples
if (!hasProperty('android_compile_version')) {
ext.android_compile_version = 20
}
if (!hasProperty('android_version')) {
ext.android_version = '20'
}
compileSdkVersion android_compile_version
buildToolsVersion android_version
}
EDIT:
I can do a "make Project" without any errors, the errors only appear when I do a "run app" (Or well I guess it's technically "run 'configuration'").
Check you prograud rules once. Also add your gradle build file.

Categories