MultiDex issue - Execution failed for task ':app:dexDebug' - android

I face a problem while adding a line for Google Calendar API to build.gradle. Here is the error:
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)
Error:Execution failed for task ':app:dexDebug'.
> com.android.ide.common.process.ProcessException:
org.gradle.process.internal.ExecException: Process 'command
'/usr/java/jdk1.7.0_79/bin/java''
finished with non-zero exit value 2
Information:BUILD FAILED
Information:Total time: 14.802 secs
Information:1 error
Information:2 warnings
Information:See complete output in console
I have tried many options but nothing is working. When I add "multiDex true" to defaultConfig, appcompat library doesn't connect to my project, and application crashes with java.lang.NoClassDefFoundError: android.support.v7.appcompat.R$layout.
Here's my build.gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
defaultConfig {
applicationId "ua.appp.appp"
minSdkVersion 14
targetSdkVersion 21
versionCode 15
versionName "2.1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:22.0.0'
compile 'com.google.android.gms:play-services:6.5.87'
compile 'com.google.apis:google-api-services-calendar:v3-rev119-1.19.1'
compile 'com.google.api-client:google-api-client:1.19.1'
compile 'com.google.api-client:google-api-client-android:1.19.1'
compile 'com.google.api-client:google-api-client-gson:1.19.1'
compile 'com.github.navasmdc:MaterialDesign:1.+#aar'
compile 'com.afollestad:material-dialogs:0.6.5.2'
compile 'com.nhaarman.listviewanimations:lib-core:3.1.0#aar'
compile 'com.nhaarman.listviewanimations:lib-manipulation:3.1.0#aar'
compile 'com.nhaarman.listviewanimations:lib-core-slh:3.1.0#aar'
}
PS: Some interesting fact: When I add all these libraries to a test project, code compiles and works fine without an error.

When you add the multidex:true don't forget to make an Application class in your project that extends from the MultiDexApplication or a lot of bad stuff will happen
public class YourApplication extends MultiDexApplication {
..........
}
And don't forget this either (the version may change over time, if you read this, make sure you use the latest version)
dependencies {
'com.android.support:multidex:1.0.1'
}

Related

Build APK - ERROR - app:transformClassesWithDexForDebug

I watched so many threads here and still didnt find working solution.
When I want to BUILD APK, I get this main error:
Error:Execution failed for task
':app:transformClassesWithDexForDebug'.
com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException:
java.util.concurrent.ExecutionException:
com.android.ide.common.process.ProcessException: Error while executing
java process with main class com.android.dx.command.Main with
arguments {--dex --num-threads=4 --multi-dex --main-dex-list
C:\Users\ratik\Desktop\BUILDBOX\VOLUNTEER\STUDIO\app\build\intermediates\multi-dex\debug\maindexlist.txt
--output C:\Users\ratik\Desktop\BUILDBOX\VOLUNTEER\STUDIO\app\build\intermediates\transforms\dex\debug\folders\1000\1f\main
C:\Users\ratik\Desktop\BUILDBOX\VOLUNTEER\STUDIO\app\build\intermediates\transforms\jarMerging\debug\jars\1\1f\combined.jar}
There is few more errors, but then apear only sometimes, some of them:
Error: at
com.android.dx.cf.direct.ClassPathOpener.processArchive(ClassPathOpener.java:284)
Error: at
com.android.dx.command.dexer.Main.processFileBytes(Main.java:723)
Error: at
com.android.dx.cf.direct.DirectClassFile.parseToInterfacesIfNecessary(DirectClassFile.java:388)
Error:java.lang.OutOfMemoryError: GC overhead limit exceeded
What I tried:
In build.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
defaultConfig {
applicationId "com.biif.volunteer"
minSdkVersion 14
targetSdkVersion 25
multiDexEnabled true
ndk {
moduleName "player_shared"
}
}
buildTypes {
release {
minifyEnabled false
shrinkResources false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
sourceSets.main {
jni.srcDirs = []// <-- disable automatic ndk-build call
}
}
dependencies {
compile ('com.google.android.gms:play-services:+'){exclude module: 'support-v4'}
compile files('libs/dagger-1.2.2.jar')
compile files('libs/javax.inject-1.jar')
compile files('libs/nineoldandroids-2.4.0.jar')
compile files('libs/support-v4-19.0.1.jar')
compile ('com.android.support:multidex:1.0.1')
}
In Manifest
android:name="android.support.multidex.MultiDexApplication"
Plus I turned off Instant run (saw in one thread here).
Nothing helped :( Any ideas please? Thanks for help guys :)
I included gradle.properties file in the project with:
org.gradle.jvmargs=-Xmx10248m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
and it works.

Error while building application on Android Studio

I am new on Android Studio. I am facing below mentioned error while building the project.
:app:shrinkDebugMultiDexComponents FAILED
Error:Execution failed for task ':app:shrinkDebugMultiDexComponents'.
> java.io.IOException: Can't read [D:\StudioWorkspace\SampleSDKDemoProject\app\build\intermediates\multi-dex\debug\allclasses.jar] (Can't process class [org/fmod/FMODAudioDevice.class] (256))
Here is my build.gradle file inside app folder.
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion '21.1.2'
defaultConfig {
applicationId "com.test.offerwall"
minSdkVersion 9
targetSdkVersion 21
versionCode 1
versionName "1.0"
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile 'com.bee7.gamewall.aar:bee7#aar'
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.google.android.gms:play-services-base:6.5.87'
compile 'com.test.android.ads.aar:myapp#aar'
compile 'com.google.android.gms:play-services:7.5.0'
}
repositories {
flatDir {
dirs 'libs'
}
}
I have updated the android sdk also but no luck. Could you guys help me out that why I am facing this issue.
Kindly help me out with the solution.
Thanks in advance.
As commented: I have tried using removing the multiDexEnabled true
Then I got this error.
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)
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_45\bin\java.exe'' finished with non-zero exit value 2
For the first error remove multiDexEnabled true.
UNEXPECTED TOP-LEVEL EXCEPTION:
for this one remove one of your com.google.android.gms:play-services libraries it is included more than once.
or add this in your build.gradle at the root level:
configurations {
all*.exclude group: 'com.google.android.gms', module: 'play-services'
}
hope this will help.

