app:dexDebug error in build.gradle Android Studio - android

I am receiving the app:dexDebug error when trying to run my project on Android Studio. I believe it's got to do with my dependencies but I am not sure where I am going wrong.
The error is:
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.7.0_17\bin\java.exe'' finished with non-zero exit value 2
My dependencies in the build.gradle file are as follows:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.2.1'
compile 'com.android.support:design:23.2.1'
compile 'com.facebook.android:facebook-android-sdk:[4,5)'
compile 'com.google.android.gms:play-services:8.3.0'
compile 'org.springframework.android:spring-android-rest-template:1.0.1.RELEASE'
compile 'com.fasterxml.jackson.core:jackson-databind:2.3.2'
}
Can anyone point me in the correct direction here, please.
Thank you.
UPDATE
Problem solved by adding the following to my build.gradle
packagingOptions {
exclude 'META-INF/license.txt'
exclude 'META-INF/LICENSE'
exclude 'META-INF/notice.txt'
exclude 'META-INF/NOTICE'
}

Android Studio Error:Execution failed for task ':app:dexDebug' to solve it setting multiDexEnabled to true in your gradle file.
defaultConfig {
// Enabling multidex support.
multiDexEnabled true
}

The problem is most likely caused by adding all play services dependencies. You should not compile the entire package of APIs into your app, it increases the number of methods in your app. app:dexDebug error indicates you have exceeded the 65k method limit. Remove this line in your build.gradle: compile 'com.google.android.gms:play-services:8.3.0'
then choose from these seperate dependencies, the ones to add based on what your app needs. E.g to use Gcm, you only need to add compile 'com.google.android.gms:play-services-gcm:8.4.0'

Related

How to use YouTube Analytics API in Android

I need to get some statistics about a certain youtube channel searched by user, and YouTube Data API doesn't provide me enough data. So how can I use YouTube Analytics API to get more data abou an youtube channel?
I can't use their lib:
compile 'com.google.apis:google-api-services-youtubeAnalytics:v1-rev73-1.22.0'
because it gives me error, and I don't want to enable multidex:
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.dex.DexIndexOverflowException: method ID not in [0,
0xffff]: 65536
all my dependences are:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:25.0.1'
compile 'com.android.support:design:25.0.1'
compile 'com.squareup.retrofit2:retrofit:2.1.0'
compile 'com.squareup.retrofit2:converter-gson:2.1.0'
compile 'com.squareup.retrofit2:adapter-rxjava:2.1.0'
compile 'com.squareup.okhttp3:logging-interceptor:3.3.+'
compile 'io.reactivex:rxandroid:1.0.1'
compile 'com.google.android.gms:play-services-ads:10.0.1'
compile "com.google.android.gms:play-services-gcm:10.0.1"
compile ('com.google.apis:google-api-services-youtubeAnalytics:v1-rev73-1.22.0'){
exclude module: 'httpclient' //by artifact name
exclude group: 'org.apache.httpcomponents' //by group
exclude group: 'org.apache.httpcomponents', module: 'httpclient' //by both name and group
}}
Check this documentation for the different types of reports you can retrieve using the API. Most of the workarounds I have read is to add multiDexEnabled true to your app build.gradle file.
com.android.build.transform.api.TransformException
Android Studio TransformException : Error:Execution failed for task ':app:transformClassesWithDexForDebug'
Since you don't want to enable it, I can suggest to remove unused code with ProGuard. You should enable code shrinking to run ProGuard for your release builds. Enabling shrinking ensures you are not shipping unused code with your APKs.
You can refer with this another SO answer on how to get both statistics and snippet printed to the console with single api call.

generate signed APK error : java.util.zip.ZipException

