wallet-core: JNI crash in wallet.core.jni.HDWallet.mnemonic()

Describe the bug Google playstore test center triggers JNI crash on some devices.

JNI DETECTED ERROR IN APPLICATION: fid == null
  in call to GetLongField
  from java.lang.String wallet.core.jni.HDWallet.mnemonic()

Calling code is Kotlin

fun createWallet(@NonNull input: HDWallet.CreateWalletInput, @NonNull result: Result) {
  val wallet = wallet.core.jni.HDWallet(input.strength, input.passphrase)
  val value = wallet.mnemonic()
  return GeneralImpl.sendResult(GeneralImpl.stringValue(value), result)
}

We use the published lib “implementation ‘com.trustwallet:wallet-core:2.0.12’”.

To Reproduce I was unable to reproduce this locally yet. Error is reported by automated tester system at google only.

Expected behavior Dont crash in JNI

Additional context logcat section cutout

05-18 05:35:09.310: A/art(10039): art/runtime/runtime.cc:427] JNI DETECTED ERROR IN APPLICATION: fid == null
05-18 05:35:09.310: A/art(10039): art/runtime/runtime.cc:427]     in call to GetLongField
05-18 05:35:09.310: A/art(10039): art/runtime/runtime.cc:427]     from java.lang.String wallet.core.jni.HDWallet.mnemonic()
05-18 05:35:09.310: A/art(10039): art/runtime/runtime.cc:427] "main" prio=5 tid=1 Runnable
05-18 05:35:09.310: A/art(10039): art/runtime/runtime.cc:427]   | group="main" sCount=0 dsCount=0 obj=0x7534da88 self=0x75dc095a00
05-18 05:35:09.310: A/art(10039): art/runtime/runtime.cc:427]   | sysTid=10039 nice=-4 cgrp=default sched=0/0 handle=0x75dff1da98
05-18 05:35:09.310: A/art(10039): art/runtime/runtime.cc:427]   | state=R schedstat=( 796894167 312348491 2679 ) utm=61 stm=17 core=3 HZ=100
05-18 05:35:09.310: A/art(10039): art/runtime/runtime.cc:427]   | stack=0x7fecfb3000-0x7fecfb5000 stackSize=8MB
05-18 05:35:09.310: A/art(10039): art/runtime/runtime.cc:427]   | held mutexes= "mutator lock"(shared held)
05-18 05:35:09.310: A/art(10039): art/runtime/runtime.cc:427]   native: #00 pc 000000000047ae90  /system/lib64/libart.so (_ZN3art15DumpNativeStackERNSt3__113basic_ostreamIcNS0_11char_traitsIcEEEEiP12BacktraceMapPKcPNS_9ArtMethodEPv+220)
05-18 05:35:09.310: A/art(10039): art/runtime/runtime.cc:427]   native: #01 pc 000000000047ae8c  /system/lib64/libart.so (_ZN3art15DumpNativeStackERNSt3__113basic_ostreamIcNS0_11char_traitsIcEEEEiP12BacktraceMapPKcPNS_9ArtMethodEPv+216)
05-18 05:35:09.310: A/art(10039): art/runtime/runtime.cc:427]   native: #02 pc 000000000044f3bc  /system/lib64/libart.so (_ZNK3art6Thread9DumpStackERNSt3__113basic_ostreamIcNS1_11char_traitsIcEEEEbP12BacktraceMap+472)
05-18 05:35:09.310: A/art(10039): art/runtime/runtime.cc:427]   native: #03 pc 00000000002eeacc  /system/lib64/libart.so (_ZN3art9JavaVMExt8JniAbortEPKcS2_+1128)
05-18 05:35:09.310: A/art(10039): art/runtime/runtime.cc:427]   native: #06 pc 00000000004649cc  /data/app/com.heatwallet.heat_wallet-1/split_config.arm64_v8a.apk (???)
05-18 05:35:09.310: A/art(10039): art/runtime/runtime.cc:427]   native: #07 pc 0000000000014160  /data/app/com.heatwallet.heat_wallet-1/oat/arm64/base.odex (Java_wallet_core_jni_HDWallet_mnemonic__+124)
05-18 05:35:09.310: A/art(10039): art/runtime/runtime.cc:427]   at wallet.core.jni.HDWallet.mnemonic(Native method)
05-18 05:35:09.310: A/art(10039): art/runtime/runtime.cc:427]   at com.heatwallet.heat_wallet.e$a.a(:-1)
05-18 05:35:09.310: A/art(10039): art/runtime/runtime.cc:427]   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:889)

Note that not all tested devices trigger these crashes.

Screenshot 2020-05-18 at 16 46 33

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 19 (5 by maintainers)

Most upvoted comments

I was able to solve this. The problem was with R8 messing up the JNI code. For any flutter developers hitting this issue while using wallet-core. Either disable R8 completely.

flutter build appbundle --release --no-shrink

Or better fine tune R8 to keep wallet-core JNI code intact.

or join https://t.me/trust_developers

<div>Telegram</div><div>Trust Developers - Public</div><div>Public discussion for Trust Developers. Documentation available: developer.trustwallet.com Add new blockchain: developer.trustwallet.com/wallet-core/newblockchain</div>