我使用一个名为 iText 的库将新信息写入现有 PDF。为了加密 PDF,iText(适用于 Android)使用名为 SpongyCastle 的库,它是 BouncyCastle 的 Android 端口。不幸的是,iText 和 Spongycastle 都包含大量的方法(15k+)。在 Android 中,您可以使用的方法数量有一个硬性限制(64k)。幸运的是,iText 并没有使用 Spongycastle jar 中的很多类。
我能够解压缩 Spongycastle jar 并删除 iText 不使用的所有类并重新压缩文件。
一切都很好,直到我在 Maven 构建中运行 proguard 以生成最终的 apk。我得到以下对我没有意义的 IOException。
非常感谢您帮助解决此错误。
先感谢您。我还包括了 proguard.cfg 中引用 bouncycastle 的部分。
-keep class org.bouncycastle.crypto.** {*;}
[DEBUG] Reading program jar [.m2/repository/com/madgag/sc-light-jdk15on/1.47.0.2/sc-light-jdk15on-1.47.0.2-reduced.jar] (filtered)
[INFO] Warning: class [spongycastleseriouslyreduced/org/spongycastle/asn1/ASN1InputStream.class] unexpectedly contains class [org.spongycastle.asn1.ASN1InputStream]
[INFO] Warning: class [spongycastleseriouslyreduced/org/spongycastle/asn1/DEROutputStream.class] unexpectedly contains class [org.spongycastle.asn1.DEROutputStream]
[INFO] Warning: class [spongycastleseriouslyreduced/org/spongycastle/crypto/BlockCipher.class] unexpectedly contains class [org.spongycastle.crypto.BlockCipher]
[INFO] java.io.IOException: Can't read [.m2/repository/com/madgag/sc-light-jdk15on/1.47.0.2/sc-light-jdk15on-1.47.0.2-reduced.jar(;;;;!META-INF/maven/**,!META-INF/MANIFEST.MF)] (Can't process class [__MACOSX/spongycastleseriouslyreduced/org/spongycastle/crypto/._BlockCipher.class] (Invalid magic number [51607] in class))
[INFO] at proguard.InputReader.readInput(InputReader.java:230)
[INFO] at proguard.InputReader.readInput(InputReader.java:200)
[INFO] at proguard.InputReader.readInput(InputReader.java:178)
[INFO] at proguard.InputReader.execute(InputReader.java:78)
[INFO] at proguard.ProGuard.readInput(ProGuard.java:196)
[INFO] at proguard.ProGuard.execute(ProGuard.java:78)
[INFO] at proguard.ProGuard.main(ProGuard.java:492)
[INFO] Caused by: java.io.IOException: Can't process class [__MACOSX/spongycastleseriouslyreduced/org/spongycastle/crypto/._BlockCipher.class] (Invalid magic number [51607] in class)
[INFO] at proguard.io.ClassReader.read(ClassReader.java:112)
[INFO] at proguard.io.FilteredDataEntryReader.read(FilteredDataEntryReader.java:87)
[INFO] at proguard.io.FilteredDataEntryReader.read(FilteredDataEntryReader.java:87)
[INFO] at proguard.io.JarReader.read(JarReader.java:65)
[INFO] at proguard.io.DirectoryPump.readFiles(DirectoryPump.java:65)
[INFO] at proguard.io.DirectoryPump.pumpDataEntries(DirectoryPump.java:53)
[INFO] at proguard.InputReader.readInput(InputReader.java:226)
[INFO] ... 6 more
[INFO] Caused by: java.lang.UnsupportedOperationException: Invalid magic number [51607] in class
[INFO] at proguard.classfile.util.ClassUtil.checkMagicNumber(ClassUtil.java:47)
[INFO] at proguard.classfile.io.ProgramClassReader.visitProgramClass(ProgramClassReader.java:79)
[INFO] at proguard.classfile.ProgramClass.accept(ProgramClass.java:346)
[INFO] at proguard.io.ClassReader.read(ClassReader.java:91)
[INFO] ... 12 more