3

I'm trying to use the stellar sdk in an android app. So I downloaded the stellar sdk and generate it's jar and include it in as a external jar in my android app. To get it working I also had to add net.i2p.crypto as external jar. I went ahead to work with it but I notice a weird behaviour on emulator with KitKat (API 19) when I call

KeyPair.random()

Basically the app crashes randomly. That is first time I call KeyPair.random() it might not crash. Second time, it crashes, I'm forced restart the app and call KeyPair.random() for the third time, it crashes again. I retry again that is the fourth time, it does not crash and fifth time it crashes. This happens really randomly that is the order of crashes is not constant.

To reproduce this behaviour, you can create a simple android on android studio. In the build.gradle (app level) add this

buildscript {

    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.1.3'
        classpath "io.realm:realm-gradle-plugin:3.3.1"
        classpath 'com.google.gms:google-services:3.0.0'
        classpath 'com.novoda:bintray-release:0.8.0'


        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        google()
        jcenter()
        maven { url "https://jitpack.io" }
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

In the other build.gradle (project level)

apply plugin: 'com.android.application'

android {
    compileSdkVersion 27
    defaultConfig {
        applicationId "com.example.raymond.testkeypair"
        minSdkVersion 16
        targetSdkVersion 27
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        multiDexEnabled true
    }
    configurations.all {
        resolutionStrategy.force 'com.google.code.findbugs:jsr305:1.3.9'
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    configurations {
        all*.exclude group:'javax.inject', module:'javax.inject'
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    dexOptions {
        javaMaxHeapSize "1g"
    }
    lintOptions{
        disable 'RestrictedApi'
    }
}


dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:27.0.1'
    implementation 'com.android.support.constraint:constraint-layout:1.0.2'
    implementation files('libs/net.i2p.crypto-4.0.0.jar')
    implementation files('libs/stellar-sdk-1.0-SNAPSHOT.jar')
    implementation 'com.google.guava:guava:26.0-android'

}
allprojects {
    repositories {
        maven {
            url "https://jitpack.io"
        }
    }

}

In the MainActivity you just add

KeyPair.random();

When the app crash, the LogCat print this stack trace.

09-02 20:59:34.712 4458-4464/? E/dalvikvm: exceeds size of memVRTable
09-02 20:59:34.712 4458-4464/? E/dalvikvm: VM aborting
09-02 20:59:34.712 4458-4464/? A/libc: Fatal signal 6 (SIGABRT) at 0x0000116a (code=-6), thread 4464 (Compiler)
09-02 20:59:34.762 1173-1173/? I/DEBUG: *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
09-02 20:59:34.762 1173-1173/? I/DEBUG: Build fingerprint: 'generic_x86/google_sdk_x86/generic_x86:4.4.2/KK/4729339:eng/test-keys'
09-02 20:59:34.762 1173-1173/? I/DEBUG: Revision: '0'
09-02 20:59:34.762 1173-1173/? I/DEBUG: pid: 4458, tid: 4464, name: Compiler  >>> com.example.raymond.testkeypair <<<
09-02 20:59:34.762 1173-1173/? I/DEBUG: signal 6 (SIGABRT), code -6 (SI_TKILL), fault addr --------
09-02 20:59:34.852 1173-1173/? I/DEBUG:     eax 00000000  ebx 0000116a  ecx 00001170  edx 00000006
09-02 20:59:34.852 1173-1173/? I/DEBUG:     esi 00001170  edi 00000000
09-02 20:59:34.852 1173-1173/? I/DEBUG:     xcs 00000073  xds 0000007b  xes 0000007b  xfs 00000000  xss 0000007b
09-02 20:59:34.852 1173-1173/? I/DEBUG:     eip b768dc96  ebp b76f2ce0  esp 8c5255c0  flags 00200207
09-02 20:59:34.852 1173-1173/? I/DEBUG: backtrace:
09-02 20:59:34.852 1173-1173/? I/DEBUG:     #00  pc 0003bc96  /system/lib/libc.so (tgkill+22)
09-02 20:59:34.852 1173-1173/? I/DEBUG:     #01  pc 00000005  <unknown>
09-02 20:59:34.852 1173-1173/? I/DEBUG: stack:
09-02 20:59:34.852 1173-1173/? I/DEBUG:          8c525580  00000000  
09-02 20:59:34.852 1173-1173/? I/DEBUG:          8c525584  b76ee268  /system/lib/libc.so
09-02 20:59:34.852 1173-1173/? I/DEBUG:          8c525588  00000000  
09-02 20:59:34.852 1173-1173/? I/DEBUG:          8c52558c  b765fef9  /system/lib/libc.so (pthread_mutex_unlock+25)
09-02 20:59:34.852 1173-1173/? I/DEBUG:          8c525590  b76ee18c  /system/lib/libc.so
09-02 20:59:34.852 1173-1173/? I/DEBUG:          8c525594  b7e20170  [heap]
09-02 20:59:34.852 1173-1173/? I/DEBUG:          8c525598  00000015  
09-02 20:59:34.852 1173-1173/? I/DEBUG:          8c52559c  8c5255e4  [stack:4464]
09-02 20:59:34.852 1173-1173/? I/DEBUG:          8c5255a0  00000000  
09-02 20:59:34.852 1173-1173/? I/DEBUG:          8c5255a4  b76ac656  /system/lib/libc.so (funlockfile+6)
09-02 20:59:34.852 1173-1173/? I/DEBUG:          8c5255a8  b76edfcc  /system/lib/libc.so
09-02 20:59:34.852 1173-1173/? I/DEBUG:          8c5255ac  b7697c76  /system/lib/libc.so (__sflush_locked+150)
09-02 20:59:34.852 1173-1173/? I/DEBUG:          8c5255b0  00000000  
09-02 20:59:34.852 1173-1173/? I/DEBUG:          8c5255b4  00000000  
09-02 20:59:34.852 1173-1173/? I/DEBUG:          8c5255b8  b765fd29  /system/lib/libc.so (pthread_mutex_lock+9)
09-02 20:59:34.852 1173-1173/? I/DEBUG:          8c5255bc  b76edfcc  /system/lib/libc.so
09-02 20:59:34.852 1173-1173/? I/DEBUG:     #00  8c5255c0  00000006  
09-02 20:59:34.852 1173-1173/? I/DEBUG:          8c5255c4  00001170  
09-02 20:59:34.852 1173-1173/? I/DEBUG:          8c5255c8  b76edfcc  /system/lib/libc.so
09-02 20:59:34.852 1173-1173/? I/DEBUG:          8c5255cc  b766a436  /system/lib/libc.so (pthread_kill+102)
09-02 20:59:34.852 1173-1173/? I/DEBUG:          8c5255d0  0000116a  
09-02 20:59:34.852 1173-1173/? I/DEBUG:          8c5255d4  00001170  
09-02 20:59:34.852 1173-1173/? I/DEBUG:          8c5255d8  00000006  
09-02 20:59:34.852 1173-1173/? I/DEBUG:          8c5255dc  00000000  
09-02 20:59:34.852 1173-1173/? I/DEBUG:          8c5255e0  b76ee268  /system/lib/libc.so
09-02 20:59:34.852 1173-1173/? I/DEBUG:          8c5255e4  00000002  
09-02 20:59:34.852 1173-1173/? I/DEBUG:          8c5255e8  b766a3d9  /system/lib/libc.so (pthread_kill+9)
09-02 20:59:34.852 1173-1173/? I/DEBUG:          8c5255ec  b76edfcc  /system/lib/libc.so
09-02 20:59:34.852 1173-1173/? I/DEBUG:          8c5255f0  8c52563c  [stack:4464]
09-02 20:59:34.852 1173-1173/? I/DEBUG:          8c5255f4  8c52587c  [stack:4464]
09-02 20:59:34.852 1173-1173/? I/DEBUG:          8c5255f8  000000a8  
09-02 20:59:34.852 1173-1173/? I/DEBUG:          8c5255fc  b766a7fc  /system/lib/libc.so (raise+44)
09-02 20:59:34.882 1615-1637/? I/BootReceiver: Copying /data/tombstones/tombstone_03 to DropBox (SYSTEM_TOMBSTONE)
09-02 20:59:34.882 1175-2943/? D/gralloc_ranchu: gralloc_alloc: Creating ashmem region of size 1323008
09-02 20:59:34.882 1176-1176/? D/Zygote: Process 4458 terminated by signal (6)
09-02 20:59:34.882 1615-1653/? W/InputDispatcher: channel '9d42d7a0 com.example.raymond.testkeypair/com.example.raymond.testkeypair.MainActivity (server)' ~ Consumer closed input channel or an error occurred.  events=0x9
09-02 20:59:34.882 1615-1653/? E/InputDispatcher: channel '9d42d7a0 com.example.raymond.testkeypair/com.example.raymond.testkeypair.MainActivity (server)' ~ Channel is unrecoverably broken and will be disposed!

                                              [ 09-02 20:59:34.882  1615: 4485 D/         ]
                                              HostConnection::get() New Host Connection established 0xb81546b0, tid 4485
09-02 20:59:34.882 1615-4485/? W/ActivityManager:   Force finishing activity com.example.raymond.testkeypair/.MainActivity

                                              [ 09-02 20:59:34.892  1615: 4485 W/         ]
                                              Unrecognized GLES max version string in extensions: ANDROID_EMU_CHECKSUM_HELPER_v1 
09-02 20:59:34.902 1615-4485/? D/dalvikvm: GC_FOR_ALLOC freed 1672K, 25% free 12903K/17128K, paused 7ms, total 7ms
09-02 20:59:34.902 1615-2491/? W/InputDispatcher: Attempted to unregister already unregistered input channel '9d42d7a0 com.example.raymond.testkeypair/com.example.raymond.testkeypair.MainActivity (server)'
09-02 20:59:34.902 1615-2491/? I/WindowState: WIN DEATH: Window{9d42d7a0 u0 com.example.raymond.testkeypair/com.example.raymond.testkeypair.MainActivity}
09-02 20:59:34.902 1615-4485/? W/ActivityManager: Exception thrown during pause
                                              android.os.DeadObjectException
                                                  at android.os.BinderProxy.transact(Native Method)
                                                  at android.app.ApplicationThreadProxy.schedulePauseActivity(ApplicationThreadNative.java:660)
                                                  at com.android.server.am.ActivityStack.startPausingLocked(ActivityStack.java:761)
                                                  at com.android.server.am.ActivityStack.finishActivityLocked(ActivityStack.java:2455)
                                                  at com.android.server.am.ActivityStack.finishTopRunningActivityLocked(ActivityStack.java:2329)
                                                  at com.android.server.am.ActivityStackSupervisor.finishTopRunningActivityLocked(ActivityStackSupervisor.java:2035)
                                                  at com.android.server.am.ActivityManagerService.handleAppCrashLocked(ActivityManagerService.java:9543)
                                                  at com.android.server.am.ActivityManagerService.makeAppCrashingLocked(ActivityManagerService.java:9436)
                                                  at com.android.server.am.ActivityManagerService.crashApplication(ActivityManagerService.java:10081)
                                                  at com.android.server.am.ActivityManagerService.handleApplicationCrashInner(ActivityManagerService.java:9632)
                                                  at com.android.server.am.NativeCrashListener$NativeCrashReporter.run(NativeCrashListener.java:86)
09-02 20:59:34.902 1615-1844/? I/ActivityManager: Process com.example.raymond.testkeypair (pid 4458) has died.

Any clue? Thanks.

0

DeadObjectException is a side-effect of some other failure. Can you debug the root cause by placing a try-catch-log block around KeyPair.random?

Aside #1: The implementation of KeyPair.random is entirely dependent on the net.i2p.crypto library, so you may be able to cut down the dependencies required to reproduce this.

Aside #2: A recent pull request to the Java SDK proposes to remove the custom library in favour of the official one, so you can test with just net.i2p.crypto:eddsa:jar:0.3.0

  • thanks for the reply, I surrounded random() with a try-catch-log block but I don't have any additional log. Remember that DeadObjectException is generated from the ActivityManager. Also KeyPair is part of the stellar sdk which is generated by calling api of net.i2p.crypto – berrytchaks Sep 3 '18 at 13:16
  • Can you try debugging with a breakpoint inside the catch block? The KeyPair constructor is four calls into the eddsa library: new KeyPairGenerator(), .generateKeyPair(), (EdDSAPublicKey) keypair.getPublic() and (EdDSAPrivateKey) keypair.getPrivate() .Remove the Stellar SDK and call these directly, adding one at a time, to see which call, if any, causes the failure. – Synesso Sep 3 '18 at 21:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.