我正在尝试运行vuforia Imagetarget示例项目,其中显示了本机函数的错误,“无法解析相应的JNI函数Java_com_vuforia_samples_ImageTargets_ImageTargets_setActivityPortraitMode”。
还会出现运行时错误和应用程序崩溃。以下是错误日志
07-10 12:15:50.774 11327-11327 / com.vuforia.samples.ImageTargets E / Vuforia:库libImageTargetsNative.so无法加载java.lang.UnsatisfiedLinkError:dlopen失败:无法找到符号“_ZN4QCAR14TrackerManager11getInstanceEv”引用通过“/data/app/com.vuforia.samples.ImageTargets-1/lib/arm/libImageTargetsNative.so”... 07-10 12:15:50.966 11327-11327 / com.vuforia.samples.ImageTargets E / art:找不到void com.vuforia.samples.ImageTargets.ImageTargets.setActivityPortraitMode(boolean)的实现(尝试过Java_com_vuforia_samples_ImageTargets_ImageTargets_setActivityPortraitMode和Java_com_vuforia_samples_ImageTargets_ImageTargets_setActivityPortraitMode__Z) 07-10 12:15:50.968 11327-11327 / com.vuforia.samples.ImageTargets E / AndroidRuntime:FATAL EXCEPTION:main 处理:com.vuforia.samples.ImageTargets,PID:11327 java.lang.UnsatisfiedLinkError:找不到void com.vuforia.samples.ImageTargets.ImageTargets.setActivityPortraitMode(boolean)的实现(尝试过Java_com_vuforia_samples_ImageTargets_ImageTargets_setActivityPortraitMode和Java_com_vuforia_samples_ImageTargets_ImageTargets_setActivityPortraitMode__Z) at com.vuforia.samples.ImageTargets.ImageTargets.setActivityPortraitMode(Native Method) at com.vuforia.samples.ImageTargets.ImageTargets.initApplication(ImageTargets.java:747) at com.vuforia.samples.ImageTargets.ImageTargets.updateApplicationStatus(ImageTargets.java:610) at com.vuforia.samples.ImageTargets.ImageTargets.onCreate(ImageTargets.java:373) 在android.app.Activity.performCreate(Activity.java:6672) 在android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1140) 在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2612) 在android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2724) 在android.app.ActivityThread.-wrap12(ActivityThread.java) 在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1473) 在android.os.Handler.dispatchMessage(Handler.java:102) 在android.os.Looper.loop(Looper.java:154) 在android.app.ActivityThread.main(ActivityThread.java:6123) at java.lang.reflect.Method.invoke(Native Method) 在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:867) 在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:757)
APP.GRADLE FILE:
apply plugin: 'com.android.application'
def VUFORIA_SDK_DIR = '../../..'
def JAR_DIR = 'build/java/vuforia'
android {
compileSdkVersion 22
buildToolsVersion "22.0.1"
sourceSets.main {
jni.srcDirs = []
jniLibs.srcDir "src/main/libs"
}
defaultConfig {
applicationId "com.vuforia.samples.ImageTargets"
minSdkVersion 8
targetSdkVersion 22
versionCode 600
versionName "6.0"
}
archivesBaseName = rootProject.projectDir.getName()
buildTypes {
release {
minifyEnabled false
ndk {
abiFilters "armeabi-v7a"
}
}
debug {
minifyEnabled false
debuggable true
ndk {
abiFilters "armeabi-v7a"
}
}
}
task buildNative(type: Exec, description: 'Compile JNI source via NDK') {
println('compiling jni code with ndk-build...')
def ndkDir = android.ndkDirectory
if (System.properties['os.name'].toLowerCase().contains('windows')) {
commandLine "$ndkDir/ndk-build.cmd",
'-C', file('src/main/jni').absolutePath
// Additional ndk-build arguments, such as NDK_DEBUG, can be provided here
} else {
commandLine "$ndkDir/ndk-build",
'-C', file('src/main/jni').absolutePath
// Additional ndk-build arguments, such as NDK_DEBUG, can be provided here
}
}
task cleanNative(type: Exec, description: 'Clean JNI object files') {
def ndkDir = android.ndkDirectory
if (System.properties['os.name'].toLowerCase().contains('windows')) {
commandLine "$ndkDir/ndk-build.cmd",
'-C', file('src/main/jni').absolutePath
'clean'
} else {
commandLine "$ndkDir/ndk-build",
'-C', file('src/main/jni').absolutePath
'clean'
}
}
clean.dependsOn 'cleanNative'
tasks.withType(JavaCompile) {
compileTask -> compileTask.dependsOn buildNative
}
}
dependencies {
compile files('src/main/java/Vuforia.jar')
}
Android.mk文件:
# An Android.mk file must begin with the definition of the LOCAL_PATH
# variable. It is used to locate source files in the development tree. Here
# the macro function 'my-dir' (provided by the build system) is used to return
# the path of the current directory.
LOCAL_PATH := $(call my-dir)
# The following section is used for copying the libVuforia.so prebuilt library
# into the appropriate folder (libs/armeabi and libs/armeabi-v7a respectively)
# and setting the include path for library-specific header files.
include $(CLEAR_VARS)
LOCAL_MODULE := Vuforia-prebuilt
LOCAL_SRC_FILES = ../../../../../../build/lib/$(TARGET_ARCH_ABI)/libVuforia.so
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/../../../../../../build/include
include $(PREBUILT_SHARED_LIBRARY)
#-----------------------------------------------------------------------------
# The CLEAR_VARS variable is provided by the build system and points to a
# special GNU Makefile that will clear many LOCAL_XXX variables for you
# (e.g. LOCAL_MODULE, LOCAL_SRC_FILES, LOCAL_STATIC_LIBRARIES, etc...),
# with the exception of LOCAL_PATH. This is needed because all build
# control files are parsed in a single GNU Make execution context where
# all variables are global.
include $(CLEAR_VARS)
# The LOCAL_MODULE variable must be defined to identify each module you
# describe in your Android.mk. The name must be *unique* and not contain
# any spaces. Note that the build system will automatically add proper
# prefix and suffix to the corresponding generated file. In other words,
# a shared library module named 'foo' will generate 'libfoo.so'.
LOCAL_MODULE := ImageTargetsNative
# Set OpenGL ES version-specific settings.
OPENGLES_LIB := -lGLESv2
OPENGLES_DEF := -DUSE_OPENGL_ES_2_0
# An optional set of compiler flags that will be passed when building
# C and C++ source files.
#
# The flag "-Wno-write-strings" removes warnings about deprecated conversion
# from string constant to 'char*'.
# The flag "-Wno-psabi" removes warning about "mangling of 'va_list' has
# changed in GCC 4.4" when compiled with certain Android NDK versions.
LOCAL_CFLAGS := -Wno-write-strings -Wno-psabi $(OPENGLES_DEF) -std=c++11
# The list of additional linker flags to be used when building your
# module. Use the "-l" prefix in front of the name of libraries you want to
# link to your module.
LOCAL_LDLIBS := \
-llog $(OPENGLES_LIB)
# The list of shared libraries this module depends on at runtime.
# This information is used at link time to embed the corresponding information
# in the generated file. Here we reference the prebuilt library defined earlier
# in this makefile.
LOCAL_SHARED_LIBRARIES := Vuforia-prebuilt
# The LOCAL_SRC_FILES variables must contain a list of C/C++ source files
# that will be built and assembled into a module. Note that you should not
# list header file and included files here because the build system will
# compute dependencies automatically for you, just list the source files
# that will be passed directly to a compiler.
LOCAL_SRC_FILES := ImageTargets.cpp SampleAppRenderer.cpp SampleUtils.cpp
Texture.cpp
# By default, ARM target binaries will be generated in 'thumb' mode, where
# each instruction is 16-bit wide. You can set this variable to 'arm' to
# set the generation of the module's object files to 'arm' (32-bit
# instructions) mode, resulting in potentially faster yet somewhat larger
# binary code.
LOCAL_ARM_MODE := arm
# BUILD_SHARED_LIBRARY is a variable provided by the build system that
# points to a GNU Makefile script being in charge of collecting all the
# information you have defined in LOCAL_XXX variables since the latest
# 'include $(CLEAR_VARS)' statement, determining what and how to build.
# Replace it with the statement BUILD_STATIC_LIBRARY to generate a static
# library instead.
include $(BUILD_SHARED_LIBRARY)
Application.mk文件:
# Build both ARMv5TE and ARMv7-A machine code.
APP_ABI := armeabi-v7a
# Set target Android API level to the application's minimum SDK version.
APP_PLATFORM := android-14
# This optional variable can be defined to either 'release' or
# 'debug'. This is used to alter the optimization level when
# building your application's modules.
#
# A 'release' mode is the default, and will generate highly
# optimized binaries. The 'debug' mode will generate un-optimized
# binaries which are much easier to debug.
#
# Note that it is possible to debug both 'release' and 'debug'
# binaries, but the 'release' builds tend to provide less information
# during debugging sessions: some variables are optimized out and
# can't be inspected, code re-ordering can make stepping through
# the code difficult, stack traces may not be reliable, etc...
# APP_OPTIM := release OR debug
libImageTargetsNative.so和libVuforia.so的路径是app / src / main / jniLibs。
所有mk文件,cpp文件和头文件都在jni文件夹下。
请告诉我,我遗漏了某些内容,或者我的代码中是否有任何错误。 提前致谢。
答案 0 :(得分:0)
Try using an older version of Unity. Everytime Unity release an update, my vuforia projects stop working, so I'm using Unity 5.2 and not updating anymore