Android中的transform.TransformException

Android中的transform.TransformException,android,itext,flying-saucer,Android,Itext,Flying Saucer,我在运行时尝试使用iText生成PDF时出错。 当应用程序以设备或geny运动方式运行时,会出现错误 Error:Execution failed for task ':app:transformClassesWithJarMergingForDebug'. com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: com/lowagie/bc/asn1/ASN

我在运行时尝试使用iText生成PDF时出错。 当应用程序以设备或geny运动方式运行时,会出现错误

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'

请帮助我解决此问题。

重复条目:com/lowagie/bc/asn1/asn1 encodable.class
-指向iText 2.1.7或更高版本,该版本与Android不兼容

您的Gradle文件中有几处错误:

  • 编译'com.itextpdf:itext pdfa:5.5.11'
    -指向与Android兼容的itext 5版本5.5.11的PDF/A附加组件,但您仍然需要itext 5的Android端口,称为iTextG。因此,您需要添加
    编译'com.itextpdf:itextg:5.5.10'
    。是的,
    5.5.10
    ,而不是
    5.5.11
    ,因为没有
    itextg:5.5.11
    。看
  • 我猜你认为“pdfa”中的“a”意味着Android,但事实并非如此。它代表PDF/A:PDF存档规范(ISO 19005),请参阅。如果您不需要存档(在典型的Android应用程序中,您可能不需要),那么您可能需要删除
    compile'com.itextpdf:itext pdfa:5.5.11'
  • 编译'com.itextpdf:itext7核心:7.0.3'
    -这是iText 7,它与Android不兼容。拆下那条线
  • compile'itext:itext:1.3.1'
    -是itext的一个古老版本,可能是它导致了您的错误。拆下那条线
  • 编译“org.xhtmlrenderer:flying-discer-pdf-itext5:9.1.6”
    -这是一种特殊的东西,我对它了解得还不够。它可能会也可能不会引入iText的另一个依赖项,这可能是错误的版本,也可能不是。用
    飞碟
    标记你的问题,以吸引更多的注意力

检查此项-@vishal我没有更改系统,也没有使用最新的v7转让任何项目……当我尝试使用iText并导入iText依赖项时,我遇到了这个问题感谢您的帮助。我们不需要使用各种iText库,只需要导入一个依赖项“compile'com.itextpdf:itextg:5.5.10”,这将解决我的问题…谢谢