大佬教程收集整理的这篇文章主要介绍了在 android 中使用 cpp 和 java 时,任务 ':app:externalNativeBuildDebug' 执行失败,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
使用 jni 将 c++ 链接到 java 时,我的 androID studio 项目无法构建此错误
Build command Failed.
Error while execuTing process C:\Users\conno\ApPDAta\Local\AndroID\Sdk\cmake\3.10.2.4988404\bin\ninja.exe with arguments {-C D:\Connor\DMA\Pipes\AndroID\smart_Pipes\app\.cxx\cmake\deBUG\arm64-v8a native-lib}
ninja: Entering directory `D:\Connor\DMA\Pipes\AndroID\smart_Pipes\app\.cxx\cmake\deBUG\arm64-v8a'
[1/1] linking CXX shared library D:\Connor\DMA\Pipes\AndroID\smart_Pipes\app\build\intermediates\cmake\deBUG\obj\arm64-v8a\libnative-lib.so
Failed: D:/Connor/DMA/Pipes/AndroID/smart_Pipes/app/build/intermediates/cmake/deBUG/obj/arm64-v8a/libnative-lib.so
cmd.exe /C "cd . && C:\Users\conno\ApPDAta\Local\AndroID\Sdk\ndk\21.4.7075529\toolchains\llvm\prebuilt\windows-x86_64\bin\clang++.exe --target=aarch64-none-linux-androID21 --gcc-toolchain=C:/Users/conno/ApPDAta/Local/AndroID/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/windows-x86_64 --sysroot=C:/Users/conno/ApPDAta/Local/AndroID/Sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/windows-x86_64/sysroot -fPIC -g -DANDROID -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -D_FORTIFY_sourcE=2 -Wformat -Werror=format-security -O0 -fno-limit-deBUG-info -Wl,--exclude-libs,libgcc.a -Wl,libgcc_real.a -Wl,libatomic.a -static-libstdc++ -Wl,--build-ID -Wl,--fatal-warnings -Wl,--no-undefined -Qunused-arguments -shared -Wl,-soname,libnative-lib.so -o D:\Connor\DMA\Pipes\AndroID\smart_Pipes\app\build\intermediates\cmake\deBUG\obj\arm64-v8a\libnative-lib.so CMakefiles/native-lib.dir/oboe/samples/deBUG-utils/trace.cpp.o CMakefiles/native-lib.dir/jni_brIDge.cpp.o CMakefiles/native-lib.dir/AudioENGIne.cpp.o CMakefiles/native-lib.dir/LatencyTuningCallBACk.cpp.o CMakefiles/native-lib.dir/SoundGenerator.cpp.o -llog oboe/liboboe.a -llog -lOpenSLES -latomic -lm && cd ."
CMakefiles/native-lib.dir/jni_brIDge.cpp.o: In function `Java_com_androID_smartpipes_PlayBACkENGIne_native_1setNote':
D:/Connor/DMA/Pipes/AndroID/smart_Pipes/app/src/main/cpp/jni_brIDge.cpp:189: undefined reference to `SoundGenerator::_F@R_489_10613@ency'
D:/Connor/DMA/Pipes/AndroID/smart_Pipes/app/src/main/cpp/jni_brIDge.cpp:189: undefined reference to `SoundGenerator::_F@R_489_10613@ency'
CMakefiles/native-lib.dir/SoundGenerator.cpp.o: In function `SoundGenerator::tap(bool)':
D:/Connor/DMA/Pipes/AndroID/smart_Pipes/app/src/main/cpp/SoundGenerator.cpp:(.text._ZN14SoundGenerator3tapEb+0x58): undefined reference to `SoundGenerator::_F@R_489_10613@ency'
D:/Connor/DMA/Pipes/AndroID/smart_Pipes/app/src/main/cpp/SoundGenerator.cpp:(.text._ZN14SoundGenerator3tapEb+0x5C): undefined reference to `SoundGenerator::_F@R_489_10613@ency'
clang++: error: linker command Failed with exit code 1 (use -v to see invocation)
ninja: build stopped: subcommand Failed.
jni_brIDge.cpp 中的方法
JNIEXPORT voID JNICALL
Java_com_androID_smartpipes_PlayBACkENGIne_native_1setNote(jnienv *env,jclass clazz,int notE) {
double freqScale[] = {419.98,//LG
480.00,//LA
540.03,//B
599.88,//C
644.42,//D
720.02,//E
802.60,//F
839.96,//HG
960.00 //HA
};
SoundGenerator::_F@R_489_10613@ency = freqScale[note];
}
我的 java 代码 PlayBACkENGIne.java
static voID setNote(ENote notE){
switch (notE){
case ELG:
native_setNote(0);
case ELA:
native_setNote(1);
case EB:
native_setNote(2);
case EC:
native_setNote(3);
case ED:
native_setNote(4);
case EE:
native_setNote(5);
case EF:
native_setNote(6);
case EHG:
native_setNote(7);
case EHA:
native_setNote(8);
default:
native_setNote(8);
}
}
private static native voID native_setNote(int notE);
SoundGenerator.cpp
voID SoundGenerator::tap(bool isOn) {
for (int i = 0; i < mChAnnelCount; ++i) {
mOscillators[i].setF@R_489_10613@ency(SoundGenerator::_F@R_489_10613@ency);
mOscillators[i].setWaveOn(isOn);
}
}
SoundGenerator.h
class SoundGenerator{
static double _F@R_489_10613@ency;
}
我正在尝试将 java 枚举注释作为 int 传递给 cpp,然后将其转换为 C++ 的 double。
感谢您的帮助
可能需要在 .cpp 文件中为静态类成员 SoundGenerator::_F@R_489_10613@ency 单独定义实际变量,如下所示。
SoundGenerator.cpp
double SoundGenerator::_F@R_489_10613@ency = 440.0; // A
以上是大佬教程为你收集整理的在 android 中使用 cpp 和 java 时,任务 ':app:externalNativeBuildDebug' 执行失败全部内容,希望文章能够帮你解决在 android 中使用 cpp 和 java 时,任务 ':app:externalNativeBuildDebug' 执行失败所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。