Android Studio CMake generates multiple so

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.