skipping tutorial
skipping tutorial

Reputation: 11

How to generate Native header files from java files in Android Studio

I am trying to learn Android Native programming , but i cannot use the Javac -h to generate header files from java source files .

javac -h "destination path desired for header files" then i add Java source file

BUT i keep getting errors saying : androidx... package does not exist .

after searching i found that my $CLASSPATH is empty. so i added -cp option and specified class path for android.jar , That resolved the android.os missing package . But i cannot find the class path for jetpack package including androidx , i found that Gradle.build dependencies import the package from Maven repository . So i really dont know what should i do . Thank you for your help

Upvotes: 0

Views: 659

Answers (1)

skipping tutorial
skipping tutorial

Reputation: 11

so i found out a solution , i dont know if its the typical solution or it should be done in another way , So basically i created a new java class containing only the native methods, without any other java methods / classes or imports . then i use the Javac -h on that newly created class . and it worked.Example:

public class native_methods_loader
{
  public native int nativeMethod();
}

then javac -h "jni folder path" ../native_methods_loader.java

so this works and creates a header file named : com_programming_learn_native_methods_loader.h with a native method prototype called

JNIEXPORT jint JNICALL Java_com_programming_learn_native_1class_1loader_nativeMethod
  (JNIEnv *, jobject)

Upvotes: 1

Related Questions