有一個非常完整的答案,同樣的問題在這裏:http://grokbase.com/t/gg/android-ndk/125v31e6wy/play-store-market-filtering-of-ndk-libs
讓我發表我自己的解決方案,這幾乎是我在這裏張貼相同:Android library .so with x86 architecture missing? (Vuforia)
所以你有一個常規的Android.mk,不能在x86架構上編譯,因爲你使用的庫(libExternalLibrary.so)只提供給arm archi。 你想建立一個基於這個庫的.so(libMyLibraryBasedOnExternalLibrary.so),當然,如果沒有這個庫,它不會永遠不會編譯。
這個想法是直接在Android.mk中使用條件編譯指令直接爲x86生成虛擬庫。
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)
// ...
}
可能解決/嘲笑的想法:http://stackoverflow.com/questions/15146174/android-library-so-with-x-86-architecture-missing-vuforia – auselen