引入第三方so库
来源:互联网 发布:淘宝联盟客户端下载 编辑:程序博客网 时间:2024/06/05 04:02
1.生成so库
2.把生成的so库复制到项目libs目录文件夹
3.修改项目build.gradle文件
android { compileSdkVersion 26 buildToolsVersion "26.0.1" defaultConfig { applicationId "com.example.administrator.aslibtest1" minSdkVersion 15 targetSdkVersion 26 versionCode 1 versionName "1.0" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" externalNativeBuild { cmake { cppFlags "-frtti -fexceptions" } } //如果需要指定开发平台 如: /*ndk { abiFilters "armeabi","x86" }*/ } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } externalNativeBuild { cmake { path "CMakeLists.txt" } } // 引入第三方库,在app.gralde中的android目录下 sourceSets.main { jniLibs.srcDirs = ['libs'] jni.srcDirs = [] }}4.修改CMakeLists.txt
# For more information about using CMake with Android Studio, read the# documentation: https://d.android.com/studio/projects/add-native-code.html# Sets the minimum version of CMake required to build the native library.cmake_minimum_required(VERSION 3.4.1)find_library( # Sets the name of the path variable. log-lib log )#设置so库路径set(my_lib_path ${CMAKE_SOURCE_DIR}/libs)#讲第三方库作为动态库引用add_library( native-lib SHARED IMPORTED )#指名第三方库的绝对路径set_target_properties( native-lib PROPERTIES IMPORTED_LOCATION ${my_lib_path}/${ANDROID_ABI}/libnative-lib.so )add_library( # Sets the name of the library. libTest SHARED src/main/cpp/native-lib.c )target_link_libraries( # Specifies the target library. libTest native-lib ${log-lib} )5.添加头文件
6.触发JNI调用
public class MainActivity extends AppCompatActivity { // Used to load the 'native-lib' library on application startup. static { System.loadLibrary("native-lib"); System.loadLibrary("libTest"); } @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); // Example of a call to a native method TextView tv = (TextView) findViewById(R.id.sample_text); tv.setText(""+stringFromJNI(99,66));//165 } /** * A native method that is implemented by the 'native-lib' native library, * which is packaged with this application. */ public native int stringFromJNI(int a,int b);}
阅读全文
0 0
- 引入第三方so库
- 引入第三方库
- Swift引入第三方库
- Angular引入第三方库
- Android.mk引入第三方jar包和so库文件
- ios开发引入第三方库
- android studio 引入第三方库
- Android Studio 引入第三方库
- android studio 引入第三方库
- NDK build 引入第三方动态库
- Laravel引入第三方库的方法
- ios 手动引入第三方库
- egret如何引入puremvc第三方库
- React Native引入第三方库
- iOS引入第三方库姿势
- Android Studio 引入第三方库
- Angular引入第三方库--问题解决方法
- linux 添加第三方库 .so
- 干货整理及PPT下载福利 2017(上海)人工智能产品经理大会
- 郁闷呐~~~
- SSH1和SSH2的区别
- JQUERY-EASYUI的理解
- ssh 免密登陆
- 引入第三方so库
- New与newInstance关系
- 依赖属性Dependency Property
- [NOIP模拟][好题]Problem
- Java注释@interface的用法
- IOC底层实现原理
- Mac本地集群上传文件可能出现的问题及解决方法
- 【Unity3d】在Unity3d中使用百度AI人脸识别功能
- 关于service的一些小得