Android studio gradle build failed [duplicate] - android

I updated Android Studio to the latest version, and let it "fix the project" and the like - but now my project does not compile, gives me
FAILED
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:
D:\VGA\AndroidStudio\sdk\build-tools\21.1.1\dx.bat --dex --no-optimize --output D:\VGA\Projects\Sales-App\Android-Project\svn\android\app\build\intermediates\dex\debug --input-list=D:\VGA\Projects\Sales-App\Android-Project\svn\android\app\build\intermediates\tmp\dex\debug\inputList.txt
Error Code:
2
Output:
UNEXPECTED TOP-LEVEL EXCEPTION:
com.android.dex.DexIndexOverflowException: method ID not in [0, 0xffff]: 65536
at com.android.dx.merge.DexMerger$6.updateIndex(DexMerger.java:502)
at com.android.dx.merge.DexMerger$IdMerger.mergeSorted(DexMerger.java:277)
at com.android.dx.merge.DexMerger.mergeMethodIds(DexMerger.java:491)
at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:168)
at com.android.dx.merge.DexMerger.merge(DexMerger.java:189)
at com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:454)
at com.android.dx.command.dexer.Main.runMonoDex(Main.java:302)
at com.android.dx.command.dexer.Main.run(Main.java:245)
at com.android.dx.command.dexer.Main.main(Main.java:214)
at com.android.dx.command.Main.main(Main.java:106)
However, this isn't resolved by just multidexing, because when I added this:
defaultConfig {
...
multiDexEnabled = true
}
This happens
D:\VGA\AndroidStudio\sdk\build-tools\21.1.1\dx.bat --dex --no-optimize --multi-dex --main-dex-list D:\VGA\Projects\Sales-App\Android-Project\svn\android\app\build\intermediates\multi-dex\debug\maindexlist.txt --output D:\VGA\Projects\Sales-App\Android-Project\svn\android\app\build\intermediates\dex\debug --input-list=D:\VGA\Projects\Sales-App\Android-Project\svn\android\app\build\intermediates\tmp\dex\debug\inputList.txt
Error Code:
3
Output:
UNEXPECTED TOP-LEVEL ERROR:
java.lang.OutOfMemoryError: GC overhead limit exceeded
at com.android.dx.cf.code.ConcreteMethod.makeSourcePosistion(ConcreteMethod.java:254)
at com.android.dx.cf.code.RopperMachine.run(RopperMachine.java:306)
at com.android.dx.cf.code.Simulator$SimVisitor.visitLocal(Simulator.java:612)
at com.android.dx.cf.code.BytecodeArray.parseInstruction(BytecodeArray.java:367)
at com.android.dx.cf.code.Simulator.simulate(Simulator.java:94)
at com.android.dx.cf.code.Ropper.processBlock(Ropper.java:787)
at com.android.dx.cf.code.Ropper.doit(Ropper.java:742)
at com.android.dx.cf.code.Ropper.convert(Ropper.java:349)
at com.android.dx.dex.cf.CfTranslator.processMethods(CfTranslator.java:280)
at com.android.dx.dex.cf.CfTranslator.translate0(CfTranslator.java:137)
at com.android.dx.dex.cf.CfTranslator.translate(CfTranslator.java:93)
at com.android.dx.command.dexer.Main.processClass(Main.java:729)
at com.android.dx.command.dexer.Main.processFileBytes(Main.java:673)
at com.android.dx.command.dexer.Main.access$300(Main.java:82)
at com.android.dx.command.dexer.Main$1.processFileBytes(Main.java:602)
at com.android.dx.cf.direct.ClassPathOpener.processArchive(ClassPathOpener.java:284)
at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:166)
at com.android.dx.cf.direct.ClassPathOpener.process(ClassPathOpener.java:144)
at com.android.dx.command.dexer.Main.processOne(Main.java:632)
at com.android.dx.command.dexer.Main.processAllFiles(Main.java:505)
at com.android.dx.command.dexer.Main.runMultiDex(Main.java:332)
at com.android.dx.command.dexer.Main.run(Main.java:243)
at com.android.dx.command.dexer.Main.main(Main.java:214)
at com.android.dx.command.Main.main(Main.java:106)
I tried changing the build tools to latest
android {
compileSdkVersion 21
buildToolsVersion "21.1.1"
Because by default it changed to 20.0.0 which seemed to use the SDK for 4.4W, but this didn't fix my problem.
Does anyone know what could be wrong here?
EDIT:
Changing the build tools or the compile SDK did not fix the problem.
Turning the app into a multi-dex project and also adding the following
android {
compileSdkVersion 21
buildToolsVersion "21.1.1"
defaultConfig {
...
multiDexEnabled true
}
...
dexOptions {
incremental true
javaMaxHeapSize "4g"
}
}
Fixed the build process, however this still seems to be just a "treatment" but not a fix to the problem.
I am not sure if this is related, but this is my dependency list:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:multidex:1.0.0'
compile 'com.android.support:appcompat-v7:21.0.2'
compile 'com.squareup:otto:1.3.5'
compile 'com.squareup.picasso:picasso:2.4.0'
compile 'com.squareup.retrofit:retrofit:1.7.1'
compile 'com.jakewharton:butterknife:6.0.0'
compile 'com.madgag.spongycastle:core:1.51.0.0'
compile 'com.madgag.spongycastle:prov:1.51.0.0'
compile 'com.madgag.spongycastle:pkix:1.51.0.0'
compile 'com.google.code.gson:gson:2.3'
compile 'commons-io:commons-io:2.4'
compile 'org.apache.httpcomponents:httpclient-android:4.3.5'
compile 'com.squareup.dagger:dagger:1.2.2'
compile 'com.squareup.dagger:dagger-compiler:1.2.2'
compile('com.googlecode.json-simple:json-simple:1.1.1') {
exclude module: 'junit'
}
compile 'com.google.android.gms:play-services:6.5.87'
}
The only new dependency since then has been the last line, which I added as per https://developer.android.com/google/gcm/client.html so I don't think that is the source of the problem.
EDIT2:
Yes, it was the source of the problem. As I needed Google Cloud Messaging, I replaced that dependency with the base as per http://developer.android.com/google/play-services/setup.html#split :
compile 'com.google.android.gms:play-services-base:6.5.87'
And it fixed the problem. Thank you for the help.
EDIT3:
As of play services 7.0.0, the GCM is in
compile 'com.google.android.gms:play-services-gcm:7.0.0'
EDIT4:
Play Services updated to 7.3.0.
Please keep check of the latest version here: http://developer.android.com/google/play-services/setup.html#split

