Crash when adding bouncy castle as a dependncy

Using IntelliJ 2016.2, MOE plugin 1.2.1, JDK 1.8.0_101, XCode 7.3.1

I created a new “Single View Application”.
Start in iOS 9.3 iPhone 5s simulator, works!

Add gradle dependency
compile 'org.bouncycastle:bcpkix-jdk15on:1.55'

Start in iOS simulator, blue launch screen shows up for a sec then crash, logs below

I only add a dependency nothing else. Can I please get advice on how to add Bouncy Castle 1.55 as a dependency.

/Users/User/multios-app/gradlew moeLaunch -Pmoe.launcher.options=no-build,config:Debug -Pmoe.launcher.simulators=4CC6DA3B-0776-4B15-BB33-1A8BFC96092A
:moeLaunchart I 66742 3767070 /Volumes/SSD/gh-moe-master-1.2.3/aosp/art/runtime/parsed_options.cc:449] setting boot class path to /Users/User/Library/Developer/CoreSimulator/Devices/4CC6DA3B-0776-4B15-BB33-1A8BFC96092A/data/Containers/Bundle/Application/455E4DF5-8B04-43E5-BB9B-F8744FFC4359/MultiOsWallet.app/application.jar:/Users/User/Library/Developer/CoreSimulator/Devices/4CC6DA3B-0776-4B15-BB33-1A8BFC96092A/data/Containers/Bundle/Application/455E4DF5-8B04-43E5-BB9B-F8744FFC4359/MultiOsWallet.app
art F 66742 3767070 /Volumes/SSD/gh-moe-master-1.2.3/aosp/art/runtime/java_vm_ext.cc:456] JNI DETECTED ERROR IN APPLICATION: java_array == null
art F 66742 3767070 /Volumes/SSD/gh-moe-master-1.2.3/aosp/art/runtime/java_vm_ext.cc:456]     in call to GetArrayLength
art F 66742 3767070 /Volumes/SSD/gh-moe-master-1.2.3/aosp/art/runtime/java_vm_ext.cc:456]     from long org.moe.natj.objc.ObjCRuntime.registerClass(java.lang.Class)
art F 66742 3767070 /Volumes/SSD/gh-moe-master-1.2.3/aosp/art/runtime/java_vm_ext.cc:456] "main" prio=5 tid=1 Runnable
art F 66742 3767070 /Volumes/SSD/gh-moe-master-1.2.3/aosp/art/runtime/java_vm_ext.cc:456]   | group="main" sCount=0 dsCount=0 obj=0x202d50a0 self=0x7fd5fb810200
art F 66742 3767070 /Volumes/SSD/gh-moe-master-1.2.3/aosp/art/runtime/java_vm_ext.cc:456]   | sysTid=3767070 nice=-1 cgrp=default sched=1/31 handle=0x9973000
art F 66742 3767070 /Volumes/SSD/gh-moe-master-1.2.3/aosp/art/runtime/java_vm_ext.cc:456]   | state=? schedstat=( 0 0 0 ) utm=0 stm=0 core=0 HZ=100
art F 66742 3767070 /Volumes/SSD/gh-moe-master-1.2.3/aosp/art/runtime/java_vm_ext.cc:456]   | stack=0x7fff5ea8e000-0x7fff5ea96000 stackSize=8MB
art F 66742 3767070 /Volumes/SSD/gh-moe-master-1.2.3/aosp/art/runtime/java_vm_ext.cc:456]   | held mutexes= "mutator lock"(shared held)
art F 66742 3767070 /Volumes/SSD/gh-moe-master-1.2.3/aosp/art/runtime/java_vm_ext.cc:456]   at org.moe.natj.objc.ObjCRuntime.registerClass(Native method)
art F 66742 3767070 /Volumes/SSD/gh-moe-master-1.2.3/aosp/art/runtime/java_vm_ext.cc:456]   at org.moe.natj.objc.ObjCRuntime.doRegistration(ObjCRuntime.java:73)
art F 66742 3767070 /Volumes/SSD/gh-moe-master-1.2.3/aosp/art/runtime/java_vm_ext.cc:456]   at org.moe.natj.general.NatJ.register(NatJ.java:265)
art F 66742 3767070 /Volumes/SSD/gh-moe-master-1.2.3/aosp/art/runtime/java_vm_ext.cc:456]   at apple.NSObject.<clinit>(NSObject.java:65)
art F 66742 3767070 /Volumes/SSD/gh-moe-master-1.2.3/aosp/art/runtime/java_vm_ext.cc:456] 
art F 66742 3767070 /Volumes/SSD/gh-moe-master-1.2.3/aosp/art/runtime/runtime.cc:464]Runtime aborting...

