Build command failed.
Error while executing process D:\AndroidStudio\Android\Sdk\cmake\3.6.4111459\bin\cmake.exe with arguments {--build F:\ccc\app\.externalNativeBuild\cmake\debug\armeabi-v7a --target native-lib}
[1/7] Building CXX object CMakeFiles/native-lib.dir/src/main/cpp/arcterncomm.pb.cc.o
[2/7] Building CXX object CMakeFiles/native-lib.dir/src/main/cpp/arcternWrap/ArcternAlgorithm.cpp.o
[3/7] Building CXX object CMakeFiles/native-lib.dir/src/main/cpp/Main.cpp.o
[4/7] Building CXX object CMakeFiles/native-lib.dir/src/main/cpp/DataSocket.cpp.o
[5/7] Building CXX object CMakeFiles/native-lib.dir/src/main/cpp/native-lib.cpp.o
[6/7] Building CXX object CMakeFiles/native-lib.dir/src/main/cpp/FixFrameSizeBufferQueue.cpp.o
[7/7] Linking CXX shared library F:\ccc\jniLibs\armeabi-v7a\libnative-lib.so
FAILED: cmd.exe /C "cd . && D:\AndroidStudio\Android\Sdk\ndk-bundle\toolchains\llvm\prebuilt\windows-x86_64\bin\clang++.exe --target=armv7-none-linux-androideabi --gcc-toolchain=D:/AndroidStudio/Android/Sdk/ndk-bundle/toolchains/arm-linux-androideabi-4.9/prebuilt/windows-x86_64 --sysroot=D:/AndroidStudio/Android/Sdk/ndk-bundle/platforms/android-23/arch-arm -fPIC -g -DANDROID -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -march=armv7-a -mfloat-abi=softfp -mfpu=vfpv3-d16 -fno-integrated-as -mthumb -Wa,--noexecstack -Wformat -Werror=format-security -g -DANDROID -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -march=armv7-a -mfloat-abi=softfp -mfpu=vfpv3-d16 -fno-integrated-as -mthumb -Wa,--noexecstack -Wformat -Werror=format-security -std=c++11 -mfpu=neon -O0 -fno-limit-debug-info -O0 -fno-limit-debug-info -Wl,--build-id -Wl,--warn-shared-textrel -Wl,--fatal-warnings -Wl,--fix-cortex-a8 -Wl,--no-undefined -Wl,-z,noexecstack -Qunused-arguments -Wl,-z,relro -Wl,-z,now -Wl,--build-id -Wl,--warn-shared-textrel -Wl,--fatal-warnings -Wl,--fix-cortex-a8 -Wl,--no-undefined -Wl,-z,noexecstack -Qunused-arguments -Wl,-z,relro -Wl,-z,now -shared -Wl,-soname,libnative-lib.so -o F:\ccc\jniLibs\armeabi-v7a\libnative-lib.so CMakeFiles/native-lib.dir/src/main/cpp/native-lib.cpp.o CMakeFiles/native-lib.dir/src/main/cpp/arcternWrap/ArcternAlgorithm.cpp.o CMakeFiles/native-lib.dir/src/main/cpp/DataSocket.cpp.o CMakeFiles/native-lib.dir/src/main/cpp/FixFrameSizeBufferQueue.cpp.o CMakeFiles/native-lib.dir/src/main/cpp/Main.cpp.o CMakeFiles/native-lib.dir/src/main/cpp/arcterncomm.pb.cc.o ../../../../src/main/jniLibs/armeabi-v7a/libarctern.a ../../../../src/main/jniLibs/armeabi-v7a/libcryptopp.a ../../../../src/main/jniLibs/armeabi-v7a/libflatbuffers.a ../../../../src/main/jniLibs/armeabi-v7a/libopencv_java3.so ../../../../src/main/jniLibs/armeabi-v7a/libdmlc.a ../../../../src/main/jniLibs/armeabi-v7a/libmxnet.so -lgomp ../../../../../protobuf_for_android/src/main/protobuf/jniLibs/armeabi-v7a/libprotobuf.so -llog -landroid -lm "D:/AndroidStudio/Android/Sdk/ndk-bundle/sources/cxx-stl/gnu-libstdc++/4.9/libs/armeabi-v7a/libsupc++.a" "D:/AndroidStudio/Android/Sdk/ndk-bundle/sources/cxx-stl/gnu-libstdc++/4.9/libs/armeabi-v7a/libgnustl_shared.so" && cd ."
D:/AndroidStudio/Android/Sdk/ndk-bundle/toolchains/arm-linux-androideabi-4.9/prebuilt/windows-x86_64/lib/gcc/arm-linux-androideabi/4.9.x/../../../../arm-linux-androideabi/bin\ld: error: ../../../../src/main/jniLibs/armeabi-v7a/libflatbuffers.a:1:1: syntax error, unexpected '!', expecting $end
D:/AndroidStudio/Android/Sdk/ndk-bundle/toolchains/arm-linux-androideabi-4.9/prebuilt/windows-x86_64/lib/gcc/arm-linux-androideabi/4.9.x/../../../../arm-linux-androideabi/bin\ld: error: ../../../../src/main/jniLibs/armeabi-v7a/libflatbuffers.a: not an object or archive
clang++.exe: error: linker command failed with exit code 1 (use -v to see invocation)
ninja: build stopped: subcommand failed.
报了如上的错误,libnative-lib.so链接时候出错,应该是没有生成这个so库文件。发现其实是一个依赖文件,用compare对比工具发现本来是unix编码,上传到git并拉下来后变成了pc编码,其实vi打开后set ff发现是dos。
关于"git submodule",首先关键字"sourcetree submodule"搜到文章<在SourceTree中使用Git submodule>,注意在add子模块的时候,如果依赖的是子模块的某个分支,则需要在add后面加上-b 分支名("git branch -a"命令后的某个远程分支,即"remotes/origin/"后面的某个远程分支名),如"git submodule add -b libs-gnustl [email protected] protobuf_for_android/src/main/protobuf ";关于从git上拉取后子模块代码的拉取参考文章
关于git的core.autocrlf,unix编码的文件上传到git的代码再拉下来后会变成dos格式(vi后:set ff查看),这个.a文件会导致链接不成功,后来参考了下文章
关于c++调用java方法,c++中传递std::string类型参数,java中是String类型参数,调用的时候需要通过env->NewStringUTF做一次转换。而且在GetMethodID获取java函数签名时用"Ljava/lang/String;"代表String类型,而不是根据int的"I"想当然成"S"。而且关于跨线程的AttachCurrentThread和DetachCurrentThread可以参考文章
关于andorid中一个应用如何导入基础库,参考了文章<导入一个AndroidStudio工程作为一个Library Module>、