Android 4.X : NoClassDefFoundError: io/reactivex/Observable [duplicate] - android

I have a project in which I have enabled multidex to avoid 65k limit and also productFlavors (dev API 21 and prod API 19) for customization.
Building my Project on API 21 i.e dev flavor is successful but on API 19 i.e. prod flavor, it is continuously giving me exception in app task shrink{component}MultiDexComponents
Complete Error log:
:app:shrinkProdDebugMultiDexComponents FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:shrinkProdDebugMultiDexComponents'.
> java.io.IOException: Can't read [{Project Path}/app/build/intermediates/multi-dex/prod/debug/allclasses.jar] (Can't process class [com/olivephone/office/a/b/e/p.class] (Unknown verification type [17] in stack map frame))
build.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion '23.0.0'
defaultConfig {
applicationId '{Project Name}'
minSdkVersion 15
targetSdkVersion 23
versionCode 1
versionName "1.0"
multiDexEnabled true
}
productFlavors {
dev {
// dev utilizes minSDKVersion = 21 to allow the Android gradle plugin
// to pre-dex each module and produce an APK that can be tested on
// Android Lollipop without time consuming dex merging processes.
minSdkVersion 21
}
prod {
// The actual minSdkVersion for the application.
minSdkVersion 19
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:appcompat-v7:23.0.1'
compile 'com.android.support:recyclerview-v7:23.0.1'
compile 'com.android.support:cardview-v7:23.0.1'
compile 'com.oguzdev:CircularFloatingActionMenu:1.0.2'
compile 'com.google.code.gson:gson:2.3.1'
compile 'com.google.android.gms:play-services:8.1.0'
compile 'com.android.support:multidex:1.0.1'
compile files('libs/linkedin-j-android.jar')
compile files('libs/itsrts-pptviewer.jar')
compile files('libs/signpost-core-1.2.1.1.jar')
compile 'org.twitter4j:twitter4j-core:4.0.2'
compile files('libs/universal-image-loader-1.9.2-SNAPSHOT-with-sources.jar')
compile files('libs/dropbox-android-sdk-1.6.3.jar')
compile files('libs/json_simple-1.1.jar')
compile 'com.joanzapata.pdfview:android-pdfview:1.0.1#jar'
compile 'com.facebook.android:facebook-android-sdk:4.1.0'
}
Any help please anyone ??

Multidex support for Android 5.0 and higher
Android 5.0 and higher uses a runtime called ART which natively
supports loading multiple dex files from application APK files. ART
performs pre-compilation at application install time which scans for
classes(..N).dex files and compiles them into a single .oat file for
execution by the Android device. For more information on the Android
5.0 runtime, see Introducing ART.
This is the reason why your app is working fine on API level 21.
Multidex support prior to Android 5.0
Versions of the platform prior to Android 5.0 use the Dalvik runtime
for executing app code. By default, Dalvik limits apps to a single
classes.dex bytecode file per APK. In order to get around this
limitation, you can use the multidex support library, which becomes
part of the primary DEX file of your app and then manages access to
the additional DEX files and the code they contain.
So, Firstly making sure you have imported correct dependency, which It seems you did it.
dependencies {
compile 'com.android.support:multidex:1.0.0'
}
In your manifest add the MultiDexApplication class from the multidex support library to the application element.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.android.multidex.myapplication">
<application
...
android:name="android.support.multidex.MultiDexApplication">
...
</application>
</manifest>
Alternative to that, If your app extends the Application class, you can override the attachBaseContext() method and call MultiDex.install(this) to enable multidex.
public void onCreate(Bundle arguments) {
MultiDex.install(getTargetContext());
super.onCreate(arguments);
...
}
I hope it will help you out.

In API 21, :app:shrinkProdDebugMultiDexComponents command is not called as API 21 already uses ART instead of Dalvik. Thus, natively support multidex.
For API below 21, then the command :app:shrinkProdDebugMultiDexComponents is executed.
Checking your build.gradle everything looks fine, which brings me to the following.
Have you setup multidex support properly?
Have you setup your manifest to support Multidex?
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.android.multidex.myapplication">
<application
...
android:name="android.support.multidex.MultiDexApplication">
...
</application>
</manifest>
OR if you actually extending the application class, you can do this:
public class MyApplication extends Application {
...
#Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
MultiDex.install(this);
}
...
}
or use this "pre-built" version
public class MyApplication extends MultiDexApplication{
...
}

