【问题标题】:Android.mk NDK/JNI: Cannot link dependency .aarAndroid.mk NDK/JNI:无法链接依赖项 .aar
【发布时间】:2021-07-07 20:43:19
【问题描述】:

我正在为 Android 构建一个名为“rnmultithreading”的库,其中包含本机代码 (C++)。本机代码依赖于另一个名为“reanimated”的库,我将其包含在 C++ 代码中。

这两个库都不是通过 maven 分发的,而是安装在本地的。 reanimated 被打包为预构建的.aar。我也想这样做,除非绝对不可能。

现在我不想将 reanimated 编译到我的库中,从那时起用户无法升级 reanimated 而无需我重建我的库。

我正在处理所有这些in this PR,其中还包括Android.mk 文件。我不想在这里粘贴我所有构建文件的内容,因为那是很多行。但这里是这些文件的链接:

当我尝试使用 ./gradlew assembleDebug 构建这个东西时,我得到一个构建错误:

> Task :buildRnMultithreading FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':buildRnMultithreading'.
> Process 'command '/Users/mrousavy/Library/Android/sdk/ndk/21.1.6352462/ndk-build'' finished with non-zero exit value 2

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

Deprecated Gradle features were used in this build, making it incompatible with Gradle 7.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/6.7/userguide/command_line_interface.html#sec:command_line_warnings

BUILD FAILED in 1m 57s
12 actionable tasks: 6 executed, 6 up-to-date

上面几行,实际的链接器错误:

[x86_64] SharedLibrary  : librnmultithreading.so
make: Leaving directory '/Users/mrousavy/Projects/react-native-multithreading/android/src/main/JNI'
fcntl(): Bad file descriptor
./../cpp/cpp-adapter.cpp:23: error: undefined reference to 'mrousavy::multithreading::install(facebook::jsi::Runtime&, std::__ndk1::function<std::__ndk1::shared_ptr<reanimated::Scheduler> ()>, std::__ndk1::function<std::__ndk1::shared_ptr<reanimated::ErrorHandler> (std::__ndk1::shared_ptr<reanimated::Scheduler>)>)'
./../Common/MakeJSIRuntime.cpp:38: error: undefined reference to 'facebook::jsc::makeJSCRuntime()'
./../Common/RNMultithreadingInstaller.cpp:36: error: undefined reference to 'reanimated::RuntimeDecorator::decorateRuntime(facebook::jsi::Runtime&, std::__ndk1::basic_string<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char> >)'
./../Common/RNMultithreadingInstaller.cpp:55: error: undefined reference to 'reanimated::ShareableValue::adapt(facebook::jsi::Runtime&, facebook::jsi::Value const&, reanimated::RuntimeManager*, reanimated::ValueType)'
./../Common/RNMultithreadingInstaller.cpp:78: error: undefined reference to 'reanimated::ShareableValue::getValue(facebook::jsi::Runtime&)'
./../Common/RNMultithreadingInstaller.cpp:81: error: undefined reference to 'reanimated::ShareableValue::adapt(facebook::jsi::Runtime&, facebook::jsi::Value const&, reanimated::RuntimeManager*, reanimated::ValueType)'
./../Common/RNMultithreadingInstaller.cpp:65: error: undefined reference to 'reanimated::Scheduler::scheduleOnJS(std::__ndk1::function<void ()>)'
./../Common/RNMultithreadingInstaller.cpp:70: error: undefined reference to 'reanimated::Scheduler::scheduleOnJS(std::__ndk1::function<void ()>)'
./../Common/RNMultithreadingInstaller.cpp:66: error: undefined reference to 'reanimated::ShareableValue::getValue(facebook::jsi::Runtime&)'
clang++: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [/Users/mrousavy/Library/Android/sdk/ndk/21.1.6352462/build/core/build-binary.mk:725: /Users/mrousavy/Projects/react-native-multithreading/android/build/tmp/buildRnMultithreading/local/x86_64/librnmultithreading.so] Error 1
make: *** Waiting for unfinished jobs....
fcntl(): Bad file descriptor
make: Entering directory '/Users/mrousavy/Projects/react-native-multithreading/android/src/main/JNI'
[armeabi-v7a] SharedLibrary  : libreactnativejni.so
make: Leaving directory '/Users/mrousavy/Projects/react-native-multithreading/android/src/main/JNI'
fcntl(): Bad file descriptor

我正试图找出我出错的地方,因为它确实成功地从 .aar 中提取了 libreanimated.so:

有人知道这里出了什么问题吗?

【问题讨论】:

    标签: android c++ cmake android-ndk java-native-interface


    【解决方案1】:

    jnilibs 中的库不能用作构建依赖项。它们仅用于通过 JNI 直接加载。如果你想在你的原生代码中使用它们,你需要关注https://developer.android.com/studio/releases/gradle-plugin#4.1-prefab-publish

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-02-06
      • 1970-01-01
      • 1970-01-01
      • 2014-01-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多