The error means you have reached maximum method count in your app. That does include any libraries that you use for your project.
There are two ways to tackle the issue:
Get rid of any third-party libraries that you don't really need. If you use google play services that might contribute a lot to the method count. Fortunately as of the latest play-services release it is possible to include only parts of the framework.
Use a multi dex setup for your application.

I am phasing these problem & in my case used these link to overcome that error successfully..!!!
The DEX 64k limit is not a problem anymore, almost
To sum it up, adding multidex support:
In case of
UNEXPECTED TOP-LEVEL EXCEPTION:
com.android.dex.DexIndexOverflowException: method ID not in [0, 0xffff]: 65536
at com.android.dx.merge.DexMerger$6.updateIndex(DexMerger.java:502)
at com.android.dx.merge.DexMerger$IdMerger.mergeSorted(DexMerger.java:277)
at com.android.dx.merge.DexMerger.mergeMethodIds(DexMerger.java:491)
at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:168)
at com.android.dx.merge.DexMerger.merge(DexMerger.java:189)
at com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:454)
at com.android.dx.command.dexer.Main.runMonoDex(Main.java:302)
at com.android.dx.command.dexer.Main.run(Main.java:245)
at com.android.dx.command.dexer.Main.main(Main.java:214)
at com.android.dx.command.Main.main(Main.java:106)
Google decided to release an official solution for this in the form of the MultiDex Support Library.
dependencies {
...
compile 'com.android.support:multidex:'
...
}
Then enable multi-dexing by setting the multiDexEnabled flag in the buildType or productFlavor section of your gradle configuration.
defaultConfig {
...
multiDexEnabled true
...
}
Then depending on your project, you have 3 options:
If you haven’t created your own Application class, simply declare android.support.multidex.MultiDexApplication as your application class in AndroidManifest.xml
....
android:name="android.support.multidex.MultiDexApplication"
...
If you already have your own Application class, make it extend android.support.multidex.MultiDexApplication instead of android.app.Application
If your Application class is extending some other class and you don’t want to or can’t change it, override attachBaseContext() as shown below:
public class MyApplication extends FooApplication {
#Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
MultiDex.install(this);
}
}
Your compilation process might run out of memory.
To fix it, set the following dex options in the ‘android’ closure –
dexOptions {
incremental true
javaMaxHeapSize "4g"
}
More to know about multidex is here: http://developer.android.com/tools/building/multidex.html
Another link which becomes helping to solve a these error : Referance Link

Related

Issue after import from Eclipse to android studio execution