I haven't peeped into the logic behind this, but in my case, it was due to version conflicts of compile 'com.android.support:appcompat-v7:25.3.1' and compile 'com.google.android.gms:play-services:10.2.4' in my build.gradle file.
Only enabling multidex didn't work for me. While searching for the other solutions, I found some people complaining about wierd issue of version conflict of play-services. So, I backtracked the code changes and finally changed play-services version from 10.2.4 to 10.2.1 and it worked for me.

Solved above crash issue. I have remove some unused dependency and also removed rx java dependency io.reactivex.rxjava . In replacement of Rx java i have added some dummy classes in my package which is already described here https://realm.io/docs/java/latest.
// File 1
package io.reactivex;
public class Flowable {
}
// File 2
package io.reactivex;
public class Observable {
}
// File 3
package io.reactivex;
public enum BackpressureStrategy {
LATEST;
}

Please change your dependencies as below :
Edited dependencies:
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:23.0.1'
compile 'com.android.support:recyclerview-v7:23.0.1'
compile 'com.android.support:cardview-v7:23.0.1'
compile 'com.oguzdev:CircularFloatingActionMenu:1.0.2'
compile 'com.google.code.gson:gson:2.3.1'
compile 'com.google.android.gms:play-services:8.1.0'
compile 'com.android.support:multidex:1.0.1'
compile 'com.googlecode.linkedin-j:linkedin-j-core:1.0.416'
compile 'oauth.signpost:signpost-core:1.2.1.2'
compile 'com.nostra13.universalimageloader:universal-image-loader:1.9.4'
compile 'com.googlecode.json-simple:json-simple:1.1'
compile 'org.twitter4j:twitter4j-core:4.0.2'
compile files('libs/itsrts-pptviewer.jar')
compile files('libs/dropbox-android-sdk-1.6.3.jar')
compile 'com.joanzapata.pdfview:android-pdfview:1.0.1#jar'
compile 'com.facebook.android:facebook-android-sdk:4.1.0'
Reason is that 'compile fileTree(dir: 'libs', include: ['*.jar'])' includes all jar file to gradle that is in libs folder..
Thanks.!!

