创建PDF

时间:2015-06-08 13:30:25

标签: android pdf android-studio itext

我正在尝试使用Android Studio生成PDF。我正在使用iText库,但当我将其添加到Android studio时,我收到以下错误:

  

错误:任务':app:dexDebug'的执行失败。   com.android.ide.common.process.ProcessException:org.gradle.process.internal.ExecException:进程'命令'C:\ Program Files \ Java \ jdk1.7.0_79 \ bin \ java.exe''以非完成零退出值2

当我删除库时,我的项目成功编译。当使用Eclipse而不是Android Studio时,它可以正常工作。

编辑

这是我的build.gradle文件

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')
}

错误列表而非发布行

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

2 个答案:

答案 0 :(得分:1)

昨天我遇到了类似的问题。只需将其添加到build.gradle文件中并清理/使项目无效=)

android {

    ....

    dexOptions {

        jumboMode = true
    }
}

答案 1 :(得分:0)

我使用了由#Br; Bruno Lowagie"提供的iTextG库。在评论和删除未使用的库。

com.android.dex.DexIndexOverflowException:例外是因为

而到达的

根据Android开发者网站

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

但是使用这种方法我们就会出现内存问题。为了解决这个问题,我们必须添加android闭包。

dexOptions { 
   incremental true 
   javaMaxHeapSize "4g" 
}

http://www.mutualmobile.com/posts/dex-64k-limit-not-problem-anymore-almost