我想将Vuforia增强实体库(jni)集成到一个Android项目中。AR不是应用程序的核心,它更像是一个辅助小工具。但是Vuforia库并不是为x86架构提供的,这意味着x86安卓手机将无法下载该应用程序。
有没有办法授权x86 phone下载应用程序,而不让他们播放应用程序的AR部分?这意味着有一种方法可以编译缺少库的x86拱门,并检测应用程序在哪个拱门上运行?
我知道x86安卓手机并不多,最后,我可能不得不等待Vuforia发布他们的.so的x86版本,但我想知道是否有办法做到我在这里描述的那样。
发布于 2013-03-04 15:32:49
这就是我实际上很容易解决这个问题的方法。Thx @auselen感谢您的帮助。
您有一个在x86架构上失败的常规Android.mk,因为您正在使用的库(libExternalLibrary.so)仅为arm archi提供。您希望基于该库构建一个.so (libMyLibraryBasedOnExternalLibrary.so)。
1)创建2个虚拟.cpp文件Dummy0.cpp和Dummy1.cpp示例Dummy0.cpp如下所示:
#include <jni.h>
#include <android/log.h>
#include <stdio.h>
#include <string.h>
#include <assert.h>
#include <math.h>
#include <string>
#ifdef __cplusplus
extern "C"
{
#endif
int dummy0 = 0;
#ifdef __cplusplus
}
#endif然后,编辑构建您的库的Android.mk,并对其进行如下修改:
LOCAL_PATH := $(call my-dir)
ifeq ($(TARGET_ARCH_ABI), armeabi)
# In this condtion block, we're compiling for arm architecture, and the libExternalLibrary.so is avaialble
# Put every thing the original Android.mk was doing here, importing the prebuilt library, compiling the shared library, etc...
# ...
# ...
else
# In this condtion block, we're not compiling for arm architecture, and the libExternalLibrary.so is not availalble.
# So we create a dummy library instead.
include $(CLEAR_VARS)
# when LOCAL_MODULE equals to ExternalLibrary, this will create a libExternalLibrary.so, which is exactly what we want to do.
LOCAL_MODULE := ExternalLibrary
LOCAL_SRC_FILES := Dummy0.cpp
include $(BUILD_SHARED_LIBRARY)
include $(CLEAR_VARS)
# This will create a libMyLibraryBasedOnExternalLibrary.so
LOCAL_MODULE := MyLibraryBasedOnExternalLibrary
# Don't forget to tell this library is based on ExternalLibrary, otherwise libExternalLibrary.so will not be copied in the libs/x86 directory
LOCAL_SHARED_LIBRARIES := ExternalLibrary
LOCAL_SRC_FILES := Dummy1.cpp
include $(BUILD_SHARED_LIBRARY)
endif当然,请确保在您的代码中,当您的应用程序在纯x86设备上运行时,您永远不会调用库:
if ((android.os.Build.CPU_ABI.equalsIgnoreCase("armeabi")) || (android.os.Build.CPU_ABI2.equalsIgnoreCase("armeabi"))) {
// Good I can launch
// Note that CPU_ABI2 is api level 8 (v2.2)
// ...
}发布于 2013-03-01 15:25:26
您可以使用工具(如cmock?)模拟vuforia。为了从头文件创建存根,然后使用x86的NDK构建存根,并在应用程序中使用生成的so (共享对象)。
在这种情况下,您还应该很好地处理代码中的不同体系结构,这可能意味着读取像Build.CPU_ABI这样的值
我建议你把这样的项目放在github下,这样其他人也可以从中受益。我不是许可方面的专家,但使用头文件应该是相当合法的。
https://stackoverflow.com/questions/15146174
复制相似问题