The shrinkProdDebugMultiDexComponents task invokes Proguard, so this error comes from Proguard code.
My guess will be that you're not using the latest version of Olive Office SDK (which is probably obfuscated with buggy or misconfigured Proguard version). If this is the case, get the latest version from SDK developer.
For workaround, check this similar bug. Although it was closed with wontfix status, this blogpost describes how to patch the Proguard code.
Also check this and that answers by Eric Lafortune (Proguard's author) on similar issues.

Related

Migrate Eclipse ADT project to Android Studio: Error Multiple dex files define Landroid/support/v4

I have an old Android project made with Eclipse ADT and I'm trying to migrate it to Android Studio.
I follow several guides and howtos and maybe I have almost migrated it.
When I try to build it I get the following error:
Error:Error converting bytecode to dex:Cause: com.android.dex.DexException: Multiple dex files define Landroid/support/v4/accessibilityservice/AccessibilityServiceInfoCompat$AccessibilityServiceInfoVersionImpl;
I have read a lot of solutions but none seems to suit to my problem.
But maybe this answer is for my case...
Here is the Project status in Eclipse project explorer:
and here is the migrated Project in Android Studio project view:
Maybe the problem is the dependencies property of every gradle script:
app-app:
dependencies {
compile project(':androidsupportv7appcompat')
compile project(':library')
compile files('libs/android-support-v4.jar')
}
androidsupportv7appcompat:
dependencies {
compile files('libs/android-support-v4.jar')
compile files('libs/android-support-v7-appcompat.jar')
}
googleplayservice_lib:
dependencies {
compile files('libs/google-play-services.jar')
}
library: (a Google Maps library for markers clustering)
dependencies {
compile project(':googleplayservices_lib')
compile files('libs/android-support-v4.jar')
}
Do you know if something could be wrong in these dependencies configurations?
Otherwise, what could be the cause?
First of all, you should remove the Support Library module from your Android Studio project. Instead add a dependency to your apps gradle build file. If your library uses components from the support library, its build file should have the proper dependencies also.
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support:support-v4:25.3.1'
}
Be sure to remove the Support Library JAR files from your lib's folder.
Similarly you should add a dependency for Google Play Services.
Dependency management with Gradle is one of the many advantages of moving to Android Studio. If the library module is not written by you, you should also find the correct take dependency to add to your build file instead of the module you have now.
in one of my old projects, I had to put this in the gradle file under app section
multiDexEnabled true in the default config and then add the dex options below... maybe this will help.
defaultConfig {
applicationId "xxx"
minSdkVersion 14
targetSdkVersion 24
versionCode 4
versionName "2.2"
multiDexEnabled true
}
dexOptions {
javaMaxHeapSize "2g"
}

Build Failed when i try to run the app

I have the error like
"Error:Execution failed for task ':app:transformClassesWithJarMergingForDebug'.
com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: com/google/android/gms/internal/zzpm$zza$zza.class"
What should i do to remove this error
gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
applicationId "com.example.user.merchant"
minSdkVersion 15
targetSdkVersion 23
versionCode 1
versionName "1.0"
multiDexEnabled true
}
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.2.0'
compile 'com.android.support:design:23.2.0'
compile 'com.android.support:support-v4:23.2.0'
compile 'com.android.volley:volley:1.0.0'
compile 'com.google.android.gms:play-services-appindexing:8.4.0'
compile 'com.google.android.gms:play-services-gcm:8.4.0'
//compile files('libs/google-play-services.jar')
}
As #Vaiden says the issue was:
"It seems that you have at least one library already bundled with GMS"
Every time that you face a duplicate entry error run ./gradlew app:dependencies and make sure that there is no duplicated versions of a same module. For example: in my case I had:
compile 'com.google.android.gms:play-services-gcm:9.0.0'
When I tried to use firebase in my project I add it like:
compile 'com.google.firebase:firebase-core:9.+'
compile 'com.google.firebase:firebase-messaging:9.+'
That makes my app crash cause when I navigate to the: app > build > intermediates > exploded-aar > com.google.android.gms one of the folders (play-services-basement) pull a version 9.4.0 instead 9.0.0 so what I did was to unificate the versions by adding firebase like:
compile 'com.google.firebase:firebase-core:9.0.0'
compile 'com.google.firebase:firebase-messaging:9.0.0'
In theory you can solve this too by pushing the firebase to 9.4.0 instead.
The bottom line is to try to know which things are your dependencies introducing to the app and check "WHO" is introducing the same thing to the app, once you get there try to set a specific version of that duplicated dependency.
Based from this forum, try to change the gradle inside your C:\Program Files\Android\Android Studio\gradle\ to gradle-2.10. Also, it seems unlikely that a program that is designed to run on an Android device doesn't need all of the jars. Try removing some of them.
Check this related SO questions:
TransformException duplicate entry for common.annotations.Beta
Android dependency issue with gms play services
It seems that you have at least one library already bundled with GMS.
None of the dependencies stated in your gradle build file should have it, so the culprit might be a library jar file in your libs dir. So either you have something in your libs dir you shouldn't have put there, or a library that has GMS bundled inside of it.
Did you remember to delete libs/google-play-services.jar?

Migrating from Ant to Gradle in Android Studio

