简体   繁体   中英

android ndk communicate different c++ project

I want to create a c++ project for android ndk.And I want to use it every project like dynamic library.I dont want to change /transport source code every time.I import *.so file and include it and use its class or whatever. This is possible.If it possible how could import and use it.

Or i create java project and i use it to communicate c++ project with using jni and i compile it.After that i have a *.jar file and i use it instead of android ndk.

Which one of them possible or effective.

I'm not entirely sure if I understood the question correctly, but I assume you prefer to write your Android applications using solely/mostly C++ and have a core library/module that you want to re-use for every consecutive project WITHOUT including that libraries SOURCE files in each consecutive project.

You can omit including the source files and include the final built .so file in your new project by adding the required libraries into your makefile. Like so:

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)
LOCAL_C_INCLUDES := (includes for libraryname)
LOCAL_MODULE := libraryname
LOCAL_SRC_FILES := libraryname.so
include $(PREBUILT_SHARED_LIBRARY)

include $(CLEAR_VARS)

--- instructions for custom application code here ---

LOCAL_SHARED_LIBRARIES := libraryname

Where "libraryname" is the name of the library module and "libraryname.so" is the name of the library file. Note the path should be relative to the make file. Below the second "include $(CLEAR_VARS)" and above the final "LOCAL_SHARED_LIBRARIES" you add the instructions for building the source code of the application which is to use the shared library.

Don't forget to load all libraries in order on the Java side, ie:

 System.loadLibrary( "libraryname" );
 System.loadLibrary( "customlib" );

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