这里有同样问题的非常完整的答案:http: //grokbase.com/t/gg/android-ndk/125v31e6wy/play-store-market-filtering-of-ndk-libs
让我发布我自己的解决方案,这与我在这里发布的几乎相同:Android library .so with x86 architecture missing? (武佛利亚)
因此,您有一个无法在 x86 架构上编译的常规 Android.mk,因为您使用的库 (libExternalLibrary.so) 仅提供给 arm 架构。你想基于这个库构建一个 .so (libMyLibraryBasedOnExternalLibrary.so),当然如果没有这个库,它永远不会在 x86 上编译。
这个想法是直接在 Android.mk 中使用条件编译指令为 x86 生成 Dummy 库。
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)
// ...
}