komputing / KEthereum

Kotlin library for Ethereum
MIT License
350 stars 73 forks source link

'generateWalletFile()' crash on Android #30

Closed klblk closed 6 years ago

klblk commented 6 years ago

Simple code:

val mnemonic = Mnemonic.generateMnemonic()
val password = "qweasdzxc"
val extendedKey = Mnemonic.mnemonicToKey(mnemonic, "m/44'/60'/0'/0", password)
val keyPair = extendedKey.keyPair;
keyPair.generateWalletFile(password, filesDir, LIGHT_SCRYPT_CONFIG)

Crash log:

java.lang.VerifyError: Rejecting class org.kethereum.wallet.model.KdfSerializer because it failed compile-time verification (declaration of 'org.kethereum.wallet.model.KdfSerializer' appears in /data/app/package.name-1/base.apk:classes3.dex)
        at org.kethereum.wallet.model.WalletCrypto.write$Self(Wallet.kt)
        at org.kethereum.wallet.model.WalletCrypto$$serializer.save(Wallet.kt)
        at org.kethereum.wallet.model.WalletCrypto$$serializer.save(Wallet.kt:15)
        at kotlinx.serialization.KOutput.writeSerializableValue(Serialization.kt:146)
        at kotlinx.serialization.KOutput.writeSerializableElementValue(Serialization.kt:191)
        at org.kethereum.wallet.model.Wallet.write$Self(Wallet.kt)
        at org.kethereum.wallet.model.Wallet$$serializer.save(Wallet.kt)
        at org.kethereum.wallet.model.Wallet$$serializer.save(Wallet.kt:53)
        at kotlinx.serialization.KOutput.write(Serialization.kt:99)
        at kotlinx.serialization.json.JSON.stringify(JSON.kt:40)
        at kotlinx.serialization.json.JSON$Companion.stringify(JSON.kt:57)
        at org.kethereum.wallet.WalletFileKt.generateWalletFile(WalletFile.kt:30)
ligi commented 6 years ago

I just tried exactly this code and get no crash but a generated file as expected - can you give some more context for this error?

klblk commented 6 years ago

Hmm, reproduced on Android 5.1 (api 22) and Android 6.0 (api 23). But not reproduced on Android 8.0 (api 26). Test on emulators.

test project testWallet.zip

ligi commented 6 years ago

OK can reproduce the problem now - works on emulator API 24 - crash on API 23

ligi commented 6 years ago

OK I found a workaround - but would still love to really understand the problem - hints welcome: https://stackoverflow.com/questions/50151499/verifyerror-rejecting-class-serializer