Aborting thread:
NATIVE BACKTRACE:
"main" prio=5 tid=1 Native
0   MOE                                 0x00000000072b2d27 _ZN3art7Runtime5AbortEv + 97
  | group="" sCount=0 dsCount=0 obj=0x202d50a0 self=0x7fd5fb810200
1   MOE                                 0x00000000072eae35 _ZN3art10LogMessageD2Ev + 807
  | sysTid=3767070 nice=-1 cgrp=default sched=1/31 handle=0x9973000
2   MOE                                 0x00000000071e661e _ZN3art9JavaVMExt8JniAbortEPKcS2_ + 1656
  | state=? schedstat=( 0 0 0 ) utm=0 stm=0 core=0 HZ=100
3   MOE                                 0x00000000071e69b1 _ZN3art9JavaVMExt9JniAbortVEPKcS2_P13__va_list_tag + 87
  | stack=0x7fff5ea8e000-0x7fff5ea96000 stackSize=8MB
4   MOE                                 0x00000000071e6a6a _ZN3art9JavaVMExt9JniAbortFEPKcS2_z + 134
  | held mutexes= "abort lock"
5   MOE                                 0x000000000751244e _ZN3art3JNI14GetArrayLengthEP7_JNIEnvP7_jarray + 144
  at org.moe.natj.objc.ObjCRuntime.registerClass(Native method)
6   MOE                                 0x000000000770e002 _ZL17registerObjCClassP7_JNIEnvP7_jclassbP8_jstringS2_ + 2679
  at org.moe.natj.objc.ObjCRuntime.doRegistration(ObjCRuntime.java:73)
7   ???                                 0x000000001c26225e 0x0 + 472261214
  at org.moe.natj.general.NatJ.register(NatJ.java:265)

  at apple.NSObject.<clinit>(NSObject.java:65)
Pending exception java.lang.ExceptionInInitializerError: 
  at java.lang.Class java.lang.ClassLoader.findLoadedClass(java.lang.String) (ClassLoader.java:373)
  at java.lang.Class java.lang.BootClassLoader.loadClass(java.lang.String, boolean) (ClassLoader.java:849)
  at java.lang.Class java.lang.ClassLoader.loadClass(java.lang.String) (ClassLoader.java:480)
  at java.lang.Class libcore.reflect.InternalNames.getClass(java.lang.ClassLoader, java.lang.String) (InternalNames.java:53)
  at java.lang.Class java.lang.Class.getDexCacheType(com.android.dex.Dex, int) (Class.java:521)
  at java.lang.Class java.lang.reflect.Method.getReturnType() (Method.java:173)
  at java.lang.reflect.Method[] java.lang.Class.getDeclaredMethods() (Class.java:717)
  at long org.moe.natj.objc.ObjCRuntime.registerClass(java.lang.Class) (ObjCRuntime.java:-2)
  at void org.moe.natj.objc.ObjCRuntime.doRegistration(java.lang.Class) (ObjCRuntime.java:73)
  at void org.moe.natj.general.NatJ.register() (NatJ.java:265)
  at void apple.NSObject.<clinit>() (NSObject.java:65)
