1

I'm trying to use chilkat library on an existing app that uses API 16 under Android Studio (macOS - Android Studio 3.5). Needs suggestions about how to correctly import the chilkat library in Android Studio.

I need to determine if the library can be used with the application (about some SFTP operations).

Following the instructions found on the Chilkat site (https://www.chilkatsoft.com/chilkatAndroid.asp) I was able to compile the app including the library. However, in order to compile the app I had to add the Multidex support in the gradle build for the app :

........ ........ android { compileSdkVersion 28 buildToolsVersion '27.0.3' defaultConfig { minSdkVersion 16 targetSdkVersion 16 versionCode 72 versionName '1.6.6' multiDexEnabled true <------- added } dexOptions { javaMaxHeapSize "4g" } ......... ......... dependencies { ....... ....... implementation 'com.android.support:multidex:1.0.3' <---- added }

And the "project structure" of the app is different from the one described in the instructions so I did end up copying the libs files in a jniLibs directory under the /app directory on the project. The source files were copied into : /app/src/main/java/com/chilatsoft

On the main application I did included the lib as suggested by the instruction and added the loader.

In the end I am able to compile the app with no errors, however runtime the app crash indicating that the chilkat library is not found.

java.lang.UnsatisfiedLinkError: Couldn't load chilkat from loader dalvik.system.PathClassLoader[DexPathList[[zip file "/system/framework/com.symbol.emdk.jar", zip file "/data/app/com.xxxxxxxxxxx.apk"],nativeLibraryDirectories=[/data/app-lib/com.xxxxxxxxxxx, /vendor/lib, /system/lib]]]: findLibrary returned null at java.lang.Runtime.loadLibrary(Runtime.java:358)

This make me think I did imported the library not correctly. Any hint/step guide to follow to import chilkat correctly ?

Before to buy the license I would like to be sure that the library can be used for the project. I can't change API or restart from scratch or change structure of the current app.

Thanks for any help ! Steve

thefwguy
  • 85
  • 1
  • 11

2 Answers2

0

When your app loads a JNI .so share lib like this:

static 
    {
    System.loadLibrary("chilkat");
    }

The Java runtime loader is looking in some list of directories for libchilkat.so

The error message seems to show the list of directories where it's looking:

alvik.system.PathClassLoader[DexPathList[[zip file "/system/framework
/com.symbol.emdk.jar", zip file "/data/app/com.xxxxxxxxxxx.apk"],
nativeLibraryDirectories=[/data/app-lib/com.xxxxxxxxxxx, 
/vendor/lib, /system/lib]]]: findLibrary returned null at
 java.lang.Runtime.loadLibrary(Runtime.java:358)

The directories are:

/data/app-lib/com.xxxxxxxxxxx

/vendor/lib

/system/lib

And the libchilkat.so is not in any of them. The libchilkat.so is located in a directory within your project's directory tree. One solution is to move the libchilkat.so to one of those directories. Another solution is to (somehow) add the directory where the libchilkat.so exists to the list of directories searched.

Another possible solution is to explicitly load the .so. Instead of calling System.loadLibrary("chilkat") where you leave it up to the system to locate the libchilkat.so, call System.load instead of System.loadLibrary. (See https://www.chilkatsoft.com/java-loadLibrary-Linux.asp) But this might be difficult because the .so to be loaded depends on the runtime architecture (armeabi-v7a, x86_64, etc.)

Chilkat Software
  • 1,405
  • 1
  • 9
  • 8
  • The directories mentioned are in the device, so I need to find a way to have the system to bring them in the apk. On the project they are located at project_root/app/jniLibs and the jniLibs dir has 4 architectures (arm64-b8a/armeabi-v7a, x86 and x86_64. My guess is that location is wrong, i.e. the system is not putting the.so on the correct place in the device. The original instructions indicated other places but the project is configured differently. Thanks for the answer, I'm trying to see if I can include them. – thefwguy Aug 26 '19 at 14:17
  • Could it be the use of multidex to screw up the library location ? Before to use chilkat the project didn't use multidex. Adding the library the code was not compiling unless enabling multidex. – thefwguy Aug 26 '19 at 14:28
  • Uhm ok, it seems I found something. I did move the directory jniLibs (that contains the 4 architectures for the chilkat lib) on the same level of the res/assets/java directory (in my case project_root/app/src/main/jniLibs). Now the lib is loaded correctly (i.e. present in the apk file). But now the code crash for other reasons :( Sigh ... it seems chilkat interfere with the logger (slf4j). I'll open another thread eventually. Thanks for the answer ! – thefwguy Aug 26 '19 at 15:01
0

For starters, you need to install and configure the android ndk

Android developers ndk documentation

Then you need to include the appropriate .so files

load .so files in android

Finally, you need to load the native code with

static 
    {
    System.loadLibrary("chilkat");
    }

Once that is done you can continue with the tutorials

Official chilkat tutorial examples

Shay Ribera
  • 359
  • 4
  • 18