Android loading may fallback to standard JVM (#9)

* Android loading may fallback to standard JVM

* Java code must target JVM 1.8 in order to be compatible Android.

Co-authored-by: Salomon BRYS <salomon@kodein.net>
This commit is contained in:
Salomon BRYS
2020-07-16 22:21:30 +02:00
committed by GitHub
parent 0cc4c251f9
commit dbf8301f34
6 changed files with 51 additions and 26 deletions

View File

@@ -16,15 +16,20 @@
package fr.acinq.secp256k1
import java.lang.IllegalStateException
import java.util.*
internal actual fun getSecpk256k1(): Secp256k1 {
private fun tryLoad(platform: String): Secp256k1? {
try {
val cls = Class.forName("fr.acinq.secp256k1.jni.NativeSecp256k1Loader")
val cls = Class.forName("fr.acinq.secp256k1.jni.NativeSecp256k1${platform.capitalize(Locale.ROOT)}Loader")
val load = cls.getMethod("load")
return load.invoke(null) as Secp256k1
} catch (ex: ClassNotFoundException) {
throw IllegalStateException("Could not load native Secp256k1 JNI library. Have you added the JNI dependency?", ex)
return null
}
}
internal actual fun getSecpk256k1(): Secp256k1 =
tryLoad("android")
?: tryLoad("jvm")
?: error("Could not load native Secp256k1 JNI library. Have you added the JNI dependency?")