I have imported project from Eclipse to Android studio. It builds successfully, but when I try to execute the project in android studio I am getting following exception .
UNEXPECTED TOP-LEVEL EXCEPTION: com.android.dex.DexException: Multiple
dex files define Landroid/support/annotation/AnimRes; at
com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:596)
at com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:554)
at com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:535)
at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:171) at
com.android.dx.merge.DexMerger.merge(DexMerger.java:189) at
com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:454)
at com.android.dx.command.dexer.Main.runMonoDex(Main.java:303) at
com.android.dx.command.dexer.Main.run(Main.java:246) at
com.android.dx.command.dexer.Main.main(Main.java:215) at
com.android.dx.command.Main.main(Main.java:106)
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_45\bin\java.exe'' finished with
non-zero exit value 2
And here is my Build.gradle file.
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion "22.0.1"
defaultConfig {
applicationId "com.example.heal4me_app"
minSdkVersion 11
targetSdkVersion 19
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
dependencies {
compile 'com.android.support:support-v4:22.2.0'
compile 'com.android.support:appcompat-v7:22.2.0'
compile 'com.google.android.gms:play-services:7.5.0'
compile files('libs/android-support-v13.jar')
}
I have tried all the posted solution for the above problem, which is available on stackoverflow. But I couldn't find any right answer for this problem.
I had the same issue after adding the library com.amazonaws:aws-java-sdk:1.8.0 to my gradle dependencies. After removing the dependencie, everything seems to be fine. I don't know why, if I find a solution I report it.
After the many efforts I have to finally do the hard work to migrate from eclipse to android studio.
I have copied all the java classes and xml file one by one to the android studio. And finally I am done. I think this is not the good solution but I have to do this compulsorily to resolve above error.
I have read so many blogs and stackoverflow questions regarding this issue. but unfortunately that didn't help me, that's why I have to come up with this hard work.

DexException: Multiple dex files

Okay so currently i am making an Android app that utilizes the Google Sheets API version 3.0 and Drive API Client Library for Java, i need the app to read a spreadhsheet from a users drive account and edit it. Following the documentation i have included the following jars in my /lib folder(Android Studio 1.1).dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:appcompat-v7:21.0.3'
compile 'com.google.android.gms:play-services:6.5.87'
compile files('libs/google-api-client-1.19.1.jar')
compile files('libs/google-api-client-android-1.19.1.jar')
compile files('libs/google-api-services-drive-v2-rev158-1.19.1.jar')
compile files('libs/google-http-client-1.19.0.jar')
compile files('libs/google-http-client-android-1.19.0.jar')
compile files('libs/google-http-client-gson-1.19.0.jar')
compile files('libs/google-oauth-client-1.19.0.jar')
compile files('libs/gson-2.1.jar')
compile files('libs/jackson-core-2.1.3.jar')
compile files('libs/jackson-core-asl-1.9.11.jar')
compile files('libs/jsr305-1.3.9.jar')
compile files('libs/protobuf-java-2.4.1.jar')
compile files('libs/mail.jar')
compile files('libs/jsr305.jar')
compile files('libs/guava-11.0.2.jar')
compile files('libs/gdata-spreadsheet-meta-3.0.jar')
compile files('libs/gdata-spreadsheet-3.0.jar')
compile files('libs/gdata-docs-meta-3.0.jar')
compile files('libs/gdata-docs-3.0.jar')
compile files('libs/gdata-core-1.0.jar')
compile files('libs/gdata-client-meta-1.0.jar')
compile files('libs/gdata-client-1.0.jar')
compile files('libs/additionnal.jar')
compile files('libs/activation.jar')
}When im typing my code everything works just fine, everything is imported appropiately but when i run my app i get this result.
`What went wrong:
Execution failed for task ':app:dexDebug'.
> com.android.ide.common.internal.LoggedErrorException: Failed to run command:
C:\Users\Ricardo\AppData\Local\Android\sdk\build-tools\21.1.2\dx.bat --dex --output C:\Users\Ricardo\Google Drive\Development\Android\Updated\Private\Google_Fiasco\MyApplication\app\build\intermediates\dex\debug --input-list=C:\Users\Ricardo\Google Drive\Development\Android\Updated\Private\Google_Fiasco\MyApplication\app\build\intermediates\tmp\dex\debug\inputList.txt
Error Code:
2
Output:
UNEXPECTED TOP-LEVEL EXCEPTION:
com.android.dex.DexException: Multiple dex files define Ljavax/annotation/CheckForNull;
at com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:596)
at com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:554)
at com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:535)
at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:171)
at com.android.dx.merge.DexMerger.merge(DexMerger.java:189)
at com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:454)
at com.android.dx.command.dexer.Main.runMonoDex(Main.java:303)
at com.android.dx.command.dexer.Main.run(Main.java:246)
at com.android.dx.command.dexer.Main.main(Main.java:215)
at com.android.dx.command.Main.main(Main.java:106)
e`<br>
Now a couple things to note, when i make two separate projects ,one implementing the Spreadsheet API and the other the Drive API no errors occur. The error only occurs when i implement both API's in the same project i.e combining the jars from both libraries. After tinkering with the jars i found that the error only happens when both jsr305.jar & jsr305-1.3.9.jar are included. Looking at these two jars i see that both have CheckForNull.java files, the file referenced in the error message Multiple dex files define Ljavax/annotation/CheckForNull.
So my question: How do i resolve this error? I think i have to exclude it in my dependencies? Precise instructions would be appreciated, and perhaps an explanation on what the solution does. Also one last thing What difference does it make between simply putting jar files in my /lib folder and adding it to my dependencies in build.gradle? It doesn't seem to affect anything.
The result of deleting either of the jsr.jat files is the following: UNEXPECTED TOP-LEVEL EXCEPTION:
com.android.dex.DexIndexOverflowException: method ID not in [0, 0xffff]: 65536
at com.android.dx.merge.DexMerger$6.updateIndex(DexMerger.java:502)
at com.android.dx.merge.DexMerger$IdMerger.mergeSorted(DexMerger.java:277)
at com.android.dx.merge.DexMerger.mergeMethodIds(DexMerger.java:491)
at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:168)
at com.android.dx.merge.DexMerger.merge(DexMerger.java:189)
at com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:454)
at com.android.dx.command.dexer.Main.runMonoDex(Main.java:303)
at com.android.dx.command.dexer.Main.run(Main.java:246)
at com.android.dx.command.dexer.Main.main(Main.java:215)
at com.android.dx.command.Main.main(Main.java:106)
Just clean the project and build again... I knew my code had nothing to do with the bug as soon as I saw the word 'dex' in the error text
This error is caused by having too many method referenced in your project. You can read more here.
Generally it means that you need to remove unused libraries or use proguard even on debug build to reduce the number of method referenced. You may also go with the multi-dex approached mentioned in the article but it makes your project more complicated.
I had react-native project with app's build.gradle:
def enableProguardInReleaseBuilds = false
...
buildTypes {
release {
minifyEnabled enableProguardInReleaseBuilds
proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
}
}
Setting enableProguardInReleaseBuilds to true worked for me:
def enableProguardInReleaseBuilds = true

