简体   繁体   English

Android NDK交流不同的C ++项目

[英]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. 我想为android ndk创建一个c ++项目,并且想要在每个项目(例如动态库)中使用它。我不想每次都更改/ transport源代码。我导入* .so文件并包含它并使用其类或其他内容。 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. 或者我创建一个Java项目,并使用jni与它通信以与c ++项目进行通信,然后对其进行编译。之后,我有了一个* .jar文件,并使用它而不是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. 我不确定我是否正确理解了这个问题,但是我认为您更愿意使用C ++编写您的Android应用程序,并且拥有一个核心库/模块,您想在每个不包含该库的后续项目中重复使用该库/模块每个连续项目中的SOURCE文件。

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. 通过将所需的库添加到makefile中,可以省略包含源文件,并在新项目中包含最终构建的.so文件。 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. 其中“ libraryname”是库模块的名称,而“ libraryname.so”是库文件的名称。 Note the path should be relative to the make file. 注意,该路径应相对于make文件。 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. 在第二个“ include $(CLEAR_VARS)”之下和最后一个“ LOCAL_SHARED_LIBRARIES”之下,您添加了用于构建将使用共享库的应用程序源代码的说明。

Don't forget to load all libraries in order on the Java side, ie: 不要忘记按顺序在Java端加载所有库,即:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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