apply plugin: 'com.android.application'
android {
compileSdkVersion 22
buildToolsVersion "23.0.2"
defaultConfig {
applicationId "SOMEID"
minSdkVersion 15
targetSdkVersion 17
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
dependencies {
compile 'com.android.support:support-v4:22.2.1'
compile 'com.google.code.gson:gson:2.2.4'
compile 'com.google.guava:guava:18.0'
compile 'com.google.guava:guava:18.0'
compile 'com.google.guava:guava:15.0'
compile fileTree(dir: 'libs', include: ['*.jar'])
}
I am fairly new to android, so please be aware. The application that I have been working on was under Ant build, and now have to change to Gradle to work with other new dependencies. And now, I am getting the following errors after migration through Android Studio->Import->Projects:
Error:Execution failed for task ':app:transformResourcesWithMergeJavaResForDebug'.
com.android.build.api.transform.TransformException: com.android.builder.packaging.DuplicateFileException: Duplicate files copied in APK overview-frame.html
File1: /Users/taeyounglee/StudioProjects/adr-android/app/libs/ormlite-android-4.45-javadoc.jar
File2: /Users/taeyounglee/StudioProjects/adr-android/app/libs/ormlite-core-4.45-javadoc.jar
Below are the ones that are in libs folder, I even tried hard-coding the dependencies on the build.gradle as well, but didn't work out:
HockeySDK-3.5.0.jar
http-request-4.2.jar
jsr305-2.0.1.jar
libGoogleAnalyticsV2.jar
ormlite-android-4.45.jar
ormlite-android-4.45-javadoc.jar
ormlite-android-4.45-sources.jar
ormlite-core-4.45.jar
ormlite-core-4.45-javadoc.jar
ormlite-core-4.45-sources.jar
otto-1.3.4.jar
picasso-2.1.1.jar
Any suggestions on this? The app uses ormlite, and requires both .jar files, as when I tried removing either one of those, it just throws compile errors. I tried looking up online about APK overview-frame.html, but can't seem to find reasonable answer. Help much appreciated, and thanks in advance!
If you can avoid it, stop using the jars. Gradle makes pulling dependencies down from Maven or JCenter super easy. When adding libraries like this to your projects, start thinking in terms of adding the dependency via accessing JCenter or Maven instead of manually downloading and placing the jar in your project.
compile 'com.j256.ormlite:ormlite-android:4.45'
compile 'com.j256.ormlite:ormlite-core:4.45'
compile 'com.squareup.picasso:picasso:2.5.2'
compile 'com.squareup:otto:1.3.8'
compile 'net.hockeyapp.android:HockeySDK:3.7.2'
compile 'com.google.android.gms:play-services-analytics:8.4.0'
compile 'com.github.kevinsawicki:http-request:6.0'
Here's their associating website references:
OrmLite
Picasso
Otto
Hockey
Analytics
HTTP Request

What are the necessary gradle dependencies for an App Engine Backend with Google Cloud Messaging?

What are the necessary gradle dependencies for an App Engine Backend with Google Cloud Messaging?
Currently, when you add a module like that to your Android Studio project it adds this dependency:
'compile 'com.google.android.gms:play-services:8.4.0'
However, when you run the project you get this error:
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
'/Library/Java/JavaVirtualMachines/jdk1.7.0_79.jdk/Contents/Home/bin/java''
finished with non-zero exit value 2
Someone suggested using this:
defaultConfig {
multiDexEnabled true
}
But that actually didn't work for me.
So it appears that I have to specify only the required libraries for GAE + GCM. So far I have:
compile 'com.google.android.gms:play-services-auth:8.4.0'
compile 'com.google.android.gms:play-services-gcm:8.4.0'
compile 'com.google.android.gms:play-services-base:8.4.0'
full list here. But that didn't work. I got this error:
E/GMPM: GoogleService failed to initialize, status: 10, Missing an
expected resource: 'R.string.google_app_id' for initializing Google
services. Possible causes are missing google-services.json or
com.google.gms.google-services gradle plugin.
So I am at a loss.
Is there some other way around this issue? What is weird is my old GAE + GCM projects work fine importing the whole google play services. Importing those older versions of google play services in my new project does not work however. So I am not sure what is going on.
EDIT: Some more information:
I did some tests.
1) Started new Android Studio project, added new google cloud module 'App Engine Java Endpoints Module'. The auto-generated build.grade (Module: app) looks like this:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:design:23.1.1'
compile project(path: ':backend', configuration: 'android-endpoints')
}
Result? Compiles and runs perfectly - no problems!
2) Started new Android Studio project, added new google cloud module 'App Engine Backend with Google Cloud Messaging'. the auto-generated build.grade (Module: app) looks like this:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:design:23.1.1'
compile 'com.google.android.gms:play-services:8.4.0'
compile project(path: ':backend', configuration: 'android-endpoints')
}
Result? Same crappy error I have been getting!
So it looks like the line 'compile 'com.google.android.gms:play-services:8.4.0'' is the problem. I replaced it with
'compile 'com.google.android.gms:play-services-gcm:8.4.0''
since in theory that is all I need for google cloud messaging. When I run it I get this:
12-30 14:14:16.482 10573-10573/com.myapp.myapp
E/GMPM: GoogleService failed to initialize, status: 10, Missing an
expected resource: 'R.string.google_app_id' for initializing Google
services. Possible causes are missing google-services.json or
com.google.gms.google-services gradle plugin. 12-30 14:14:16.482
10573-10573/com.myapp.myapp E/GMPM: Scheduler not
set. Not logging error/warn. 12-30 14:14:16.502
10573-10623/com.myapp.myapp E/GMPM: Uploading is
not possible. App measurement disabled
So it looks like I am missing this google-services.json file or something. I don't get what happened with Android Studio because several months ago I made a GCM enabled app the same way and that one compiles no problem. The gradle.build file of that app looks like this:
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile project(path: ':gcm-backend', configuration: 'android-endpoints')
compile 'com.android.support:appcompat-v7:22.2.0'
compile 'com.ganyo:gcm-server:1.0.2'
compile 'com.google.android.gms:play-services:7.5.0'
compile 'com.android.support:support-v4:22.2.0'
}
So it looks like Android Studio stopped adding the 'compile 'com.ganyo:gcm-server:1.0.2'' dependency.
So I ran a project with
'compile 'com.ganyo:gcm-server:1.0.2'
'compile 'com.google.android.gms:play-services:8.4.0'
Result? Same Execution failed error.
Ok so let's try the old play-services library in my new project:
'compile 'com.ganyo:gcm-server:1.0.2'
'compile 'com.google.android.gms:play-services:7.5.0'
Result? Same Execution failed error.
I just don't get why this isn't working out of the box like it used to...
So, this should be considered an issue with Android Studio since simply adding a module 'App Engine Backend with Google Cloud Messaging' will break the build every time on even the simplest of apps, due to the full Google Play Services dependency 'com.google.android.gms:play-services:8.4.0' being large enough to exceed the 65K DEX method limit on its own. This problem is actually documented in 'Setting Up Google Play Services'.
The solution is, as you had discovered, to manually edit your build.gradle and add only the import for GCM 'com.google.android.gms:play-services-gcm:8.4.0'. The requirement for 'google-services.json' to be added manually is normal though, since you need to generate it for your project on developers.google.com. Adding 'multiDexEnabled true' isn't a good solution, as it increases your APK size needlessly, and you still end up with duplicate dependencies.
I've created an entry on the Android issue tracker to fix the dependencies for the App Engine GCM backend module in Android Studio. Feel free to star this issue for visibility and updates.
Preliminary tests show that this works so far.
I took at a look at the google GCM sample project here: https://github.com/googlesamples/google-services/tree/master/android/gcm
And edited my gradle files. Here is what they look like now:
APP:
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
applicationId "com.me.myapp"
minSdkVersion 13
targetSdkVersion 23
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.google.android.gms:play-services-gcm:8.4.0'
testCompile 'junit:junit:4.12'
compile project(path: ':backend', configuration: 'android-endpoints')
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:design:23.1.1'
}
apply plugin: 'com.google.gms.google-services'
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:1.5.0'
classpath 'com.google.gms:google-services:2.0.0-alpha3'
// 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
}
And also I followed this guide (see step 2) to generate a google-services.json file which I dropped into the app/ directory.
Now the app compiles and works (so far at least).
I'm really angry this doesn't work out of the box with the auto generated gradle files and that I have to hunt them down in some sample app. It didn't used to be this way just a few months ago. It worked as soon as you added the GCM module.
If anyone else has any tips/suggestions for future projects please let me know. =D
If you do get to the stage where you need to run with MultiDex enabled, there are three steps you need to do:
Enable it in your defaultConfig in Gradle as you already tried:
defaultConfig {
...
minSdkVersion 14
targetSdkVersion 21
...
// Enabling multidex support.
multiDexEnabled true
}
Include it in your dependencies:
dependencies {
compile 'com.android.support:multidex:1.0.0'
}
Add it to your manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.android.multidex.myapplication">
<application
...
android:name="android.support.multidex.MultiDexApplication">
...
</application>
</manifest>
https://developer.android.com/intl/es/tools/building/multidex.html#about
But always have a good look at the dependencies you already have as it's usually not needed.

Java finished with non-zero exit value 2 - Android Gradle

I'm getting this error executing my Android app (I cleaned it and then built it, but the error is still present)
Sync: OK
Make Project: OK
Clean: OK
Run: 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.7.0_25\bin\java.exe'' finished with non-zero exit value 2
My gradle file:
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
defaultConfig {
applicationId "com.rzr.rzevallosr.miappdepruebas"
minSdkVersion 19
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
productFlavors {
}
repositories {
mavenCentral()
flatDir {
dirs 'libs'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
// This library handles authentication and authorization
compile 'com.spotify.sdk:spotify-auth:1.0.0-beta9#aar'
// This library handles music playback
compile 'com.spotify.sdk:spotify-player:1.0.0-beta9#aar'
compile 'com.android.support:appcompat-v7:21.0.3'
compile 'com.android.support:recyclerview-v7:21.0.+'
compile 'com.squareup.retrofit:retrofit:1.9.0'
compile 'com.squareup.okhttp:okhttp-urlconnection:2.2.0'
compile 'com.squareup.okhttp:okhttp:2.2.0'
compile files('libs/spotify-web-api-android-master-0.1.0.jar')
compile files('libs/okio-1.3.0.jar')
}
EDIT: I didn't see "compile fileTree(dir: 'libs', include: ['*.jar'])" it was compiling twice my libraries, so i just comment:
//compile 'com.squareup.retrofit:retrofit:1.9.0'
//compile 'com.squareup.okhttp:okhttp-urlconnection:2.2.0'
//compile 'com.squareup.okhttp:okhttp:2.2.0'
//compile files('libs/spotify-web-api-android-master-0.1.0.jar')
//compile files('libs/okio-1.3.0.jar')
and it works fine.
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
}
You can read more about multidex support and developing apps with more than 65K methods here.
For me the problem was, i had put a 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'
Hi people i again encountered this problem and this time it was because of changing build tools version and it really required me to enable multidex..so i added these my app's build.gradle file..
defaultConfig {
applicationId "com.am.android"
minSdkVersion 13
targetSdkVersion 23
// Enabling multidex support.
multiDexEnabled true
}
dexOptions {
incremental true
javaMaxHeapSize "2048M"
jumboMode = true
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:multidex:1.0.1'
}
And create a class that extends Application class and include this method inside the class..
#Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
MultiDex.install(this);
}
also include in OnCreate method too
#Override
public void onCreate() {
MultiDex.install(this);
super.onCreate();
}
Just in case if someone still struggling with this and have no clue why is this happening and how to fix. In fact 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\jdkx.x.x_xx\bin\java.exe'' finished with non-zero exit value 2
can have many reasons to happen but certainly not something related to your JDK version so don't wast your time in wrong direction.
These are two main reasons for this to happen
You have same library or jar file included several places and some of them conflicting with each other.
You are about to or already exceeded 65k method limit
First case can be fixed as follows:
Find out which dependencies you have included multiple times. In order to do this run following command in android studio terminal
gradlew -q dependencies yourProjectName_usually_app:dependencies --configuration compile
this will return all the dependencies but jar files that you include from lib folder
try to get rid of duplication marked with asterisk (*), this is not always possible but in some cases you still can do it, after this try to exclude modules that are included many times, you can do it like this
compile ('com.facebook.android:facebook-android-sdk:4.0.1'){
exclude module: 'support-v4'
}
For the second case when you exceeding method limit suggestion is to try to minimize it by removing included libraries (note sounds like first solution) if no way to do it add multiDexEnabled true to your defaultConfig
defaultConfig {
...
...
multiDexEnabled true
}
this increases method limit but it is not the best thing to do because of possible performance issues
IMPORTANT adding only multiDexEnabled true to defaultConfig is not enough in fact on all devices running android <5 Lollipop it will result in unexpected behavior and NoClassDefFoundError. how to solve it is described here
I didn't know (by then) that "compile fileTree(dir: 'libs', include: ['*.jar'])" compile all that has jar extension on libs folder, so i just comment (or delete) this lines:
//compile 'com.squareup.retrofit:retrofit:1.9.0'
//compile 'com.squareup.okhttp:okhttp-urlconnection:2.2.0'
//compile 'com.squareup.okhttp:okhttp:2.2.0'
//compile files('libs/spotify-web-api-android-master-0.1.0.jar')
//compile files('libs/okio-1.3.0.jar')
and it works fine. Thanks anyway! My bad.
I had the same issue and I fixed removing the library that were unnecessary
compile fileTree(dir: 'libs', include: ['*.jar'])
I removed that library and I could run the project without any problem.
Mine got solved by enabling multiDex for debug builds.
defaultConfig {
multiDexEnabled true
}
I Reject Embedded JDK ( in 32bit ) because embedded JDK is 64bit
Right click your Project -> Open Module Setting -> SDK Location -> Uncheck Use embedded JDk then set your JDK Path, eg in Ubuntu /usr/lib/jvm/java-8-openjdk-i386
Possible problem: You have exceeded dex 65k methods limit, may be you added some library or several methods before problem occurred?
If You have already updated your SDK and You also using google-play-services then you need to take care of the dependency because there are some kind of conflics with :
Follow the below : compile 'com.google.android.gms:play-services:+' Replace by compile 'com.google.android.gms:play-services:6.5.87'
Note: Here '6.5.87' is the google-play-service version. I hope it will help..
I think it's conflicts of .jar file in your project.
I have removed android-support-v4.jar from libs folder and its working !!!
if your project gives error, check in your build.gradle file
dependencies {
}
In my case, the problem was that the new library (gradle dependency) that I had added was relying on some other dependencies and two of those underlying dependencies were conflicting/clashing with some dependencies of other libraries/dependencies in my build script. Specifically, I added Apache Commons Validator (for email validation), and two of its dependencies (Apache Commons Logging and Apache Commons Collections) were conflicting with those used by Robolectric (because different versions of same libraries were present in my build path). So I excluded those conflicting versions of dependencies (modules) when adding the new dependency (the Validator):
compile ('commons-validator:commons-validator:1.4.1') {
exclude module: 'commons-logging'
exclude module: 'commons-collections'
}
You can see the dependencies of your gradle module(s) (you might have only one module in your project) using the following gradle command (I use the gradle wrapper that gets created for you if you have created your project in Android Studio/Intellij Idea). Run this command in your project's root directory:
./gradlew :YOUR-MODULE-NAME:dependencies
After adding those exclude directives and retrying to run, I got a duplicate file error for NOTICE.txtthat is used by some apache commons libraries like Logging and Collections. I had to exclude that text file when packaging. In my build.gradle, I added:
packagingOptions {
exclude 'META-INF/NOTICE'
exclude 'META-INF/notice.txt'
exclude 'META-INF/NOTICE.txt'
}
It turned out that the new library (the Validator) can work with slightly older versions of its dependencies/modules (which are already imported into my build path by another library (Robolectric)). This was the case with this specific library, but other libraries might be using the latest API of the underlying dependencies (in which case you have to try to see if the other libraries that rely on the conflicting module/dependency are able to work with the newer version (by excluding the older version of the module/dependecy under those libraries's entries)).
In my case, I got this error when there are 2 or more libraries conflict (same library but different versions). Check your app build.gradle in dependencies block.
There are two alternatives that'll work for sure:
Clean your project and then build.
If the above method didn't worked, try the next.
Add the following to build.gradle file at app level
defaultConfig {
multiDexEnabled true
}
Updating my Java SDK to the latest version 1.7.0_79 and updating the SDK Location under Project Structure solved the problem for me.
My problem was that apart from having
com.android.build.api.transform.TransformException:
com.android.ide.common.process.ProcessException:
org.gradle.process.internal.ExecException: Process 'command
'/Library/Java/JavaVirtualMachines/jdk1.X.X_XX.jdk/Contents/Home/bin/java''
finished with non-zero exit value 2
I had this trace as well:
Uncaught translation error: java.lang.IllegalArgumentException:
already added: Lcom/mypackage/ClassX;
The problem was that I was adding the same class in two differents libraries. Removing the class/jar file from one of the libraries, the project run properly
For me i was adding the whole playstore dependencies
compile 'com.google.android.gms:play-services:8.4.0'
But i needed google map only , so i made it more specific and the error was resolved.
compile 'com.google.android.gms:play-services-maps:8.4.0'
in my case problem was build tools version which was 23.0.0 rc3 and i changed to 22.0.1 and my problem fixed.
You may be using a low quality cable/defected cable to connect your device to the PC, I replaced the cable and it worked for me.
This error is because of using more number of libraries.in my case 'compile 'com.google.android.gms:play-services-9.4.0' caused this error.To avoid this error use necessary libraries.for example if you want to use Maps in your app.Then use
compile 'com.google.android.gms:play-services-maps:9.4.0'.while adding google play services dependency specify the needed libraries only.by default it includes all the libraries.
In Your gradle.build file, Use this
"compile fileTree(dir: 'libs', include: ['*.jar'])"
And it works fine.
If you want to see what exactly is causing the error, try building your project via gradle terminal, like this ./gradlew assembleDebug --stacktrace --debug . I've seen the following error in my case com.android.dex.DexIndexOverflowException: method ID not in [0, 0xffff]: 65536
This happened when I was trying to entegrate Google Maps to my project. To fix it, I simply checked libraries I was including
compile 'com.google.android.gms:play-services:9.8.0'
I simply changed it to
compile 'com.google.android.gms:play-services-maps:9.8.0'
and problem was gone
I had the same error after converting my project to Kotlin. My problem was that my jre location was changed to an invalid path during the process (I wonder why this could happen... made me waste time). Fixed it by doing this:
File > Project Structure > SDK Location
Unchecked the Use embedded JDK option, which was pointing to an old JDK installation, and selected the correct one:
/home/my_user/jdk1.8.0_101
After changing this, the error disappeared
WORKED FOR ME :)
i upgraded the java to the latest version 8 previously it was 7 and then go to OPEN MODULE SETTING right clicking on project and changed the jdk path to /usr/lib/jvm/java-8-oracle the new java 8 installed. And restart the studio
check in /usr/lib/jvm for java 8 folder name
I am using ubuntu

Categories

Resources