Android Studio: Error:Execution failed for task ':app:dexDebug'

I'm using Android Studio for the first time and I got the following error after importing the project (previously it was an eclipse project where I had issues too.)
Here is the information given:
Error:Execution failed for task ':app:dexDebug'.
> com.android.ide.common.internal.LoggedErrorException: Failed to run command:
/home/crash-id/Development/SDK/adt-bundle-linux-x86_64-20140702/sdk/build-tools/21.1.2/dx --dex --no-optimize --output /home/crash-id/AndroidstudioProjects/LocalSin/app/build/intermediates/dex/debug --input-list=/home/crash-id/AndroidstudioProjects/LocalSin/app/build/intermediates/tmp/dex/debug/inputList.txt
Error Code:
2
Output:
UNEXPECTED TOP-LEVEL EXCEPTION:
com.android.dex.DexException: Multiple dex files define Lcom/google/ads/AdRequest$ErrorCode;
at com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:596)
at com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:554)
at com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:535)
at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:171)
at com.android.dx.merge.DexMerger.merge(DexMerger.java:189)
at com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:454)
at com.android.dx.command.dexer.Main.runMonoDex(Main.java:303)
at com.android.dx.command.dexer.Main.run(Main.java:246)
at com.android.dx.command.dexer.Main.main(Main.java:215)
at com.android.dx.command.Main.main(Main.java:106)
:app:dexDebug
UNEXPECTED TOP-LEVEL EXCEPTION:
com.android.dex.DexException: Multiple dex files define Lcom/google/ads/AdRequest$ErrorCode;
at com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:596)
at com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:554)
at com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:535)
at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:171)
at com.android.dx.merge.DexMerger.merge(DexMerger.java:189)
at com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:454)
at com.android.dx.command.dexer.Main.runMonoDex(Main.java:303)
at com.android.dx.command.dexer.Main.run(Main.java:246)
at com.android.dx.command.dexer.Main.main(Main.java:215)
at com.android.dx.command.Main.main(Main.java:106)
FAILED
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:
/home/crash-id/Development/SDK/adt-bundle-linux-x86_64-20140702/sdk/build-tools/21.1.2/dx --dex --no-optimize --output /home/crash-id/AndroidstudioProjects/LocalSin/app/build/intermediates/dex/debug --input-list=/home/crash-id/AndroidstudioProjects/LocalSin/app/build/intermediates/tmp/dex/debug/inputList.txt
Error Code:
2
Output:
UNEXPECTED TOP-LEVEL EXCEPTION:
com.android.dex.DexException: Multiple dex files define Lcom/google/ads/AdRequest$ErrorCode;
at com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:596)
at com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:554)
at com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:535)
at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:171)
at com.android.dx.merge.DexMerger.merge(DexMerger.java:189)
at com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:454)
at com.android.dx.command.dexer.Main.runMonoDex(Main.java:303)
at com.android.dx.command.dexer.Main.run(Main.java:246)
at com.android.dx.command.dexer.Main.main(Main.java:215)
at com.android.dx.command.Main.main(Main.java:106)
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
The app build.gradle is this:
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
defaultConfig {
applicationId "com.myapp.test"
minSdkVersion 11
targetSdkVersion 14
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
dependencies {
compile 'com.android.support:support-v4:18.0.0'
compile 'com.android.support:appcompat-v7:21.0.3'
compile 'com.google.android.gms:play-services:+'
compile files('libs/google-play-services.jar')
compile files('libs/httpcore-4.3.2.jar')
compile files('libs/httpmime-4.3.4.jar')
}
And the project built.gradle is this:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.0.0'
}
}
allprojects {
repositories {
jcenter()
}
}
Do you have any idea what the problem could be and how can it be solved? A good explanation for the problem would be useful too as I am new to Android Studio. Thanks in advance :)
compile 'com.google.android.gms:play-services:+'
compile files('libs/google-play-services.jar')
I think you should remove 1 of those lines.
cd android/ && ./gradlew clean && cd .. && react-native run-android
I had the Android Studio Error:Execution failed for task ':app:dexDebug' that i solve it by setting multiDexEnabled to true
defaultConfig {
// Enabling multidex support.
multiDexEnabled true
}
Too many library were used in my project so i exceed the 65K methods dex limit imposed by Android for more information see : http://developer.android.com/tools/building/multidex.html
This happens because you are duplicating the library dependency inside of app build.gradle in android studio.
Android Studio automatically adds the dependencies for all the files in the libs folder by using
compile fileTree(dir: 'libs', include: ['*.jar'])
or in your specific case the dependency is added using
compile files('libs/google-play-services.jar')
^ Now when you try to add the dependency again by using
compile 'com.google.android.gms:play-services:+'
you get the error.
SOLUTION
Remove all duplicate dependencies added inside the "app build.gradle" and you should be good to go.In your case remove
compile 'com.google.android.gms:play-services:+'
avoid to include whole gms library:
compile 'com.google.android.gms:play-services:+'
Instead, just use required components in this way:
compile 'com.google.android.gms:play-services-ads:8.3.0'
compile 'com.google.android.gms:play-services-analytics:8.3.0'
compile 'com.google.android.gms:play-services-gcm:8.3.0'
Ensure that the Package names are not duplicated across the projects being compiled
In #Drivers' answer, it is pointed out that in a given project, there should not be multiple dependencies that have the same namespace. In the case above, the Google Play Services library had been included twice, and thus caused a package name conflict.
The same can also happen across multiple modules (apps, libraries etc.) in the same project. So, ensure that for each AndroidManifest.xml file, the package name is unique across all modules:-
AndroidManifest.xml:
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="this.must.be.unique.across.modules">
I had the below code on gradle file and same error.
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:23.0.0'
compile 'com.google.android.gms:play-services-ads:8.3.0'
}
dependencies {
compile 'com.android.support:design:23.+'
}
dependencies {
compile 'com.android.support:design:23.+'
}
dependencies {
compile 'com.android.support:design:23.+'
}
Removed those last 3 dependencies and now its working!
delete all files in c:\users\<username>\.gradle\caches\transforms-2\files-2.1\
Enjoy the command flutter run

