简体   繁体   中英

Incorporate open source JniLibs into own android project

I have source code from a demo app that is involves some native coding. I'd like to integrate some part of that code into my own app.

This is how the code is structured:

app/
    java/
        com.demoUser/
            caffe_android_demo/
                MainActivity
            caffe_android_lib/
                CaffeMobile
    jniLibs/
        libcaffe_jni.so

Apparantly there are some parts in the native code which are specific towards the the app's package name, like in caffe_jni.cpp :

JNIEXPORT void JNICALL
Java_com_demoUser_caffe_1android_1lib_CaffeMobile_extractFeatures(
someArgs...) {
...
}

How can I refactor those names such that it can be called from my app com.myUsername ? Or is there another way to include code from another app in android studio?

The native code is invoking a java method demoMethodName() in your demoClassName Class. Make sure you have defined the method in your class.

For he second part You can change the function name following the below rules

Prepend Java_ to the function name.

Describe the filepath relative to the top-level source directory.

Use underscores in place of forward slashes.

Omit the .java file extension.

After the last underscore, append the function name.

In your case change the demoUser with your user name

JNIEXPORT void JNICALL
Java_com_myUsername_caffe_1android_1lib_CaffeMobile_extractFeatures(
someArgs...) {
   ...
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM