2017-06-29 35 views
1

我在运行时尝试使用iText生成PDF时出现错误。 当应用程序在设备或geny Motion中运行时出现错误。Android中的transform.TransformException

Error:Execution failed for task ':app:transformClassesWithJarMergingForDebug'. 
com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: com/lowagie/bc/asn1/ASN1Encodable.class. 

我的摇篮代码是:

apply plugin: 'com.android.application' 

android { 
    compileSdkVersion 25 
    buildToolsVersion "25.0.1" 
    useLibrary 'org.apache.http.legacy' 
    defaultConfig { 
     applicationId "com.visioneering.tfd" 
     minSdkVersion 15 
     targetSdkVersion 24 
     versionCode 5 
     versionName "1.5" 
     multiDexEnabled true 

    } 
    buildTypes { 
     release { 
      minifyEnabled false 
      proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 
     } 
    } 

    dexOptions { 
     preDexLibraries = false 
     javaMaxHeapSize "4g" 
    } 
    android { 
     lintOptions { 
      checkReleaseBuilds false 
     } 
    } 
    packagingOptions { 
     exclude 'META-INF/DEPENDENCIES.txt' 
     exclude 'META-INF/LICENSE.txt' 
     exclude 'META-INF/NOTICE.txt' 
     exclude 'META-INF/NOTICE' 
     exclude 'META-INF/LICENSE' 
     exclude 'META-INF/DEPENDENCIES' 
     exclude 'META-INF/notice.txt' 
     exclude 'META-INF/license.txt' 
     exclude 'META-INF/dependencies.txt' 
     exclude 'META-INF/LGPL2.1' 
    } 

} 

dependencies { 
    compile fileTree(include: ['*.jar'], dir: 'libs') 
    compile 'com.android.support:appcompat-v7:25.2.0' 
    compile 'com.android.support:design:25.2.0' 
    compile 'com.google.firebase:firebase-core:10.2.1' 
    compile 'com.google.firebase:firebase-messaging:10.2.1' 
    compile 'com.github.florent37:materialtextfield:1.0.5' 
    compile 'com.android.support:cardview-v7:25.2.0' 
    compile 'com.android.support:support-v4:25.2.0' 
    compile 'com.google.android.gms:play-services:10.2.1' 
    compile 'com.fasterxml.jackson.core:jackson-databind:2.5.3' 
    compile 'com.googlecode.json-simple:json-simple:1.1' 
    compile 'com.weiwangcn.betterspinner:library-material:1.1.0' 
    compile 'com.android.support.constraint:constraint-layout:1.0.2' 
    compile 'com.itextpdf:itext7-core:7.0.3' 
    compile 'com.itextpdf:itext-pdfa:5.5.11' 
    compile 'itext:itext:1.3.1' 
    compile 'org.xhtmlrenderer:flying-saucer-pdf-itext5:9.1.6' 

} 

// ADD THIS AT THE BOTTOM 
apply plugin: 'com.google.gms.google-services' 

请帮我解决这个问题。

+0

入住这一点 - [java.util.zip.ZipException:重复的条目(https://stackoverflow.com/a/39120731/6244429) –

+0

@vishal我没有改变系统或者转让项目也使用最新的v7 ....这个问题我正面临着当我试图使用iText和导入iText依赖 –

回答

2

duplicate entry: com/lowagie/bc/asn1/ASN1Encodable.class - 指向iText 2.1.7或更高版本,它不被称为与Android兼容。

有一对夫妇在你的摇篮文件的东西错了:

  • compile 'com.itextpdf:itext-pdfa:5.5.11' - 指向PDF/A附加iText的5,版本5.5.11,这与Android兼容的,但您仍然需要iText 5的Android端口,即iTextG。所以你需要compile 'com.itextpdf:itextg:5.5.10'。是的,5.5.10,而不是5.5.11,因为没有itextg:5.5.11。请参阅http://repo1.maven.org/maven2/com/itextpdf/itextg/
  • 我是猜测您认为“pdfa”中的“a”表示Android,但它不是。它代表PDF/A:用于归档(ISO 19005)的PDF规范,请参阅https://en.wikipedia.org/wiki/PDF/A。如果你不需要存档(你可能不这样做,在一个典型的Android应用程序),那么你可能需要删除compile 'com.itextpdf:itext-pdfa:5.5.11'
  • compile 'com.itextpdf:itext7-core:7.0.3' - 这是iText的7,这是不与Android兼容。删除该行。
  • compile 'itext:itext:1.3.1' - 是iText的一个古老版本,可能是什么导致你的错误。删除该行。
  • compile 'org.xhtmlrenderer:flying-saucer-pdf-itext5:9.1.6' - 这是特别的东西,我不太了解。它可能会也可能不会引入iText的另一个依赖,这可能是也可能不是错误的版本。用flying-saucer标记您的问题以吸引额外的关注。
+0

谢谢你,你帮了我很多。而不是使用各种iText库,我们只需要导入一个依赖“compile”com.itextpdf:itextg:5.5.10'“这将解决我的问题...谢谢 –

+0

这是awsme。尝试这个。 https://stackoverflow.com/a/44843333/6523041 –