After update of AS to 1.0, getting "method ID not in [0, 0xffff]: 65536" error in project

I updated Android Studio to the latest version, and let it "fix the project" and the like - but now my project does not compile, gives me
FAILED
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:
D:\VGA\AndroidStudio\sdk\build-tools\21.1.1\dx.bat --dex --no-optimize --output D:\VGA\Projects\Sales-App\Android-Project\svn\android\app\build\intermediates\dex\debug --input-list=D:\VGA\Projects\Sales-App\Android-Project\svn\android\app\build\intermediates\tmp\dex\debug\inputList.txt
Error Code:
2
Output:
UNEXPECTED TOP-LEVEL EXCEPTION:
com.android.dex.DexIndexOverflowException: method ID not in [0, 0xffff]: 65536
at com.android.dx.merge.DexMerger$6.updateIndex(DexMerger.java:502)
at com.android.dx.merge.DexMerger$IdMerger.mergeSorted(DexMerger.java:277)
at com.android.dx.merge.DexMerger.mergeMethodIds(DexMerger.java:491)
at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:168)
at com.android.dx.merge.DexMerger.merge(DexMerger.java:189)
at com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:454)
at com.android.dx.command.dexer.Main.runMonoDex(Main.java:302)
at com.android.dx.command.dexer.Main.run(Main.java:245)
at com.android.dx.command.dexer.Main.main(Main.java:214)
at com.android.dx.command.Main.main(Main.java:106)
However, this isn't resolved by just multidexing, because when I added this:
defaultConfig {
...
multiDexEnabled = true
}
This happens
D:\VGA\AndroidStudio\sdk\build-tools\21.1.1\dx.bat --dex --no-optimize --multi-dex --main-dex-list D:\VGA\Projects\Sales-App\Android-Project\svn\android\app\build\intermediates\multi-dex\debug\maindexlist.txt --output D:\VGA\Projects\Sales-App\Android-Project\svn\android\app\build\intermediates\dex\debug --input-list=D:\VGA\Projects\Sales-App\Android-Project\svn\android\app\build\intermediates\tmp\dex\debug\inputList.txt
Error Code:
3
Output:
UNEXPECTED TOP-LEVEL ERROR:
java.lang.OutOfMemoryError: GC overhead limit exceeded
at com.android.dx.cf.code.ConcreteMethod.makeSourcePosistion(ConcreteMethod.java:254)
at com.android.dx.cf.code.RopperMachine.run(RopperMachine.java:306)
at com.android.dx.cf.code.Simulator$SimVisitor.visitLocal(Simulator.java:612)
at com.android.dx.cf.code.BytecodeArray.parseInstruction(BytecodeArray.java:367)
at com.android.dx.cf.code.Simulator.simulate(Simulator.java:94)
at com.android.dx.cf.code.Ropper.processBlock(Ropper.java:787)
at com.android.dx.cf.code.Ropper.doit(Ropper.java:742)
at com.android.dx.cf.code.Ropper.convert(Ropper.java:349)
at com.android.dx.dex.cf.CfTranslator.processMethods(CfTranslator.java:280)
at com.android.dx.dex.cf.CfTranslator.translate0(CfTranslator.java:137)
at com.android.dx.dex.cf.CfTranslator.translate(CfTranslator.java:93)
at com.android.dx.command.dexer.Main.processClass(Main.java:729)
at com.android.dx.command.dexer.Main.processFileBytes(Main.java:673)
at com.android.dx.command.dexer.Main.access$300(Main.java:82)
at com.android.dx.command.dexer.Main$1.processFileBytes(Main.java:602)
at com.android.dx.cf.direct.ClassPathOpener.processArchive(ClassPathOpener.java:284)
at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:166)
at com.android.dx.cf.direct.ClassPathOpener.process(ClassPathOpener.java:144)
at com.android.dx.command.dexer.Main.processOne(Main.java:632)
at com.android.dx.command.dexer.Main.processAllFiles(Main.java:505)
at com.android.dx.command.dexer.Main.runMultiDex(Main.java:332)
at com.android.dx.command.dexer.Main.run(Main.java:243)
at com.android.dx.command.dexer.Main.main(Main.java:214)
at com.android.dx.command.Main.main(Main.java:106)
I tried changing the build tools to latest
android {
compileSdkVersion 21
buildToolsVersion "21.1.1"
Because by default it changed to 20.0.0 which seemed to use the SDK for 4.4W, but this didn't fix my problem.
Does anyone know what could be wrong here?
EDIT:
Changing the build tools or the compile SDK did not fix the problem.
Turning the app into a multi-dex project and also adding the following
android {
compileSdkVersion 21
buildToolsVersion "21.1.1"
defaultConfig {
...
multiDexEnabled true
}
...
dexOptions {
incremental true
javaMaxHeapSize "4g"
}
}
Fixed the build process, however this still seems to be just a "treatment" but not a fix to the problem.
I am not sure if this is related, but this is my dependency list:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:multidex:1.0.0'
compile 'com.android.support:appcompat-v7:21.0.2'
compile 'com.squareup:otto:1.3.5'
compile 'com.squareup.picasso:picasso:2.4.0'
compile 'com.squareup.retrofit:retrofit:1.7.1'
compile 'com.jakewharton:butterknife:6.0.0'
compile 'com.madgag.spongycastle:core:1.51.0.0'
compile 'com.madgag.spongycastle:prov:1.51.0.0'
compile 'com.madgag.spongycastle:pkix:1.51.0.0'
compile 'com.google.code.gson:gson:2.3'
compile 'commons-io:commons-io:2.4'
compile 'org.apache.httpcomponents:httpclient-android:4.3.5'
compile 'com.squareup.dagger:dagger:1.2.2'
compile 'com.squareup.dagger:dagger-compiler:1.2.2'
compile('com.googlecode.json-simple:json-simple:1.1.1') {
exclude module: 'junit'
}
compile 'com.google.android.gms:play-services:6.5.87'
}
The only new dependency since then has been the last line, which I added as per https://developer.android.com/google/gcm/client.html so I don't think that is the source of the problem.
EDIT2:
Yes, it was the source of the problem. As I needed Google Cloud Messaging, I replaced that dependency with the base as per http://developer.android.com/google/play-services/setup.html#split :
compile 'com.google.android.gms:play-services-base:6.5.87'
And it fixed the problem. Thank you for the help.
EDIT3:
As of play services 7.0.0, the GCM is in
compile 'com.google.android.gms:play-services-gcm:7.0.0'
EDIT4:
Play Services updated to 7.3.0.
Please keep check of the latest version here: http://developer.android.com/google/play-services/setup.html#split
The error means you have reached maximum method count in your app. That does include any libraries that you use for your project.
There are two ways to tackle the issue:
Get rid of any third-party libraries that you don't really need. If you use google play services that might contribute a lot to the method count. Fortunately as of the latest play-services release it is possible to include only parts of the framework.
Use a multi dex setup for your application.
I am phasing these problem & in my case used these link to overcome that error successfully..!!!
The DEX 64k limit is not a problem anymore, almost
To sum it up, adding multidex support:
In case of
UNEXPECTED TOP-LEVEL EXCEPTION:
com.android.dex.DexIndexOverflowException: method ID not in [0, 0xffff]: 65536
at com.android.dx.merge.DexMerger$6.updateIndex(DexMerger.java:502)
at com.android.dx.merge.DexMerger$IdMerger.mergeSorted(DexMerger.java:277)
at com.android.dx.merge.DexMerger.mergeMethodIds(DexMerger.java:491)
at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:168)
at com.android.dx.merge.DexMerger.merge(DexMerger.java:189)
at com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:454)
at com.android.dx.command.dexer.Main.runMonoDex(Main.java:302)
at com.android.dx.command.dexer.Main.run(Main.java:245)
at com.android.dx.command.dexer.Main.main(Main.java:214)
at com.android.dx.command.Main.main(Main.java:106)
Google decided to release an official solution for this in the form of the MultiDex Support Library.
dependencies {
...
compile 'com.android.support:multidex:'
...
}
Then enable multi-dexing by setting the multiDexEnabled flag in the buildType or productFlavor section of your gradle configuration.
defaultConfig {
...
multiDexEnabled true
...
}
Then depending on your project, you have 3 options:
If you haven’t created your own Application class, simply declare android.support.multidex.MultiDexApplication as your application class in AndroidManifest.xml
....
android:name="android.support.multidex.MultiDexApplication"
...
If you already have your own Application class, make it extend android.support.multidex.MultiDexApplication instead of android.app.Application
If your Application class is extending some other class and you don’t want to or can’t change it, override attachBaseContext() as shown below:
public class MyApplication extends FooApplication {
#Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
MultiDex.install(this);
}
}
Your compilation process might run out of memory.
To fix it, set the following dex options in the ‘android’ closure –
dexOptions {
incremental true
javaMaxHeapSize "4g"
}
More to know about multidex is here: http://developer.android.com/tools/building/multidex.html
Another link which becomes helping to solve a these error : Referance Link