I use my samsung A5 for testing app and the project is working correctly on my phone, but not working on other phones. so I want to Generate signed APK from my project. but there was an exception error:
Error:Execution failed for task '::transformClassesWithDexForRelease'.
> com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: com.android.dex.DexException: Multiple dex files define Lcom/daimajia/androidanimations/library/BaseViewAnimator;
I googled the error and these code remove that error:
multiDexEnabled true
and
packagingOptions {
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/NOTICE'
exclude 'META-INF/LICENSE'
exclude 'META-INF/license.txt'
exclude 'META-INF/notice.txt'
}
but now there is another exception:
Error:Execution failed for task ':transformClassesWithJarMergingForRelease'.
com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: com/daimajia/androidanimations/library/BaseViewAnimator.class
I think this might be because of libraries that I use, but have no idea how to handle it. below is all libraries in build.gradle :
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.1'
//for compiling card view
compile 'com.android.support:cardview-v7:23.0.0'
compile 'com.android.support:recyclerview-v7:23.0.0'
//for sticky header
compile 'com.github.carlonzo.stikkyheader:core:0.0.3-SNAPSHOT'
compile 'com.github.ksoichiro:android-observablescrollview:1.5.0'
compile 'com.nineoldandroids:library:2.4.0'
compile 'com.melnykov:floatingactionbutton:1.0.7'
compile 'com.ogaclejapan.smarttablayout:library:1.6.1#aar'
compile 'com.ogaclejapan.smarttablayout:utils-v4:1.6.1#aar'
compile 'me.drakeet.materialdialog:library:1.3.1'
compile files('libs/volley.jar')
compile 'com.daimajia.easing:library:1.0.1#aar'
compile 'com.daimajia.androidanimations:library:1.1.3#aar'
//Sweet Alert Dialog
compile 'cn.pedant.sweetalert:library:1.3'
compile 'org.apmem.tools:layouts:1.10#aar'
}
A few things...
First of all, I'd remove most of the 3rd party libraries you are including. For example,
//for sticky header
compile 'com.github.carlonzo.stikkyheader:core:0.0.3-SNAPSHOT'
compile 'com.github.ksoichiro:android-observablescrollview:1.5.0'
compile 'com.nineoldandroids:library:2.4.0'
compile 'com.melnykov:floatingactionbutton:1.0.7'
all of those are covered by the Design Support Library from Google
From the names I think you can also remove
compile 'com.ogaclejapan.smarttablayout:library:1.6.1#aar'
compile 'com.ogaclejapan.smarttablayout:utils-v4:1.6.1#aar'
compile files('libs/volley.jar') should be replaced with compile 'com.android.volley:volley:1.0.0'
and I'd also remove
//Sweet Alert Dialog
compile 'cn.pedant.sweetalert:library:1.3'
compile 'org.apmem.tools:layouts:1.10#aar'
Many of those projects you are including haven't been worked on in over 2 years.
Try to still with the support libraries from Google. You'll get most of this from the Design support library.
Last point. You are getting the Dex errors because the app is including all of these libraries and passing the 64k method limit. I suggest enabling proguard to remove un-used code and reduce the method count of your project.

Error after adding play-services library : ':app:transformClassesWithJarMergingForDebug'

