我試圖讓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
字段)來添加我的目錄,但是當我嘗試另一個生成時它會被覆蓋。
在此先感謝。