无法编译apk,Itext和Proguard冲突

5

我正在开发一个Android应用程序,现在我需要构建一个APK文件,为此我按照以下步骤进行:

1)Build -> Clean

2)Build -> Generate Signed APK

3)选择Jar Signature或Full APK Signature

但是,在生成应用程序时出现了错误:

Information:Gradle tasks [:app:assembleRelease]
Warning:com.itextpdf.text.pdf.PdfEncryptor: can't find referenced class org.spongycastle.cms.jcajce.JceKeyTransEnvelopedRecipient
Warning:com.itextpdf.text.pdf.PdfEncryptor: can't find referenced class org.spongycastle.cms.RecipientInformation
Warning:com.itextpdf.text.pdf.PdfEncryptor: can't find referenced class org.spongycastle.cms.CMSException
Warning:com.itextpdf.text.pdf.PdfEncryptor: can't find referenced class org.spongycastle.cms.RecipientInformation
Warning:com.itextpdf.text.pdf.PdfEncryptor: can't find referenced class org.spongycastle.cms.Recipient
Warning:com.itextpdf.text.pdf.PdfPublicKeySecurityHandler: can't find referenced class org.spongycastle.asn1.DEROutputStream
Warning:com.itextpdf.text.pdf.PdfPublicKeySecurityHandler: can't find referenced class org.spongycastle.asn1.ASN1InputStream
Warning:com.itextpdf.text.pdf.PdfPublicKeySecurityHandler: can't find referenced class org.spongycastle.asn1.DEROctetString
Warning:com.itextpdf.text.pdf.PdfPublicKeySecurityHandler: can't find referenced class org.spongycastle.asn1.DERSet
Warning:com.itextpdf.text.pdf.PdfPublicKeySecurityHandler: can't find referenced class org.spongycastle.asn1.cms.RecipientInfo
Warning:com.itextpdf.text.pdf.PdfPublicKeySecurityHandler: can't find referenced class org.spongycastle.asn1.DERSet
Warning:com.itextpdf.text.pdf.PdfPublicKeySecurityHandler: can't find referenced class org.spongycastle.asn1.x509.AlgorithmIdentifier
Warning:com.itextpdf.text.pdf.PdfPublicKeySecurityHandler: can't find referenced class org.spongycastle.asn1.ASN1ObjectIdentifier
Warning:com.itextpdf.text.pdf.PdfPublicKeySecurityHandler: can't find referenced class org.spongycastle.asn1.x509.AlgorithmIdentifier
Warning:com.itextpdf.text.pdf.PdfPublicKeySecurityHandler: can't find referenced class org.spongycastle.asn1.cms.EncryptedContentInfo
Warning:com.itextpdf.text.pdf.security.PdfPKCS7: can't find referenced class org.spongycastle.asn1.tsp.MessageImprint
Warning:com.itextpdf.text.pdf.security.PdfPKCS7: can't find referenced class org.spongycastle.asn1.ASN1Sequence
Warning:com.itextpdf.text.pdf.security.PdfPKCS7: can't find referenced class org.spongycastle.cert.ocsp.BasicOCSPResp
Warning:com.itextpdf.text.pdf.security.PdfPKCS7: can't find referenced class org.spongycastle.cert.ocsp.SingleResp
Warning:com.itextpdf.text.pdf.security.PdfPKCS7: can't find referenced class org.spongycastle.cert.ocsp.CertificateID
Warning:com.itextpdf.text.pdf.security.PdfPKCS7: can't find referenced class org.spongycastle.operator.DigestCalculator
Warning:com.itextpdf.text.pdf.security.PdfPKCS7: can't find referenced class org.spongycastle.cert.ocsp.CertificateID
Warning:com.itextpdf.text.pdf.security.PdfPKCS7: can't find referenced class org.spongycastle.asn1.ASN1Sequence
Warning:com.itextpdf.text.pdf.security.PdfPKCS7: can't find referenced class org.spongycastle.asn1.ASN1TaggedObject
Warning:com.itextpdf.text.pdf.security.PdfPKCS7: can't find referenced class org.spongycastle.asn1.ASN1Sequence
Warning:com.itextpdf.text.pdf.security.PdfPKCS7: can't find referenced class org.spongycastle.asn1.ASN1OctetString
Warning:com.itextpdf.text.pdf.security.PdfPKCS7: can't find referenced class org.spongycastle.asn1.ASN1InputStream
Warning:com.itextpdf.text.pdf.security.PdfPKCS7: can't find referenced class org.spongycastle.asn1.ocsp.BasicOCSPResponse
Warning:com.itextpdf.text.pdf.security.PdfPKCS7: can't find referenced class org.spongycastle.tsp.TimeStampToken
Warning:com.itextpdf.text.pdf.security.SignaturePolicyInfo: can't find referenced class org.spongycastle.asn1.esf.SigPolicyQualifierInfo
Warning:com.itextpdf.text.pdf.security.SignaturePolicyInfo: can't find referenced class org.spongycastle.asn1.pkcs.PKCSObjectIdentifiers
Warning:com.itextpdf.text.pdf.security.SignaturePolicyInfo: can't find referenced class org.spongycastle.asn1.DERIA5String
Warning:com.itextpdf.text.pdf.security.SignaturePolicyInfo: can't find referenced class org.spongycastle.asn1.esf.SigPolicyQualifierInfo
Warning:com.itextpdf.text.pdf.security.SignaturePolicyInfo: can't find referenced class org.spongycastle.asn1.esf.SigPolicyQualifiers
Warning:com.itextpdf.text.pdf.security.SignaturePolicyInfo: can't find referenced class org.spongycastle.asn1.esf.SignaturePolicyIdentifier
Warning:com.itextpdf.text.pdf.security.SignaturePolicyInfo: can't find referenced class org.spongycastle.asn1.esf.SignaturePolicyId
Warning:com.itextpdf.text.pdf.security.SignaturePolicyInfo: can't find referenced class org.spongycastle.asn1.DERObjectIdentifier
Warning:com.itextpdf.text.pdf.security.SignaturePolicyInfo: can't find referenced class org.spongycastle.asn1.esf.OtherHashAlgAndValue
Warning:com.itextpdf.text.pdf.security.SignaturePolicyInfo: can't find referenced class org.spongycastle.asn1.x509.AlgorithmIdentifier
Warning:com.itextpdf.text.pdf.security.SignaturePolicyInfo: can't find referenced class org.spongycastle.asn1.DEROctetString
Warning:com.itextpdf.text.pdf.security.SignaturePolicyInfo: can't find referenced class org.spongycastle.asn1.esf.OtherHashAlgAndValue
Warning:com.itextpdf.text.pdf.security.SignaturePolicyInfo: can't find referenced class org.spongycastle.asn1.esf.SignaturePolicyId
Warning:com.itextpdf.text.pdf.security.SignaturePolicyInfo: can't find referenced class org.spongycastle.asn1.esf.SignaturePolicyIdentifier
Warning:com.itextpdf.text.pdf.security.SignaturePolicyInfo: can't find referenced class org.spongycastle.asn1.pkcs.PKCSObjectIdentifiers
Warning:com.itextpdf.text.pdf.security.SignaturePolicyInfo: can't find referenced class org.spongycastle.asn1.esf.SignaturePolicyIdentifier
Warning:com.itextpdf.text.pdf.security.SignaturePolicyInfo: can't find referenced class org.spongycastle.asn1.esf.SigPolicyQualifierInfo
Warning:com.itextpdf.text.pdf.security.SignaturePolicyInfo: can't find referenced class org.spongycastle.asn1.esf.SigPolicyQualifiers
Warning:com.itextpdf.text.pdf.security.TSAClientBouncyCastle: can't find referenced class org.spongycastle.tsp.TimeStampRequestGenerator
Warning:com.itextpdf.text.pdf.security.TSAClientBouncyCastle: can't find referenced class org.spongycastle.asn1.ASN1ObjectIdentifier
Warning:com.itextpdf.text.pdf.security.TSAClientBouncyCastle: can't find referenced class org.spongycastle.tsp.TimeStampRequestGenerator
Warning:com.itextpdf.text.pdf.security.TSAClientBouncyCastle: can't find referenced class org.spongycastle.tsp.TimeStampRequest
Warning:com.itextpdf.text.pdf.security.TSAClientBouncyCastle: can't find referenced class org.spongycastle.tsp.TimeStampResponse
Warning:com.itextpdf.text.pdf.security.TSAClientBouncyCastle: can't find referenced class org.spongycastle.asn1.cmp.PKIFailureInfo
Warning:com.itextpdf.text.pdf.security.TSAClientBouncyCastle: can't find referenced class org.spongycastle.tsp.TimeStampResponse
Warning:com.itextpdf.text.pdf.security.TSAClientBouncyCastle: can't find referenced class org.spongycastle.tsp.TimeStampToken
Warning:com.itextpdf.text.pdf.security.TSAClientBouncyCastle: can't find referenced class org.spongycastle.tsp.TimeStampTokenInfo
Warning:com.itextpdf.text.pdf.security.TSAClientBouncyCastle: can't find referenced class org.spongycastle.tsp.TSPException
Warning:com.itextpdf.text.pdf.security.TSAClientBouncyCastle: can't find referenced class org.spongycastle.tsp.TimeStampRequest
Warning:com.itextpdf.text.pdf.security.TSAClientBouncyCastle: can't find referenced class org.spongycastle.asn1.cmp.PKIFailureInfo
Warning:com.itextpdf.text.pdf.security.TSAClientBouncyCastle: can't find referenced class org.spongycastle.tsp.TimeStampToken
Warning:com.itextpdf.text.pdf.security.TSAClientBouncyCastle: can't find referenced class org.spongycastle.tsp.TimeStampTokenInfo
Warning:com.itextpdf.text.pdf.security.TSAClientBouncyCastle: can't find referenced class org.spongycastle.tsp.TimeStampRequestGenerator
Warning:com.itextpdf.text.pdf.security.TSAClientBouncyCastle: can't find referenced class org.spongycastle.tsp.TimeStampRequest
Warning:com.itextpdf.text.pdf.security.TSAClientBouncyCastle: can't find referenced class org.spongycastle.tsp.TimeStampResponse
Warning:com.itextpdf.text.pdf.security.TSAClientBouncyCastle: can't find referenced class org.spongycastle.asn1.cmp.PKIFailureInfo
Warning:com.itextpdf.text.pdf.security.TSAClientBouncyCastle: can't find referenced class org.spongycastle.tsp.TimeStampToken
Warning:com.itextpdf.text.pdf.security.TSAClientBouncyCastle: can't find referenced class org.spongycastle.tsp.TimeStampTokenInfo
Warning:com.itextpdf.text.pdf.security.TSAInfoBouncyCastle: can't find referenced class org.spongycastle.tsp.TimeStampTokenInfo
Warning:org.joda.convert.AbstractTypeStringConverter: can't find referenced class com.google.common.collect.ImmutableMap
Warning:org.joda.convert.AbstractTypeStringConverter: can't find referenced class com.google.common.collect.ImmutableMap$Builder
Warning:org.joda.convert.AbstractTypeStringConverter: can't find referenced class com.google.common.collect.ImmutableMap
Warning:org.joda.convert.AbstractTypeStringConverter: can't find referenced class com.google.common.collect.ImmutableMap$Builder
Warning:org.joda.convert.AbstractTypeStringConverter: can't find referenced class com.google.common.collect.ImmutableMap
Warning:org.joda.convert.TypeStringConverter: can't find referenced class com.google.common.reflect.TypeToken
Warning:org.joda.convert.TypeTokenStringConverter: can't find referenced class com.google.common.reflect.TypeToken
Warning:there were 823 unresolved references to classes or interfaces.
Warning:Exception while processing task java.io.IOException: Please correct the above warnings first.
Error:Execution failed for task ':app:transformClassesAndResourcesWithProguardForRelease'.
> Job failed, see logs for details
Information:BUILD FAILED

