我正在尝试构建一个使用JNI的Android程序,这是我的Android.mk
:
LOCAL_PATH := $(call my-dir)
TESSERACT_PATH := $(LOCAL_PATH)/tesseract/src
LEPTONICA_PATH := $(LOCAL_PATH)/leptonica/src
LIBJPEG_PATH := $(LOCAL_PATH)/libjpeg
LIBPNG_PATH := $(LOCAL_PATH)/libpng
# Just build the Android.mk files in the subdirs
include $(call all-subdir-makefiles)
Application.mk
APP_STL := gnustl_static
APP_ABI := armeabi armeabi-v7a arm64-v8a
APP_OPTIM := release
APP_PLATFORM := android-9
APP_CPPFLAGS += -fexceptions -frtti
NDK_TOOLCHAIN_VERSION := clang
但是Android Studio警告我 Java native method can't resolve corresponding JNI method
,但实际上每项工作都可以运行,程序可以编译并运行correclty:
这是我的gradle构建脚本:
task ndkBuild(type: Exec) {
def ndkDirProperty = properties.getProperty('ndk.dir')
def ndkDirPrefix = ndkDirProperty != null ? ndkDirProperty + '/' : ''
def ndkBuildExt = Os.isFamily(Os.FAMILY_WINDOWS) ? ".cmd" : ""
commandLine "${ndkDirPrefix}ndk-build${ndkBuildExt}", '-C', file('.').absolutePath,
'-j', Runtime.runtime.availableProcessors()
}
tasks.withType(JavaCompile) {
compileTask -> compileTask.dependsOn ndkBuild
}
// Cleanup task to remove previously generated binaries
task ndkClean(type: Exec) {
def ndkDirProperty = properties.getProperty('ndk.dir')
def ndkDirPrefix = ndkDirProperty != null ? ndkDirProperty + '/' : ''
def ndkBuildExt = Os.isFamily(Os.FAMILY_WINDOWS) ? ".cmd" : ""
commandLine "${ndkDirPrefix}ndk-build${ndkBuildExt}", '-C', file('.').absolutePath, 'clean'
}
tasks.withType(Delete) {
cleanTask -> cleanTask.dependsOn ndkClean
}