我正在为Android开发一个需要一个小型c库的应用程序。此C库是使用SDK Tools中包含的GCMake编译的。我使用JNI函数连接java和C.
这是jni文件(jni_wrapper.c)
#include <jni.h>
#include "check.h"
JNIEXPORT void JNICALL Java_package_ui_fragments_menu_WeatherFragment_checkData( JNIEnv* env, jobject instance,
jobject data) {
checkData(data);
}
我的check.h文件
typedef struct {
char *date;
char *query;
} Data;
void checkData(Data* data);
我的check.c文件
#include <stdio.h>
#include <getopt.h>
#include <stdlib.h>
.... More imports
void checkData(Data* data) {
//implementation
}
目录结构
<root>/app/src/main/checkdata/
jni_wrapper.c
check.c
check.h
other_file_dependent_check.c
other_file_dependent_check.c
我的CMakeLists.txt
project(checkdata)
add_library(checkdata SHARED
jni_wrapper.c)
target_link_libraries(checkdata
android
log)
我的build.gradle文件(gradle插件版本2.2.2)
android {
compileSdkVersion 23
buildToolsVersion "23.0.3"
externalNativeBuild {
cmake {
path "src/main/checkdata/CMakeLists.txt"
}
}
失败:构建因异常而失败。
构建命令失败。 执行&#39; /Users/adrian/Library/Android/sdk/cmake/3.6.3155560/bin/cmake'时出错带参数{--build /App/path/app/.externalNativeBuild/cmake/debug/mips64 --target checkdata} [1/2]构建C对象CMakeFiles / checkdata.dir / jni_wrapper.c.o [2/2]链接C共享库/Users/adrian/Documents/devel/App/path/app/build/intermediates/cmake/debug/obj/mips64/libcheckdata.so 失败:&amp;&amp; / Users / bob / Library / Android / sdk / ndk-bundle / toolchains / llvm / prebuilt / darwin-x86_64 / bin / clang -target mips64el-none-linux-android -gcc-toolchain / Users / bob / Library / Android / sdk / ndk-bundle / toolchains / mips64el-linux-android-4.9 / prebuilt / darwin-x86_64 --sysroot = / Users / bob / Library / Android / sdk / ndk-bundle / platforms / android-21 / arch-mips64 - fPIC -g -DANDROID -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -Wa, - noexecstack -Wformat -Werror = format-security -g -DANDROID -ffunction-sections -funwind- tables -fstack-protector-strong -no-canonical-prefixes -Wa, - noexecstack -Wformat -Werror = format-security -O0 -fno-limit-debug-info -O0 -fno-limit-debug-info -Wl, --build-id -Wl, - warn-shared-textrel -Wl, - fatal-warnings -Wl, - no-undefined -Wl,-z,noexecstack -Qunused-arguments -Wl,-z,relro - Wl,-z,现在-Wl, - build-id -Wl, - warn-shared-textrel -Wl, - 致命警告-Wl, - no-undefined -Wl,-z,noexecstack -Qunused-参数-Wl,-z,relro -Wl,-z,now -shared -Wl,-soname,libchec kdata.so -o /App/path/app/build/intermediates/cmake/debug/obj/mips64/libcheckdata.so CMakeFiles / checkdata.dir / jni_wrapper.c.o -landroid -llog -lm&amp;&amp; : CMakeFiles / checkdata.dir / jni_wrapper.c.o:在函数
Java_package_ui_fragments_menu_WeatherFragment_checkData': /Users/bob/Documents/devel/App/path/src/main/checkdata/jni_wrapper.c:7: undefined reference to
checkData&#39; clang:错误:链接器命令失败,退出代码为1(使用-v查看调用) 忍者:构建停止:子命令失败。
我需要帮助错误/Users/bob/Documents/devel/App/path/src/main/checkdata/jni_wrapper.c:7:对`checkData&#39;
的未定义引用答案 0 :(得分:1)
add_library(Checkdata check.c)