JNI and javah on Android Studio 3.0 Canary 1


#1

Hi,

I’m currently porting my existing code to Kotlin and a large portion contains JNI calls. When I’m trying to run the code I’m getting the following error:

java.lang.UnsatisfiedLinkError: No implementation found for long com.company.project.Context.nativeContextCreate$project_debug() (tried Java_com_company_project_Context_nativeContextCreate_00024project_1debug and Java_com_company_project_Context_nativeContextCreate_00024project_1debug__)

This is a bit odd because it’s looking for a method that ends with $project_debug(). I thought that maybe re-generating the headers would fix this but I wasn’t able to use javah property. I followed this tutorial (https://github.com/fuzzdota/kotlin-jni-example) but I ended up with a “Cannot find class” error.

Is JNI supposed to be working property at this time with Android Studio 3.0 Canary 1 and, if so, does anyone knows the proper javah command to generate the headers from Kotlin classes ? Otherwise I’m thinking about moving all my native methods to a Java class, make them statics and invoke them from Kotlin classes.

Thanks


#2

Looks like the method is declared with internal visibility. It needs to be either public or private.

Other than that, JNI should work.


#3

Thanks, I’ll give it a try!