error while creating PDF - android

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

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.

Execution failed for task ':app:dexDebug'. java.exe finished with non-zero exit value 1

I am building an app that needs to connect to a Google app engine backend built in python. However every time i build the app i get this 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_11\bin\java.exe'' finished with non-zero exit value 1
I ran the build with --stacktrace and --info and got this
AGPBI: {"kind":"simple","text":"Uncaught translation error: java.util.concurrent.ExecutionException: java.lang.OutOfMemoryError: Java heap space","sources":[{}]}
AGPBI: {"kind":"simple","text":"Uncaught translation error: java.util.concurrent.ExecutionException: java.lang.OutOfMemoryError: Java heap space","sources":[{}]}
AGPBI: {"kind":"simple","text":"Uncaught translation error: java.util.concurrent.ExecutionException: java.lang.OutOfMemoryError: Java heap space","sources":[{}]}
AGPBI: {"kind":"simple","text":"Uncaught translation error: java.util.concurrent.ExecutionException: java.lang.OutOfMemoryError: Java heap space","sources":[{}]}
AGPBI: {"kind":"simple","text":"Uncaught translation error: java.util.concurrent.ExecutionException: java.lang.OutOfMemoryError: Java heap space","sources":[{}]}
AGPBI: {"kind":"simple","text":"5 errors; aborting","sources":[{}]}
The build.gradle file
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.1"
defaultConfig {
applicationId "com.test.testapp"
minSdkVersion 9
targetSdkVersion 23
versionCode 1
versionName "1.0"
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
repositories {
maven {
url 'http://google-api-client-libraries.appspot.com/mavenrepo'
}
mavenCentral()
mavenLocal()
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:appcompat-v7:23.1.0'
compile 'com.android.support:design:23.1.0'
compile project(':app:libs:customerapi')
compile([group: 'com.google.api-client', name: 'google-api-client', version: '1.20.0'])
compile 'com.google.android.gms:play-services:8.1.0'
compile 'com.android.support:support-v4:23.1.0'
compile 'com.google.api-client:google-api-client-android:1.20.0'
compile 'com.android.support:multidex:1.0.1'
}
I have no clue what is happening and could not find a solution.
Add this to your android closure in build.gradle:
dexOptions {
incremental true
javaMaxHeapSize "4g"
}
Answer found on https://groups.google.com/forum/#!topic/adt-dev/r4p-sBLl7DQ
The problem is that java runs out of memory during the gradle compilation. Increasing the heap size will raise the memory ceiling, allowing the compilation to complete successfully. Do you need to increase the heap to 4GB? No. But increasing it solved the problem I was having -- which happened to be the same as the original poster.

UNEXPECTED TOP-LEVEL EXCEPTION when using renderscriptSupportModeEnabled true

Hi i previously using renderscriptSupportModeEnabled true whiteout any problem but today when i want to run my app i giving this error message
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:502)
at com.android.dx.command.dexer.Main.runMonoDex(Main.java:334)
at com.android.dx.command.dexer.Main.run(Main.java:277)
at com.android.dx.command.dexer.Main.main(Main.java:245)
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_51\bin\java.exe'' finished with non-zero exit value 2
i even create new empty sample project with no dependency but same error message here is my .gradle file
android {
compileSdkVersion 22
buildToolsVersion "23.0.0 rc3"
defaultConfig {
applicationId "com.mk.sample"
minSdkVersion 10
targetSdkVersion 22
versionCode 1
versionName "1.0"
renderscriptTargetApi 19
renderscriptSupportModeEnabled true
}
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.2.1'
}
I can't say I understand this solution - or that it's necessarily a good fix, but it got my app compiling again:
configurations.all {
exclude group: 'com.android.support', module: 'support-annotations'
}
Also, see: Getting Multiple dex error when using render script support lib
and Using buildToolsVersion 23 fails because Multiple dex files define 'AnimRes'
Credit to Luboš Staráček for this solution

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.

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

I didn't modified library dependencies or even build.gradle script at all, just modified some code but this error showed up suddenly while it didn't before.
>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_15\bin\java.exe'' finished with non-zero exit value 2
I tried using --stacktrace --debug but not quite understand what I saw and it seemed the error just popped up suddenly like so
>Merged dex A (3701 defs/5082.9KiB) with dex B (266 defs/275.0KiB). Result is 3967 defs/5328.6KiB. Took 1.3s
Result compacted from 10118.4KiB to 8222.8KiB to save 1895.6KiB
Merged dex A (3967 defs/5328.6KiB) with dex B (3293 defs/2941.1KiB). Result is 7260 defs/8222.8KiB. Took 1.6s
>AGPBI: {"kind":"SIMPLE","text":"UNEXPECTED TOP-LEVEL EXCEPTION:","position":{},"original":"UNEXPECTED TOP-LEVEL EXCEPTION:"}
Now, what could be wrong or what can I do to understand what went wrong?
This is my gradle script, for reference
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
defaultConfig {
applicationId "com.xxx.yyy"
minSdkVersion 16
targetSdkVersion 21
versionCode 24
versionName "2.1.2"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
dexOptions {
javaMaxHeapSize "2g"
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.google.android.gms:play-services:6.1.71'
compile 'com.actionbarsherlock:actionbarsherlock:4.4.0#aar'
compile 'com.facebook.android:facebook-android-sdk:3.21.1'
compile 'net.simonvt.menudrawer:menudrawer:3.0.+#aar'
compile 'com.commonsware.cwac:sacklist:1.0.0'
compile 'com.commonsware.cwac:merge:1.1.+'
compile 'com.loopj.android:android-async-http:1.4.5'
compile project(':library')
}
I managed to solve it by adding multiDexEnabled true under defaultConfig section in my gradle script, don't know for sure why though.
UPDATE
It is due to 65K limit just as #clemp6r explained in the comment.

Categories

Resources