Adding library in Android Studio make "UNEXPECTED TOP-LEVEL EXCEPTION"

I'm trying to add libraries from maven, specifically, Crouton library.
I can add it, Sync and use the Crouton object in my project, but when trying to run the app, i get this
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':timetable:preDexDebug'.
> com.android.ide.common.internal.LoggedErrorException: Failed to run command:
C:\Program Files (x86)\Android\android-studio\sdk\build-tools\19.0.1\dx.bat --dex --output D:\Developer\TimeTable3\timetable\build\pre-dexed\debug\crouton-library-1.8.2-c968ce53b92080dec516373cec51e9993ca5051f.jar C:\Users\Shahar\.gradle\caches\modules-2\files-2.1\de.keyboardsurfer.android.widget\crouton-library\1.8.2\725b0873131748c8c1bf2e1a27465e5bea857ab3\crouton-library-1.8.2.jar
Error Code:
1
Output:
error:
UNEXPECTED TOP-LEVEL EXCEPTION:
com.android.dx.cf.iface.ParseException: class name (de/keyboardsurfer/android/widget/crouton/Configuration$1) does not match path (release/de/keyboardsurfer/android/widget/crouton/Configuration$1.class)
at com.android.dx.cf.direct.DirectClassFile.parse0(DirectClassFile.java:520)
at com.android.dx.cf.direct.DirectClassFile.parse(DirectClassFile.java:406)
at com.android.dx.cf.direct.DirectClassFile.parseToInterfacesIfNecessary(DirectClassFile.java:388)
at com.android.dx.cf.direct.DirectClassFile.getMagic(DirectClassFile.java:251)
at com.android.dx.command.dexer.Main.processClass(Main.java:665)
at com.android.dx.command.dexer.Main.processFileBytes(Main.java:634)
at com.android.dx.command.dexer.Main.access$600(Main.java:78)
at com.android.dx.command.dexer.Main$1.processFileBytes(Main.java:572)
at com.android.dx.cf.direct.ClassPathOpener.processArchive(ClassPathOpener.java:284)
at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:166)
at com.android.dx.cf.direct.ClassPathOpener.process(ClassPathOpener.java:144)
at com.android.dx.command.dexer.Main.processOne(Main.java:596)
at com.android.dx.command.dexer.Main.processAllFiles(Main.java:498)
at com.android.dx.command.dexer.Main.runMonoDex(Main.java:264)
at com.android.dx.command.dexer.Main.run(Main.java:230)
at com.android.dx.command.dexer.Main.main(Main.java:199)
at com.android.dx.command.Main.main(Main.java:103)
...while parsing release/de/keyboardsurfer/android/widget/crouton/Configuration$1.class
EDIT: gradle file added
this is my gradle:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.7.+'
}
}
apply plugin: 'android'
android {
compileSdkVersion 15
buildToolsVersion '19.0.1'
defaultConfig {
minSdkVersion 15
targetSdkVersion 19
versionCode 1
versionName "1.0"
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
dependencies {
compile 'com.android.support:support-v4:+'
compile 'com.google.android.gms:play-services:4.0.30'
compile 'de.keyboardsurfer.android.widget:crouton-library:1.8.2'
compile files('libs/ActiveAndroid.jar')
}
if i use all three without "de.keyboardsurfer.android.widget:crouton-library:1.8.2"
then it all works ok.
Yeah, the build was broken. I didn't notice it locally. But thanks to you it's fixed and deployed to maven central. Clear your cache to get the new build of 1.8.2.
It looks like the crouton library is mispackaged. If you examine its contents:
jar -tf /Users/sbarta/.gradle/caches/modules-2/files-2.1/de.keyboardsurfer.android.widget/crouton-library/1.8.2/725b0873131748c8c1bf2e1a27465e5bea857ab3/crouton-library-1.8.2.jar
META-INF/
META-INF/MANIFEST.MF
release/
release/de/
release/de/keyboardsurfer/
release/de/keyboardsurfer/android/
release/de/keyboardsurfer/android/widget/
release/de/keyboardsurfer/android/widget/crouton/
release/de/keyboardsurfer/android/widget/crouton/Configuration$1.class
release/de/keyboardsurfer/android/widget/crouton/Configuration$Builder.class
release/de/keyboardsurfer/android/widget/crouton/Configuration.class
release/de/keyboardsurfer/android/widget/crouton/Crouton.class
release/de/keyboardsurfer/android/widget/crouton/DefaultAnimationsBuilder.class
release/de/keyboardsurfer/android/widget/crouton/LifecycleCallback.class
release/de/keyboardsurfer/android/widget/crouton/Manager$1.class
release/de/keyboardsurfer/android/widget/crouton/Manager$Messages.class
release/de/keyboardsurfer/android/widget/crouton/Manager.class
release/de/keyboardsurfer/android/widget/crouton/Style$1.class
release/de/keyboardsurfer/android/widget/crouton/Style$Builder.class
release/de/keyboardsurfer/android/widget/crouton/Style.class
release/de/keyboardsurfer/mobile/
release/de/keyboardsurfer/mobile/app/
release/de/keyboardsurfer/mobile/app/android/
release/de/keyboardsurfer/mobile/app/android/widget/
release/de/keyboardsurfer/mobile/app/android/widget/crouton/
release/de/keyboardsurfer/mobile/app/android/widget/crouton/BuildConfig.class
Everything is inside a release directory, but based on the error message, Configuration$1.class is in the package de.keyboardsurfer.android.widget.crouton (without release). You can contact the library author, or you could disassemble the jar, pull everything inside the release directory one level up, and repackage it.
The packing is wrong for the library on maven repository. So by the time it is corrected by author you can use the this libary as module by downloading and adding it in your project structure .
The path is https://github.com/keyboardsurfer/Crouton
I have informed author Benjamin Weiss on Google plus regarding the same.

Categories

Resources