Cannot use .so files in Android Studio

1,472 views
Skip to first unread message

Fight Forge

unread,
Feb 17, 2017, 1:47:21 PM2/17/17
to android-ndk
Hi,
i'm trying to use this library https://github.com/DemonGiggle/android-udt in android studio. If i enter in jni folder and run ndk-build all is done and i see libs folder with architecture and .so files.
After that i try to add this .so files to Android Studio in this way:
1 - make folder jniLibs in src/main subfolder of my project
2 - copy all .so (with armeabi.... directory structure) in jniLibs

Ok but, now if i go in my MainActivity files i cannot write code like this:

try{

SocketUDT ns = new SocketUDT(TypoUDT.DATAGRAM);

...
}catch{...}

I cannot use SocketUDT, Android Studio give me error and i cannot use the library functions.

Where i'm doing wrong?


thanks

Gerry Fan

unread,
Mar 24, 2017, 4:19:05 PM3/24/17
to android-ndk
no, you could not use it this way.  you are using are third-party lib, got to tell your application that you have it somewhere in your build scripts ( either cmake or ndk-build scripts )
maybe check for this one see if it could help:

you did one step, need another step to import your-just-built libs into your project. it will work

Alex Cohn

unread,
Mar 30, 2017, 4:39:08 AM3/30/17
to android-ndk
See the example at https://github.com/DemonGiggle/android-udt/blob/master/src/com/udt/udt.java. It does not use SocketUDT class and does not connect directly to https://github.com/DemonGiggle/android-udt/blob/master/jni/lib/api.h. Instead, Java uses a JNI wrapper declared in https://github.com/DemonGiggle/android-udt/blob/master/jni/com_udt_udt.h.

Unfortunately, JNI binding Java to C++ is not "class" based, but is "old C" style, defining C functions for each native Java method you declare in your class.

The full name of the Java class that defines native methods should be com.udt.udt: this is hardcoded in C function names in com_udt_udt.h file. You can declare these methods pubic and use them from any class in your Android app. The good practice is to declare native methods private and wrap each of them with a public Java wrapper. This makes it easier to handle parameter validation, logging, etc.

BR,
Alex Cohn
Reply all
Reply to author
Forward
0 new messages