Using SDK and JavaWrapper in Android Studio


#1

Hello everyone,

I’m trying to use the the Indy SDK for building an android app. Unfortunately I can’t get the Android Studio to install the app. My steps on a Windows 10 machine:

  1. download the libindy/stable/1.8.2/libindy_android_x86_1.8.2.zip from evernym (https://repo.sovrin.org/android/libindy/stable/1.8.2/)
  2. copying the libindy.so to app\src\main\jniLibs\x86
  3. adding to build.gradle
    maven {url 'https://repo.sovrin.org/repository/maven-public} and
    api ‘org.hyperledger:indy:1.8.1-dev-985’
  4. set compileOptions to Java 8 in build.gradle
  5. try to install the app on an x86 emulator, without using any wrapper class
  6. android studio tries to install the app for about 5min and nothing happens

What am I missing?


#2

After some more time wating the app got installed. I tried to open a pool from the onCreate() and got a NullPointerException. So I guess I did somethin wrong when installing the libindy.so?

Caused by: java.lang.NullPointerException: Attempt to invoke interface method ‘int org.hyperledger.indy.sdk.LibIndy$API.indy_open_pool_ledger(int, java.lang.String, java.lang.String, com.sun.jna.Callback)’ on a null object reference


#3

I think you may have better luck asking this type of question on Rocket Chat (chat.hyperledger.org, #indy-sdk). Internal developers tend to hang out more in that forum. Here, there are more people that work at a higher level in the stack.


#4

Hello Daniel, thanks :slight_smile:

I posted the question to chat.hyperledger, but I solved the issue meanwhile. I’ll keep an eye on the chat, maybe there is a better way to solve it.
For whose who face the same problem, here is what I did to get libindy 1.8.2 working in android:

  1. download the NDK16b from here:
    https://dl.google.com/android/repository/android-ndk-r16b-linux-x86_64.zip
    The readme.md for indy-sdk (https://github.com/hyperledger/indy-sdk) says, that NDK16b has been used for compiling the dependencies .

  2. extract the NDK and copy gnustl_shared.so into the appropriate JniLibs folder. It is located here:
    sources\cxx-stl\gnu-libstdc++\4.9\libs\x86

  3. download jna-5.2.0 from here and extract it
    https://github.com/java-native-access/jna

  4. in jna-5.2.0\lib\native there are some .jar - files for your plattform. Open the appropriate .jar and extract libjnidispatch.so from it. Copy libjnidispatch.so to the appropriate jniLibs subfolder.

  5. add implementation ‘net.java.dev.jna:jna:5.2.0’ to the dependencies of your app’s build.gradle. Without it I get the following error and the app doesnt launch.
    There is an incompatible JNA native library installed on this system
    Expected: 5.1.0
    Found: 6.0.0


#5

I had the same issue, but solved it by downloading the jar file from the lib files in the repository under the 5.2 tag

Would you mind sharing a piece of your graddle file? I am trying to add the maven repo into my android project but keep on getting the error

Could not resolve org.hyperledger:indy:1.8.1-dev-985

Even though I already set the repository as
maven { url ‘https://repo.sovrin.org/repository/maven-public’ }


#6

apply plugin: ‘com.android.application’

repositories {
maven { url ‘https://repo.sovrin.org/repository/maven-public’ }
}

android {
compileSdkVersion 28
defaultConfig {
applicationId “com.example.emutest”
minSdkVersion 24
targetSdkVersion 28
versionCode 1
versionName “1.0”
testInstrumentationRunner “android.support.test.runner.AndroidJUnitRunner”
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile(‘proguard-android-optimize.txt’), ‘proguard-rules.pro’
}
}

compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
}

}

dependencies {
implementation fileTree(dir: ‘libs’, include: [’*.jar’])
implementation ‘com.android.support:appcompat-v7:28.0.0’
implementation ‘com.android.support.constraint:constraint-layout:1.1.3’
testImplementation ‘junit:junit:4.12’
androidTestImplementation ‘com.android.support.test:runner:1.0.2’
androidTestImplementation ‘com.android.support.test.espresso:espresso-core:3.0.2’

api 'org.hyperledger:indy:1.8.1-dev-985'
implementation 'net.java.dev.jna:jna:5.2.0'
implementation 'org.apache.directory.studio:org.apache.commons.io:2.4'

}


#7

To resolve org.hyperledger:indy:1.8.1-dev-985 you need to add
maven { url ‘https://repo.sovrin.org/repository/maven-public’ }