Generate multiple so cases
Here stringfromjni and stringFromJNI11 are called One-lib and Two-lib respectively two so
PackageCom.test.ndkmoreso;Importandroid.support.v7.app.AppCompatActivity;ImportAndroid.os.Bundle;ImportAndroid.widget.TextView; Public classMainactivityextendsappcompatactivity {//used to load the ' Native-lib ' Library on application startup. Static{system.loadlibrary ("One-lib"); System.loadlibrary ("Two-lib"); } @Overrideprotected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate); Setcontentview (R.layout.activity_main); //Example of a call to a native methodTextView TV =(TextView) Findviewbyid (R.id.sample_text); Tv.settext (Stringfromjni ()+ "both" +stringFromJNI11 ()); } /*** A Native method that's implemented by the ' native-lib ' native library, * which are packaged with this appli cation. */ Public nativeString Stringfromjni (); Public nativeString stringFromJNI11 ();}
The directory structure of the CPP:
See 1 of CMakeLists.txt files directly
3.4. 1 ) #添加子目录, the Cmakelists.txtset (One_path ${cmake_current_source_dir}/src/main/cpp/one) set in the subdirectory will be called(two_ PATH ${cmake_current_source_dir}/src/main/cpp/) MESSAGE (STATUS "src DIR: ${cmake_current_source_ DIR} ") Message (status" One dir: ${one_path} ") Message (status" dir: ${two_path} ") Add_subdirectory (${one_ PATH}) add_subdirectory (${two_path})
Lib of one
2 of CMakeLists.txt files
3.4. 1 ) #生成so动态库ADD_LIBRARY (one-lib SHARED one.cpp) target_link_libraries (one-lib log)
One.cpp
#include <jni.h><string>extern"C" Jniexport jstring jnicalljava_com_test_ndkmoreso_mainactivity_stringfromjni ( *env, /* */ ) { std::string'Hello from C + + " ; return env->Newstringutf (Hello.c_str ());}
The Lib of the other
Viewing 3 of CMakeLists.txt files
3.4. 1 ) #生成so动态库ADD_LIBRARY (twin-lib SHARED two.cpp) target_link_libraries (double-lib log)
Two.cpp
#include <jni.h><string>extern"C" Jniexport jstring jnicalljava_com_test_ndkmoreso_mainactivity_stringfromjni11 ( *env, /*/) {std::string'Hello from C + + " ; return env->Newstringutf (Hello.c_str ());}
The resulting results are as follows
Android Studio CMake generates multiple so