Java.io.IOException: cannot handle class when running ProGuard in the assembly of the Maven Android project

I use the iText library to write new information to existing PDF files. To encrypt PDF files, iText (for Android) uses the SpongyCastle library, which is an Android BouncyCastle port. Unfortunately, both iText and Spongycastle contain a very large number of methods (15k +). Android has a hard limit on the number of methods you can use (64k). Fortunately, iText does not use many classes at Spongycastle Bank.

I was able to unzip the Spongycastle jar and delete all classes that iText does not use and does not decompress the file.

Everything worked fine until I ran proguard in the maven build to create the final apk. I get the following IOException, which makes no sense to me.

Your help in resolving this error will be greatly appreciated.

Thanks in advance. I also included the proguard.cfg part, which refers to the 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 
0
source share
1 answer

The problem is that your repackaged jar contains *.class files that do not start with the correct magic bytes, from which such a file is expected to start, i.e. 0xCAFEBABE, cf. this wikipedia article .

He also names the file in question:

 __MACOSX/spongycastleseriouslyreduced/org/spongycastle/crypto/._BlockCipher.class 

The naming scheme indicates that this is not really a *.class file, but instead a metafile added by some Mac zip program. Proguard does not know such Mac-specific materials and therefore crashes.

Thus, when you rezip a file, you must ensure that you do not add such Mac-specific things. This can be done, for example, using the jar Java SDK utility or the non-Mac zip utility.

+3
source

All Articles