我试图让C++代码与react-native
一起工作(有关一般步骤,请参阅this)。包含用于与JNI交互的gradle生成的头文件目录
我使用react-native init
生成了我的项目,使用Djinni生成了JNI绑定。我现在试图构建应用程序并在我的android模拟器上测试它(cd $PROJECT_ROOT/android && ./gradlew installDebug
)。好像都找不到头文件,不包含他们的目录:
> ./gradlew installDebug
(...)
:app:compileDebugJavaWithJavac UP-TO-DATE
:app:compileDebugNdk
Warning: Deprecated NDK integration enabled by useDeprecatedNdk flag in gradle.properties will be removed from Android Gradle plugin soon.
Consider using CMake or ndk-build integration with the stable Android Gradle plugin:
https://developer.android.com/studio/projects/add-native-code.html
or use the experimental plugin:
http://tools.android.com/tech-docs/new-build-system/gradle-experimental.
In file included from $PROJECT_ROOT/android/app/src/main/jni/NativeCppBridgeText.cpp:4:
$PROJECT_ROOT/android/app/src/main/jni/NativeCppBridgeText.hpp:6:10: fatal error: 'cpp_bridge_text.hpp' file not found
#include "cpp_bridge_text.hpp"
^~~~~~~~~~~~~~~~~~~~~
1 error generated.
make: *** [$PROJECT_ROOT/android/app/build/intermediates/ndk/debug/obj/local/armeabi-v7a/objs/app/$PROJECT_ROOT/android/app/src/main/jni/NativeCppBridgeText.o] Error 1
:app:compileDebugNdk FAILED
FAILURE: Build failed with an exception.
我设法通过创建硬链接导致问题的头,让过去这个小问题。这导致我:
> ./gradlew installDebug
(...)
:app:compileDebugJavaWithJavac UP-TO-DATE
:app:compileDebugNdk
Warning: Deprecated NDK integration enabled by useDeprecatedNdk flag in gradle.properties will be removed from Android Gradle plugin soon.
Consider using CMake or ndk-build integration with the stable Android Gradle plugin:
https://developer.android.com/studio/projects/add-native-code.html
or use the experimental plugin:
http://tools.android.com/tech-docs/new-build-system/gradle-experimental.
In file included from $PROJECT_ROOT/android/app/src/main/jni/NativeCppBridgeText.cpp:4:
In file included from $PROJECT_ROOT/android/app/src/main/jni/NativeCppBridgeText.hpp:7:
$PROJECT_ROOT/app/src/main/jni/djinni_support.hpp:20:10: fatal error: 'exception' file not found
#include <exception>
^~~~~~~~~~~
1 error generated.
make: *** [$PROJECT_ROOT/android/app/build/intermediates/ndk/debug/obj/local/armeabi-v7a/objs/app/$PROJECT_ROOT/android/app/src/main/jni/NativeCppBridgeText.o] Error 1
:app:compileDebugNdk FAILED
FAILURE: Build failed with an exception.
在这种情况下,似乎甚至标准库不包括在内。
我的问题是:如何明确指定gradle
将目录添加到其搜索/ indlude路径?
在常规的Android项目中,似乎您可以编辑Android.mk/Application.mk文件。我的文件夹中没有这些文件;我认为gradle
实际上生成一个Android.mk文件(在$PROJECT_ROOT/android/app/build/intermediates/ndk/debug/Android.mk
),我试着编辑它(LOCAL_C_INCLUDES
字段)来添加我的目录,但是当我尝试另一个生成时它会被覆盖。
在此先感谢。