My project was working perfectly with those libraries included:
// Support libraries
compile 'com.android.support:support-v4:23.1.0'
compile 'com.android.support:appcompat-v7:23.1.0'
compile 'com.android.support:cardview-v7:23.1.0'
compile 'com.android.support:recyclerview-v7:23.1.0'
// Other stuff
compile 'com.jakewharton:butterknife:7.0.1'
compile 'com.squareup.picasso:picasso:2.5.2'
compile 'com.google.code.gson:gson:2.3'
compile 'com.squareup.retrofit:retrofit:1.9.0'
compile 'com.afollestad:material-dialogs:0.7.8.1'
compile 'com.jpardogo.materialtabstrip:library:1.1.0'
compile 'com.melnykov:floatingactionbutton:1.3.0'
compile 'com.code-troopers.betterpickers:library:2.0.0'
compile 'com.loopj.android:android-async-http:1.4.9'
compile 'com.squareup.okhttp:okhttp:2.5.0'
compile 'com.facebook.fresco:fresco:0.7.0'
now i tried to follow this tutorial: Set up a GCM Client App on Android
I added
Add the dependency to your project's top-level build.gradle:
classpath 'com.google.gms:google-services:1.4.0-beta3'
Add the plugin to your app-level build.gradle:
apply plugin: 'com.google.gms.google-services'
Then i added :
compile "com.google.android.gms:play-services:8.1.0"
Now when i try to sync, clean, or rebuild. Gradle shows me it is done successfully.
THE ERROR:
When i try to run the app and choose device. I get this error:
Error:Execution failed for task ':app:transformClassesWithJarMergingForDebug'.
> com.android.build.transform.api.TransformException: java.util.zip.ZipException: duplicate entry: android/support/v4/accessibilityservice/AccessibilityServiceInfoCompat$AccessibilityServiceInfoIcsImpl.class
This is the last version of my app-level build.gradle:
apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'
android {
packagingOptions {
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/LICENSE'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/license.txt'
exclude 'META-INF/NOTICE'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/notice.txt'
exclude 'META-INF/ASL2.0'
exclude 'META-INF/services/javax.annotation.processing.Processor'
}
compileSdkVersion 23
buildToolsVersion "23.0.0"
defaultConfig {
applicationId "com.mbh.gcmTest"
minSdkVersion 15
targetSdkVersion 23
versionCode 12
versionName "1.2.2"
// Enabling multidex support. trying to fix
multiDexEnabled true
}
lintOptions {
disable 'InvalidPackage'
}
buildTypes {
release {
minifyEnabled false
}
}
dexOptions {
preDexLibraries = false
}
productFlavors {
}
}
//compile fileTree(include: ['*.jar'], dir: 'libs')
//debugCompile 'com.squareup.leakcanary:leakcanary-android:1.3.1'
//releaseCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.3.1'
dependencies {
provided 'org.glassfish:javax.annotation:10.0-b28'
// Support Libraries
compile 'com.android.support:support-v4:23.1.0'
compile 'com.android.support:appcompat-v7:23.1.0'
compile 'com.android.support:cardview-v7:23.1.0'
compile 'com.android.support:recyclerview-v7:23.1.0'
compile 'com.jakewharton:butterknife:7.0.1'
compile 'com.squareup.picasso:picasso:2.5.2'
compile 'com.google.code.gson:gson:2.3'
compile 'com.squareup.retrofit:retrofit:1.9.0'
compile 'com.afollestad:material-dialogs:0.7.8.1'
compile 'com.jpardogo.materialtabstrip:library:1.1.0'
compile 'com.melnykov:floatingactionbutton:1.3.0'
compile 'com.code-troopers.betterpickers:library:2.0.0'
compile 'com.loopj.android:android-async-http:1.4.9'
compile 'com.squareup.okhttp:okhttp:2.5.0'
compile 'com.facebook.fresco:fresco:0.7.0'
// FOR GCM
compile 'com.android.support:multidex:1.0.1'
compile 'com.google.android.gms:play-services:8.1.0'
}
after trying the answer provided by #JBirdVegas I got this error:
Error:Execution failed for task ':app:transformClassesWithDexForDebug'.
> com.android.build.transform.api.TransformException: com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Program Files\Java\jdk1.8.0_51\bin\java.exe'' finished with non-zero exit value 1
this is gradle log:
Note: the configuration refers to the unknown method 'void attachBaseContext(android.content.Context)' in class 'com.emse.emseportal3.App'
Note: there were 1 references to unknown class members.
You should check your configuration for typos.
Note: there were 14 classes trying to access annotations using reflection.
You should consider keeping the annotation attributes
(using '-keepattributes *Annotation*').
(http://proguard.sourceforge.net/manual/troubleshooting.html#attributes)
Note: there were 20 classes trying to access generic signatures using reflection.
You should consider keeping the signature attributes
(using '-keepattributes Signature').
(http://proguard.sourceforge.net/manual/troubleshooting.html#attributes)
Note: there were 3 classes trying to access enclosing classes using reflection.
You should consider keeping the inner classes attributes
(using '-keepattributes InnerClasses').
(http://proguard.sourceforge.net/manual/troubleshooting.html#attributes)
Note: there were 15 unresolved dynamic references to classes or interfaces.
You should check if you need to specify additional program jars.
(http://proguard.sourceforge.net/manual/troubleshooting.html#dynamicalclass)
Note: there were 33 accesses to class members by means of introspection.
You should consider explicitly keeping the mentioned class members
(using '-keep' or '-keepclassmembers').
(http://proguard.sourceforge.net/manual/troubleshooting.html#dynamicalclassmember)
Note: you're ignoring all warnings!
Preparing output jar [D:\EmseArge\Mohamad\Android\EmsePortal2\app\build\intermediates\multi-dex\debug\componentClasses.jar]
Copying resources from program jar [D:\EmseArge\Mohamad\Android\EmsePortal2\app\build\intermediates\transforms\CLASSES\FULL_PROJECT\jarMerging\debug\classes.jar]
:app:transformClassesWithDexForDebug
Uncaught translation error: java.util.concurrent.ExecutionException: java.lang.OutOfMemoryError: GC overhead limit exceeded
Uncaught translation error: java.util.concurrent.ExecutionException: java.lang.OutOfMemoryError: GC overhead limit exceeded
Uncaught translation error: java.util.concurrent.ExecutionException: java.lang.OutOfMemoryError: GC overhead limit exceeded
3 errors; aborting
Error:Execution failed for task ':app:transformClassesWithDexForDebug'.
> com.android.build.transform.api.TransformException: com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Program Files\Java\jdk1.8.0_51\bin\java.exe'' finished with non-zero exit value 1
Information:BUILD FAILED
Looks like play-services already contains support-v4. Try excluding it from the classpath
compile('com.google.android.gms:play-services:8.1.0') {
exclude group: 'com.android.support', module: 'support-v4'
}
The second error is different. First thing don't use Java8 it's not supported instead use Java7 Also what version of the Android Gradle Plugin are you using? Try the latest com.android.tools.build:gradle:1.4.0-beta4
Also try not using the latest play-services I ran into an issue compiling against 8.1.0 but not 7.8.0

Could not resolve all dependencies for configuration ':app:_debugCompile'. in android studio

When I am run my application in android studio error. I am new in android developing.
My Logtag is here:
Information:Gradle tasks [:app:generateDebugSources, :app:generateDebugAndroidTestSources, :app:assembleDebug]
Error:A problem occurred configuring project ':app'.
> Could not resolve all dependencies for configuration ':app:_debugCompile'.
> Could not find com.android.support:recyclerview-v7:.
Searched in the following locations:
https://jcenter.bintray.com/com/android/support/recyclerview-v7//recyclerview-v7-.pom
https://jcenter.bintray.com/com/android/support/recyclerview-v7//recyclerview-v7-.jar
file:/C:/Users/ANDROID/AppData/Local/Android/sdk/extras/android/m2repository/com/android/support/recyclerview-v7//recyclerview-v7-.pom
file:/C:/Users/ANDROID/AppData/Local/Android/sdk/extras/android/m2repository/com/android/support/recyclerview-v7//recyclerview-v7-.jar
file:/C:/Users/ANDROID/AppData/Local/Android/sdk/extras/google/m2repository/com/android/support/recyclerview-v7//recyclerview-v7-.pom
file:/C:/Users/ANDROID/AppData/Local/Android/sdk/extras/google/m2repository/com/android/support/recyclerview-v7//recyclerview-v7-.jar
Required by:
ShoppingMazza:app:unspecified
Information:BUILD FAILED
Information:Total time: 4.964 secs
Information:1 error
Information:0 warnings
Information:See complete output in console
My build.gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.1"
defaultConfig {
applicationId "com.catalyst.android.shoppingmazza"
minSdkVersion 16
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
packagingOptions {
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/NOTICE'
exclude 'META-INF/LICENSE'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.0.1'
compile 'com.android.support:design:23.0.1'
compile 'com.squareup.picasso:picasso:2.3.2'
compile 'com.nineoldandroids:library:2.4.0'
compile 'com.daimajia.slider:library:1.1.5#aar'
compile 'com.android.support:recyclerview-v7:'
}
Error:
Error:A problem occurred configuring project ':app'. Could not
resolve all dependencies for configuration ':app:_debugCompile'.
Could not find com.android.support:recyclerview-v7:.
From error i can say you'll have to add the following gradle dependency :
compile 'com.android.support:recyclerview-v7:+'
EDIT:
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_51\bin\java.exe'' finished with
non-zero exit value 1
For this error i think you are compiling JAR library twice. You are using
compile fileTree(dir: 'libs', include: ['*.jar'])
in build.gradle file so it will compile all library that has jar extension on libs folder, so You can remove this lines:
compile 'com.squareup.picasso:picasso:2.3.2'
compile 'com.nineoldandroids:library:2.4.0'
compile 'com.daimajia.slider:library:1.1.5#aar'
If issue still exists then 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.
defaultConfig {
// Enabling multidex support.
multiDexEnabled true
}
Did you forget the version? In your gradle config you should have something like this:
compile 'com.android.support:recyclerview-v7:23.0.1'
In my case, I deleted caches folder inside .gradle folder and then I added compile. It worked for me!

cloud messaging and android

I am trying to implement google cloud messaging and push notifications on my android app
I am following official google tutorial , I am using android studio
https://developers.google.com/cloud-messaging/android/client
and I am getting this error
Error:Execution failed for task ':app:transformClassesWithDexForDebug'.
> com.android.build.transform.api.TransformException: com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Program Files\Java\jdk1.7.0_79\bin\java.exe'' finished with non-zero exit value 2
here is my build.gradle
apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'
android {
packagingOptions {
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/NOTICE'
exclude 'META-INF/LICENSE'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/ASL2.0'
exclude 'META-INF/notice.txt'
}
compileSdkVersion 22
buildToolsVersion "23.0.0 rc2"
defaultConfig {
applicationId "com.myapp.example"
minSdkVersion 15
targetSdkVersion 22
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
sourceSets.main {
jniLibs.srcDir 'libs'
jni.srcDirs = [] //disable automatic ndk-build call
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.google.android.gms:play-services:8.1.0'
compile 'com.android.support:appcompat-v7:22.2.0'
compile 'org.java-websocket:Java-WebSocket:1.3.0'
compile 'com.github.nkzawa:socket.io-client:0.3.0'
compile 'rongi.rotate-layout:rotate-layout:1.0.1'
compile 'com.vdurmont:emoji-java:2.0.1'
compile 'commons-lang:commons-lang:2.5'
compile 'com.github.javadev:underscore:1.6'
compile 'com.astuetz:pagerslidingtabstrip:1.0.1'
compile 'org.florescu.android.rangeseekbar:rangeseekbar-library:0.2.0'
compile 'com.beardedhen:androidbootstrap:1.1.1'
compile 'com.mcxiaoke.volley:library:1.0.18'
compile 'com.reginald.swiperefresh:library:1.1.1'
compile 'com.makeramen:roundedimageview:2.2.0'
compile 'com.google.code.gson:gson:2.3.1'
compile 'com.github.d-max:spots-dialog:0.4#aar'
compile 'cn.pedant.sweetalert:library:1.3'
compile 'com.jakewharton:butterknife:6.1.0'
compile 'com.squareup.picasso:picasso:2.5.2'
compile 'in.srain.cube:grid-view-with-header-footer:1.0.12'
compile 'com.vstechlab.easyfonts:easyfonts:1.0.0'
}
also here is my project build.gradle file
// 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.2.3'
classpath 'com.google.gms:google-services:1.4.0-beta3'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
After some-days and nightmares, Finally I can defeat the problem and believe it could be of help to others.
Because of my massive coded project, test and checking each advice takes about 5 minutes of my system to build. I examined almost all of SO community suggestions and I wanna conclude them here:
This is most likely a problem with the dependencies you have listed in your build.gradle file for you app.
Things I do not recommend:
Unless you have an absolute need to enable multiDex in your
build.gradle DO NOT DO IT, this is just stepping over the
underlying problem in your app and not getting to the root of it. You
are also unnecessarily increasing the size of your apk, and there
could be unexpected crashes when there is a conflicting method in your
dex file.
Things to look out for:
Check all your dependencies in your build.gradle file if you have any
duplication. Are you referencing a dependency that also includes a
dependency you have already included? For example, if your including
appcompat-v7 there is no need to include appcompat-v4 since v7
includes all features from v4.
My Issue: GOOGLE PLAY SERVICES >> causing my app to exceed method limit in my dex file.
If you do not need all the google play services library dependencies DO NOT INCLUDE this line in your build.gradle compile 'com.google.android.gms:play-services:8.3.0' and instead just use what you need!! also check if your can build correctly with lower versions of the dependency.
Google has a comprehensive list of the libraries for selectively compiling here
With all that said you probably only need to include this one line in gradle for your Google Analytics:
dependencies{
compile 'com.google.android.gms:play-services-plus:8.3.0'
}
Well Done!
take a look in your gradle console and check the exact error
i just had the same problem. i solved it with:
Clean the project (at first, gradle had a error because of multiple classes included)
only include the service you really needed from play.
https://developers.google.com/android/guides/setup#split
Add one more file in your dependency list
compile 'com.android.support:multidex:1.0.0'
and add following to your defaultconfig
defaultConfig {
//your stuff
multiDexEnabled true
}

Categories

Resources