error while creating PDF

I am trying to generate a PDF using Android Studio. I am using the iText library, but when I add it into Android studio, I get the following 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_79\bin\java.exe'' finished with non-zero exit value 2
When I remove the library, my project successfully compiles. It works as expected when using Eclipse instead of Android Studio.
EDIT
Here is my build.gradle file
apply plugin: 'com.android.application'
android {
compileSdkVersion 22
buildToolsVersion "22.0.1"
defaultConfig {
applicationId "com.abc"
minSdkVersion 9
targetSdkVersion 22
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
}
dependencies {
compile project(':Wheel')
compile project(':facebook')
compile files('libs/mint-4.0.8.jar')
compile 'com.android.support:support-v4:22.1.0'
compile 'com.google.android.gms:play-services:7.0.0'
compile 'com.android.support:appcompat-v7:22.1.0'
compile 'com.google.code.gson:gson:2.3.1'
compile 'com.android.support:recyclerview-v7:22.1.0'
compile 'com.squareup.picasso:picasso:2.5.2'
compile files('libs/itextpdf-5.5.6.jar')
}
And error list instead of line posted
UNEXPECTED TOP-LEVEL EXCEPTION:
com.android.dex.DexIndexOverflowException: Cannot merge new index 66843 into a non-jumbo instruction!
at com.android.dx.merge.InstructionTransformer.jumboCheck(InstructionTransformer.java:109)
at com.android.dx.merge.InstructionTransformer.access$800(InstructionTransformer.java:26)
at com.android.dx.merge.InstructionTransformer$StringVisitor.visit(InstructionTransformer.java:72)
at com.android.dx.io.CodeReader.callVisit(CodeReader.java:114)
at com.android.dx.io.CodeReader.visitAll(CodeReader.java:89)
at com.android.dx.merge.InstructionTransformer.transform(InstructionTransformer.java:49)
at com.android.dx.merge.DexMerger.transformCode(DexMerger.java:842)
at com.android.dx.merge.DexMerger.transformMethods(DexMerger.java:813)
at com.android.dx.merge.DexMerger.transformClassData(DexMerger.java:785)
at com.android.dx.merge.DexMerger.transformClassDef(DexMerger.java:682)
at com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:542)
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.7.0_79\bin\java.exe'' finished with non-zero exit value 2
I faced a similar problem yesterday. Just add this to your build.gradle file and clean/invalidate your project =)
android {
....
dexOptions {
jumboMode = true
}
}
I used iTextG library as suggesed by "Bruno Lowagie" in comment and Remove unused libraries.
The com.android.dex.DexIndexOverflowException: exception is arrived because
As per android developer site
The Dalvik Executable specification limits the total number of methods that can be referenced within a single DEX file to 65,536, including Android framework methods, library methods, and methods in your own code.
https://developer.android.com/tools/building/multidex.html
But with this method we got out of memory issue. To fix this we have to add in android closure.
dexOptions {
incremental true
javaMaxHeapSize "4g"
}
http://www.mutualmobile.com/posts/dex-64k-limit-not-problem-anymore-almost