我不知道如何解决这个问题。

我尝试了什么?

我在我的proguard-android文件中加入了这段代码(位于\AppData\Local\Android\sdk\tools\proguard)。

Rif

-keep class org.spongycastle.** { *; }
-dontwarn org.spongycastle.**

这个解决方案对我不起作用,问题仍然存在。

**** 当前的解决方案 ****

实际上,我找到的唯一一个解决方案是在gradle中设置以下值:

1) shrinkResources false

2) minifyEnabled false


如果你想使用Proguard来缩小你的应用程序,那么你的解决方案是不正确的,因为你正在禁用它。但是除此之外,它是正确的。 - Mahdi-Malv
禁用Proguard肯定不是解决方案... - Pablo Rodriguez
3个回答

6

尝试将此放入proguard规则中

-keep class com.itextpdf.** { *; }
-dontwarn com.itextpdf.**

2

尝试将以下内容添加到Gradle中:

android{
...
 dexOptions {
    jumboMode true
}
...
}

实际上我找到的唯一解决方案是设置以下两个属性:1) shrinkResources false 2) minifyEnabled false。 - Mattia

1
如果您保留所有iText类,那么使用Proguard的意义何在?
仔细观察,您会发现所有警告都包含com.itextpdf.text.pdf包,因此我们只需保留它。还有org.joda.convert。所以我们有:
-keep class com.itextpdf.text.pdf.** {*;}
-dontwarn com.itextpdf.text.pdf.**
-keep class org.joda.convert.** {*;}
-dont warn org.joda.convert.**

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接