Caused by: java.lang.SecurityException: /Users/User/Library/Developer/CoreSimulator/Devices/4CC6DA3B-0776-4B15-BB33-1A8BFC96092A/data/Containers/Bundle/Application/455E4DF5-8B04-43E5-BB9B-F8744FFC4359/MultiOsWallet.app/application.jar failed verification of META-INF/BCKEY.SF
  at java.lang.SecurityException java.util.jar.JarVerifier.failedVerification(java.lang.String, java.lang.String) (JarVerifier.java:145)
  at void java.util.jar.JarVerifier.verifyCertificate(java.lang.String) (JarVerifier.java:334)
  at boolean java.util.jar.JarVerifier.readCertificates() (JarVerifier.java:268)
  at void java.util.jar.StrictJarFile.<init>(java.lang.String) (StrictJarFile.java:86)
  at void libcore.io.ClassPathURLStreamHandler.<init>(java.lang.String) (ClassPathURLStreamHandler.java:57)
  at libcore.io.ClassPathURLStreamHandler[] java.lang.VMClassLoader.createBootClassPathUrlHandlers() (VMClassLoader.java:48)
  at void java.lang.VMClassLoader.<clinit>() (VMClassLoader.java:31)
  at java.lang.Class java.lang.ClassLoader.findLoadedClass(java.lang.String) (ClassLoader.java:373)
  at java.lang.Class java.lang.BootClassLoader.loadClass(java.lang.String, boolean) (ClassLoader.java:849)
  at java.lang.Class java.lang.ClassLoader.loadClass(java.lang.String) (ClassLoader.java:480)
  at java.lang.Class libcore.reflect.InternalNames.getClass(java.lang.ClassLoader, java.lang.String) (InternalNames.java:53)
  at java.lang.Class java.lang.Class.getDexCacheType(com.android.dex.Dex, int) (Class.java:521)
  at java.lang.Class java.lang.reflect.Method.getReturnType() (Method.java:173)
  at java.lang.reflect.Method[] java.lang.Class.getDeclaredMethods() (Class.java:717)
  at long org.moe.natj.objc.ObjCRuntime.registerClass(java.lang.Class) (ObjCRuntime.java:-2)
  at void org.moe.natj.objc.ObjCRuntime.doRegistration(java.lang.Class) (ObjCRuntime.java:73)
  at void org.moe.natj.general.NatJ.register() (NatJ.java:265)
  at void apple.NSObject.<clinit>() (NSObject.java:65)
Dumping all threads without appropriate locks held: thread list lock mutator lock
All threads:
DALVIK THREADS (6):
"main" prio=5 tid=1 Runnable
  | group="" sCount=0 dsCount=0 obj=0x202d50a0 self=0x7fd5fb810200
  | sysTid=3767070 nice=-1 cgrp=default sched=1/31 handle=0x9973000
  | state=? schedstat=( 0 0 0 ) utm=0 stm=0 core=0 HZ=100
  | stack=0x7fff5ea8e000-0x7fff5ea96000 stackSize=8MB
  | held mutexes= "abort lock" "mutator lock"(shared held)
  at org.moe.natj.objc.ObjCRuntime.registerClass(Native method)
  at org.moe.natj.objc.ObjCRuntime.doRegistration(ObjCRuntime.java:73)
  at org.moe.natj.general.NatJ.register(NatJ.java:265)
  at apple.NSObject.<clinit>(NSObject.java:65)
...

Dear gradle42,

could you please send us the project where we can reproduce this issue?

We tried to create a new project as you described:

  • New Single View Application project
  • Add compile ‘org.bouncycastle:bcpkix-jdk15on:1.55’
  • Additionally add repositories { jcenter() } to build.gradle

But Gradle won’t build it. (SHA-256 digest error for org/bouncycastle/LICENSE.class)

Turns out that the signed bouncy castle jars are the issue. For some reasons signing can’t be verified by the build process and if it is building it crashes at runtime. Repackaging bouncy castle jars did fix the issue.

  • In META-INF folder you need to remove both BCKEY.DSA and BCKEY.SF.
  • In MANIFEST.MF: Delete all the export and singing entries.

There might be more elegant way but this works. For Maven you can use the maven-shade-plugin, there might be a similar solution for gradle.

We face the same problem and managed to solve this by adding these code in build.gradle:

moeMainProGuard {
    doLast {
        def jar = getOutJar()
        def outputDir = file(jar.getAbsolutePath() + "_")
        copy{
            from(zipTree(jar)){
                exclude "META-INF/*.SF"
                exclude "META-INF/*.DSA"
                exclude "META-INF/*.RSA"
            }
            into outputDir
        }
        delete jar
        ant.jar(update: "true", index: "true", destfile: jar.getAbsolutePath()) {
            fileset(dir: outputDir)
        }
        delete outputDir
    }
}

basically is deleting certs during build.

1 Like

Thanks for sharing, I had the same issue!