Android GraphView Gradle "Failed to run" Error?

i need to do more graph in my app and i thought to import that library ( http://www.android-graphview.org/ ).
I just follow the rules and i add to the gradle the compile row.
That is :
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion "21.1.1"
defaultConfig {
applicationId "com.btc.btcmobile"
minSdkVersion 17
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:21.0.3'
compile 'com.jjoe64:graphview:4.0.0'
}
after that, i copy-paste the example on the site, but when i compile now i can see that error:
Error:Execution failed for task ':app:dexDebug'.
com.android.ide.common.internal.LoggedErrorException: Failed to run command:
C:\Users\valerio\AppData\Local\Android\sdk2\build-tools\21.1.1\dx.bat --dex --no-optimize --output C:\Users\valerio\Desktop\BtcMobile\btcmobile\app\build\intermediates\dex\debug --input-list=C:\Users\valerio\Desktop\BtcMobile\btcmobile\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/jjoe64/graphview/BuildConfig;
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: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)
UNEXPECTED TOP-LEVEL EXCEPTION:
How i can resolve?
Thanks.
In my case I had the GraphView4.1.jar inside the libs folder. I also had compile 'com.jjoe64:graphview:4.0.1' in the build.gradle. As soon as I removed the jar file from libs folder, the com.android.dex.DexException error was resolved.

Multiple dependencies are trying to import “UNEXPECTED TOP-LEVEL EXCEPTION:”

I have two libraries on my proyect.
https://github.com/rengwuxian/MaterialEditText
https://github.com/navasmdc/MaterialDesignLibrary
It compiles, but when I run the program it reports an error.
UNEXPECTED TOP-LEVEL EXCEPTION:
Error:Execution failed for task ':app:dexDebug'.
> com.android.ide.common.internal.LoggedErrorException: Failed to run command:
C:\Users\Alvaro\AppData\Local\Android\sdk\build-tools\21.1.2\dx.bat --dex --no-optimize --output D:\ALVARO\AndroidStudioProjects\Proyecto\app\build\intermediates\dex\debug --input-list=D:\Alva\AndroidStudioProjects\Proyecto\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/nineoldandroids/animation/Animator$AnimatorListener;
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)
I KNOW THE PROBLEM, BUT I CAN'T SOLVE
Problem
Multiple dependencies are trying to import nineoldandroids exactly "nineoldandroids"
app build.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
defaultConfig {
applicationId "com.example.alva.proyecto"
minSdkVersion 14
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt')
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:appcompat-v7:21.0.3'
//seconds library
compile project(':materialDesign')
//first library
compile project(':EditText')
}
first library build.gradle
apply plugin: 'com.android.library'
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
defaultConfig {
minSdkVersion 14
targetSdkVersion 21
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile 'com.android.support:support-annotations:21.0.3'
compile 'com.nineoldandroids:library:2.4.0'
compile 'com.android.support:appcompat-v7:21.0.3'
}
seconds library build.gradle
apply plugin: 'com.android.library'
android {
compileSdkVersion 8
buildToolsVersion "19.1.0"
defaultConfig {
minSdkVersion 8
targetSdkVersion 8
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
dependencies {
compile 'com.android.support:support-v4:18.+'
compile files('libs/nineoldandroids-2.4.0.jar')
}
I have tried:
1. Put on "app" build.gradle:
compile project(':EditText') {
exclude group: 'com.nineoldandroids', module: 'library:2.4.0'
}
NOT WORKS, IT'S REPORTS AN ERROR
Error:(31, 0) Gradle DSL method not found: 'exclude()'
Possible causes:<ul><li>The project 'Proyecto' may be using a version of Gradle that does not contain the method.
Gradle settings</li><li>The build file may be missing a Gradle plugin.
Apply Gradle plugin</li>
2. Remove "nineoldandroids" from seconds library, NOT WORKS
Any suggestions?
I don't know how to import using their respective artifacts
It is in the documentation for each library.
The MaterialEditText "Download" section cites:
compile 'com.rengwuxian.materialedittext:library:1.8.2'
The "How to Use" section of MaterialDesignLibrary cites:
repositories {
jcenter()
}
dependencies {
compile 'com.github.navasmdc:MaterialDesign:1.+#aar'
}
Then, Gradle will (hopefully) be able to detect that both of these dependencies themselves depend upon nineoldandroids and resolve the conflict. I say "hopefully" because whichever library the "seconds library build.gradle" comes from uses a local copy of nineoldandroids, which is not a good idea. Neither GitHub repo seems to have that particular build.gradle file, though, so you may be OK.

Categories

Resources