React Native with JNI & C文章阅读笔记
链接: https://thebhwgroup.com/blog/react-native-jni
对应的演示代码: https://github.com/rdixonbhw/ReactNative-JNI-Blog
我按照这个react jni入门教程做相关操作,由于版本升级,需要做一些修改,下面就是一些记录;
- 可以通过在local.properties中添加来指定使用的cmake ,形如
cmake.dir=C:/android-sdk_r24.4.1-windows/cmake/3.10.2.4988404 - cmake的配置参考
https://developer.android.com/studio/projects/configure-cmake
具体到上面这个文章中的例子则修改
android/app/src/mian/CMakeLists.txt为:
cmake_minimum_required(VERSION 3.10.2) # Set compiler flags set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -frtti -fexceptions -std=c++14 -Wno-deprecated-declarations -Wno-reorder -Wno-invalid-offsetof -fPIC") # Add source files to be compliled here # Path is relative to this CMakeLists.txt file set(SOURCE_FILES ./jni/hello_world.c ) add_library( # Specifies the name of the library. hello_world_jni # Sets the library as a shared library. SHARED # Provides a relative path to your source file(s). ${SOURCE_FILES} )
- Gradle的配置参考
https://developer.android.com/studio/projects/gradle-external-native-builds
具体到上面这个文章中的例子则修改
android/app/build.gradle
在defaultConfig 节点之中添加 ndk { abiFilters "armeabi-v7a", "x86" moduleName "hello_world_jni" ldLibs "log" cFlags "-std=c99" } buildTypes节点的同级之下添加 sourceSets { main { jni.srcDirs = ['src/main/jni/'] } } externalNativeBuild { cmake { path "src/main/CMakeLists.txt" } }
- gradle.properties最后的android.useDeprecatedNdk=true去掉
- 还需要注意的是hello_world.c中的函数名中的包名部分要和你自己例子工程中HelloWorlModule.java的包名对应上;
- 另外一个修改MyReactPackage的createJSModules之上的@Override在新版本里不再需要;
- 在MainApplication的getPackages()函数中添加packages.add(new MyReactPackage());
参考:
[APP闪退分析及Crash日志获取(PC端Log打印)](https://blog.csdn.net/u013110200/article/details/92767776)
[Android 发出警告 android.useDeprecatedNdk 不在被支持](https://www.jianshu.com/p/34b5702d3927)
[Just remove the @Override Annotation of createJSModules() and it will work for both!](https://stackoverflow.com/questions/45584887/react-native-0-47-removed-createjsmodules-method-retrocompatibility)
- 点赞
- 收藏
- 关注作者
评论(0)