此文已由做者尹彬彬受權網易雲社區發佈。
html
歡迎訪問網易雲社區,瞭解更多網易技術產品運營經驗。java
0X0 前言android
在Android系統中,當咱們安裝apk文件的時候,lib目錄下的so文件會被解壓到app的原生庫目錄,通常來講是放到/data/data/<package-name>/lib目錄下,而根據系統和CPU架構的不一樣,其拷貝策略也是不同的,在咱們測試過程當中發現不正確地配置了so文件,好比某些app使用第三方的so時,只配置了其中某一種CPU架構的so,可能會形成app在某些機型上的適配問題。因此這篇文章主要介紹一下在不一樣版本的Android系統中,安裝apk時,PackageManagerService選擇解壓so庫的策略,並給出一些so文件配置的建議。安全
0x1 Android4.0之前bash
當apk被安裝時,執行路徑雖然有差異,但最終要調用到的一個核心函數是copyApk,負責拷貝apk中的資源。架構
參考2.3.6的android源碼,它的copyApk其內部函數一段選取原生庫so邏輯:app
public static int listPackageNativeBinariesLI(ZipFile zipFile,
List> nativeFiles) throws ZipException, IOException {
String cpuAbi = Build.CPU_ABI; int result = listPackageSharedLibsForAbiLI(zipFile, cpuAbi, nativeFiles); /*
* Some architectures are capable of supporting several CPU ABIs
* for example, 'armeabi-v7a' also supports 'armeabi' native code
* this is indicated by the definition of the ro.product.cpu.abi2
* system property.
*
* only scan the package twice in case of ABI mismatch
*/
if (result == PACKAGE_INSTALL_NATIVE_ABI_MISMATCH) { final String cpuAbi2 = SystemProperties.get("ro.product.cpu.abi2", null); if (cpuAbi2 != null) {
result = listPackageSharedLibsForAbiLI(zipFile, cpuAbi2, nativeFiles);
} if (result == PACKAGE_INSTALL_NATIVE_ABI_MISMATCH) {
Slog.w(TAG, "Native ABI mismatch from package file"); return PackageManager.INSTALL_FAILED_INVALID_APK;
} if (result == PACKAGE_INSTALL_NATIVE_FOUND_LIBRARIES) {
cpuAbi = cpuAbi2;
}
} /*
* Debuggable packages may have gdbserver embedded, so add it to
* the list to the list of items to be extracted (as lib/gdbserver)
* into the application's native library directory later. */ if (result == PACKAGE_INSTALL_NATIVE_FOUND_LIBRARIES) { listPackageGdbServerLI(zipFile, cpuAbi, nativeFiles); } return PackageManager.INSTALL_SUCCEEDED; }複製代碼
這段代碼中的Build.CPU_ABI和「ro.product.cpu.abi2」分別爲手機支持的主abi和次abi屬性字符串,abi爲手機支持的指令集所表明的字符串,好比armeabi-v7a、armeabi、x8六、mips等,而主abi和次abi分別表示手機支持的第一指令集和第二指令集。代碼首先調用listPackageSharedLibsForAbiLI來遍歷主abi目錄。當主abi目錄不存在時,纔會接着調用listPackageSharedLibsForAbiLI遍歷次abi目錄。ide
/*
* Find all files of the form lib//lib.so in the .apk
* and add them to a list to be installed later.
*
* NOTE: this method may throw an IOException if the library cannot
* be copied to its final destination, e.g. if there isn't enough * room left on the data partition, or a ZipException if the package * file is malformed. */ private static int listPackageSharedLibsForAbiLI(ZipFile zipFile, String cpuAbi, List> libEntries) throws IOException, ZipException { final int cpuAbiLen = cpuAbi.length(); boolean hasNativeLibraries = false; boolean installedNativeLibraries = false; if (DEBUG_NATIVE) { Slog.d(TAG, "Checking " + zipFile.getName() + " for shared libraries of CPU ABI type " + cpuAbi); } Enumeration entries = zipFile.entries(); while (entries.hasMoreElements()) { ZipEntry entry = entries.nextElement(); // skip directories if (entry.isDirectory()) { continue; } String entryName = entry.getName(); /* * Check that the entry looks like lib//lib.so * here, but don't check the ABI just yet.
*
* - must be sufficiently long
* - must end with LIB_SUFFIX, i.e. ".so"
* - must start with APK_LIB, i.e. "lib/"
*/
if (entryName.length() < MIN_ENTRY_LENGTH || !entryName.endsWith(LIB_SUFFIX)
|| !entryName.startsWith(APK_LIB)) { continue;
} // file name must start with LIB_PREFIX, i.e. "lib"
int lastSlash = entryName.lastIndexOf('/'); if (lastSlash < 0
|| !entryName.regionMatches(lastSlash + 1, LIB_PREFIX, 0, LIB_PREFIX_LENGTH)) { continue;
}
hasNativeLibraries = true; // check the cpuAbi now, between lib/ and /lib.so
if (lastSlash != APK_LIB_LENGTH + cpuAbiLen
|| !entryName.regionMatches(APK_LIB_LENGTH, cpuAbi, 0, cpuAbiLen)) continue; /*
* Extract the library file name, ensure it doesn't contain * weird characters. we're guaranteed here that it doesn't contain * a directory separator though. */ String libFileName = entryName.substring(lastSlash+1); if (!FileUtils.isFilenameSafe(new File(libFileName))) { continue; } installedNativeLibraries = true; if (DEBUG_NATIVE) { Log.d(TAG, "Caching shared lib " + entry.getName()); } libEntries.add(Pair.create(entry, libFileName)); } if (!hasNativeLibraries) return PACKAGE_INSTALL_NATIVE_NO_LIBRARIES; if (!installedNativeLibraries) return PACKAGE_INSTALL_NATIVE_ABI_MISMATCH; return PACKAGE_INSTALL_NATIVE_FOUND_LIBRARIES; }複製代碼
listPackageSharedLibsForAbiLI中判斷當前遍歷的apk中文件的entry名是否符合so命名的規範且包含相應abi字符串名。若是符合則規則則將so的entry名加入list,若是遍歷失敗或者規則不匹配則返回相應錯誤碼。函數
拷貝so策略:性能
遍歷apk中文件,當apk中lib目錄下主abi子目錄中有so文件存在時,則所有拷貝主abi子目錄下的so;只有當主abi子目錄下沒有so文件的時候即PACKAGE_INSTALL_NATIVE_ABI_MISMATCH的狀況,纔會拷貝次ABI子目錄下的so文件。
策略問題:
當so放置不當時,安裝apk時會致使拷貝不全。好比apk的lib目錄下存在armeabi/libx.so,armeabi/liby.so,armeabi-v7a/libx.so這3個so文件,那麼在主ABI爲armeabi-v7a且系統版本小於4.0的手機上,apk安裝後,按照拷貝策略,只會拷貝主abi目錄下的文件即armeabi-v7a/libx.so,當加載liby.so時就會報找不到so的異常。另外若是主abi目錄不存在,這個策略會遍歷2次apk,效率偏低。
0x2 Android 4.0-Android 4.0.3
參考4.0.3的android源碼,同理,找處處理so拷貝的核心邏輯(native層):
static install_status_titerateOverNativeFiles(JNIEnv *env, jstring javaFilePath, jstring javaCpuAbi, jstring javaCpuAbi2,
iterFunc callFunc, void* callArg) { ScopedUtfChars filePath(env, javaFilePath); ScopedUtfChars cpuAbi(env, javaCpuAbi); ScopedUtfChars cpuAbi2(env, javaCpuAbi2);
ZipFileRO zipFile; if (zipFile.open(filePath.c_str()) != NO_ERROR) {
LOGI("Couldn't open APK %s\n", filePath.c_str()); return INSTALL_FAILED_INVALID_APK;
} const int N = zipFile.getNumEntries(); char fileName[PATH_MAX]; for (int i = 0; i < N; i++) { const ZipEntryRO entry = zipFile.findEntryByIndex(i); if (entry == NULL) { continue;
} // Make sure this entry has a filename.
if (zipFile.getEntryFileName(entry, fileName, sizeof(fileName))) { continue;
} // Make sure we're in the lib directory of the ZIP. if (strncmp(fileName, APK_LIB, APK_LIB_LEN)) { continue; } // Make sure the filename is at least to the minimum library name size. const size_t fileNameLen = strlen(fileName); static const size_t minLength = APK_LIB_LEN + 2 + LIB_PREFIX_LEN + 1 + LIB_SUFFIX_LEN; if (fileNameLen < minLength) { continue; } const char* lastSlash = strrchr(fileName, '/'); LOG_ASSERT(lastSlash != NULL, "last slash was null somehow for %s\n", fileName); // Check to make sure the CPU ABI of this file is one we support. const char* cpuAbiOffset = fileName + APK_LIB_LEN; const size_t cpuAbiRegionSize = lastSlash - cpuAbiOffset; LOGV("Comparing ABIs %s and %s versus %s\n", cpuAbi.c_str(), cpuAbi2.c_str(), cpuAbiOffset); if (cpuAbi.size() == cpuAbiRegionSize && *(cpuAbiOffset + cpuAbi.size()) == '/' && !strncmp(cpuAbiOffset, cpuAbi.c_str(), cpuAbiRegionSize)) { LOGV("Using ABI %s\n", cpuAbi.c_str()); } else if (cpuAbi2.size() == cpuAbiRegionSize && *(cpuAbiOffset + cpuAbi2.size()) == '/' && !strncmp(cpuAbiOffset, cpuAbi2.c_str(), cpuAbiRegionSize)) { LOGV("Using ABI %s\n", cpuAbi2.c_str()); } else { LOGV("abi didn't match anything: %s (end at %zd)\n", cpuAbiOffset, cpuAbiRegionSize); continue; } // If this is a .so file, check to see if we need to copy it. if ((!strncmp(fileName + fileNameLen - LIB_SUFFIX_LEN, LIB_SUFFIX, LIB_SUFFIX_LEN) && !strncmp(lastSlash, LIB_PREFIX, LIB_PREFIX_LEN) && isFilenameSafe(lastSlash + 1)) || !strncmp(lastSlash + 1, GDBSERVER, GDBSERVER_LEN)) { install_status_t ret = callFunc(env, callArg, &zipFile, entry, lastSlash + 1); if (ret != INSTALL_SUCCEEDED) { LOGV("Failure for entry %s", lastSlash + 1); return ret; } } } return INSTALL_SUCCEEDED; }複製代碼
拷貝so策略:
遍歷apk中全部文件,若是符合so文件的規則,且爲主ABI目錄或者次ABI目錄下的so,就解壓拷貝到相應目錄。
策略問題:
存在同名so覆蓋,好比一個app的armeabi和armeabi-v7a目錄下都包含同名的so,那麼就會發生覆蓋現象,覆蓋的前後順序根據so文件對應ZipFileR0中的hash值而定,考慮這樣一個例子,假設一個apk同時有armeabi/libx.so和armeabi-v7a/libx.so,安裝到主ABI爲armeabi-v7a的手機上,拷貝so時根據遍歷順序,存在一種可能即armeab-v7a/libx.so優先遍歷並被拷貝,隨後armeabi/libx.so被遍歷拷貝,覆蓋了前者。原本應該加載armeabi-v7a目錄下的so,結果按照這個策略拷貝了armeabi目錄下的so。
apk中文件entry的散列計算函數以下:
/*
* Simple string hash function for non-null-terminated strings.
*//*static*/ unsigned int ZipFileRO::computeHash(const char* str, int len)
{
unsigned int hash = 0; while (len--)
hash = hash * 31 + *str++; return hash;
}/*
* Add a new entry to the hash table.
*/void ZipFileRO::addToHash(const char* str, int strLen, unsigned int hash)
{ int ent = hash & (mHashTableSize-1); /*
* We over-allocate the table, so we're guaranteed to find an empty slot. */ while (mHashTable[ent].name != NULL) ent = (ent + 1) & (mHashTableSize-1); mHashTable[ent].name = str; mHashTable[ent].nameLen = strLen; }複製代碼
0x3 Android 4.0.4之後
以4.1.2系統爲例,遍歷選擇so邏輯以下:
static install_status_titerateOverNativeFiles(JNIEnv *env, jstring javaFilePath, jstring javaCpuAbi, jstring javaCpuAbi2,
iterFunc callFunc, void* callArg) { ScopedUtfChars filePath(env, javaFilePath); ScopedUtfChars cpuAbi(env, javaCpuAbi); ScopedUtfChars cpuAbi2(env, javaCpuAbi2);
ZipFileRO zipFile; if (zipFile.open(filePath.c_str()) != NO_ERROR) {
ALOGI("Couldn't open APK %s\n", filePath.c_str()); return INSTALL_FAILED_INVALID_APK;
} const int N = zipFile.getNumEntries(); char fileName[PATH_MAX];
bool hasPrimaryAbi = false; for (int i = 0; i < N; i++) { const ZipEntryRO entry = zipFile.findEntryByIndex(i); if (entry == NULL) { continue;
} // Make sure this entry has a filename.
if (zipFile.getEntryFileName(entry, fileName, sizeof(fileName))) { continue;
} // Make sure we're in the lib directory of the ZIP. if (strncmp(fileName, APK_LIB, APK_LIB_LEN)) { continue; } // Make sure the filename is at least to the minimum library name size. const size_t fileNameLen = strlen(fileName); static const size_t minLength = APK_LIB_LEN + 2 + LIB_PREFIX_LEN + 1 + LIB_SUFFIX_LEN; if (fileNameLen < minLength) { continue; } const char* lastSlash = strrchr(fileName, '/'); ALOG_ASSERT(lastSlash != NULL, "last slash was null somehow for %s\n", fileName); // Check to make sure the CPU ABI of this file is one we support. const char* cpuAbiOffset = fileName + APK_LIB_LEN; const size_t cpuAbiRegionSize = lastSlash - cpuAbiOffset; ALOGV("Comparing ABIs %s and %s versus %s\n", cpuAbi.c_str(), cpuAbi2.c_str(), cpuAbiOffset); if (cpuAbi.size() == cpuAbiRegionSize && *(cpuAbiOffset + cpuAbi.size()) == '/' && !strncmp(cpuAbiOffset, cpuAbi.c_str(), cpuAbiRegionSize)) { ALOGV("Using primary ABI %s\n", cpuAbi.c_str()); hasPrimaryAbi = true; } else if (cpuAbi2.size() == cpuAbiRegionSize && *(cpuAbiOffset + cpuAbi2.size()) == '/' && !strncmp(cpuAbiOffset, cpuAbi2.c_str(), cpuAbiRegionSize)) { /* * If this library matches both the primary and secondary ABIs, * only use the primary ABI. */ if (hasPrimaryAbi) { ALOGV("Already saw primary ABI, skipping secondary ABI %s\n", cpuAbi2.c_str()); continue; } else { ALOGV("Using secondary ABI %s\n", cpuAbi2.c_str()); } } else { ALOGV("abi didn't match anything: %s (end at %zd)\n", cpuAbiOffset, cpuAbiRegionSize); continue; } // If this is a .so file, check to see if we need to copy it. if ((!strncmp(fileName + fileNameLen - LIB_SUFFIX_LEN, LIB_SUFFIX, LIB_SUFFIX_LEN) && !strncmp(lastSlash, LIB_PREFIX, LIB_PREFIX_LEN) && isFilenameSafe(lastSlash + 1)) || !strncmp(lastSlash + 1, GDBSERVER, GDBSERVER_LEN)) { install_status_t ret = callFunc(env, callArg, &zipFile, entry, lastSlash + 1); if (ret != INSTALL_SUCCEEDED) { ALOGV("Failure for entry %s", lastSlash + 1); return ret; } } } return INSTALL_SUCCEEDED; }複製代碼
拷貝so策略:
遍歷apk中文件,當遍歷到有主Abi目錄的so時,拷貝並設置標記hasPrimaryAbi爲真,之後遍歷則只拷貝主Abi目錄下的so,當標記爲假的時候,若是遍歷的so的entry名包含次abi字符串,則拷貝該so。
策略問題:
通過實際測試,so放置不當時,安裝apk時存在so拷貝不全的狀況。這個策略想解決的問題是在4.0~4.0.3系統中的so隨意覆蓋的問題,即若是有主abi目錄的so則拷貝,若是主abi目錄不存在這個so則拷貝次abi目錄的so,但代碼邏輯是根據ZipFileR0的遍歷順序來決定是否拷貝so,假設存在這樣的apk,lib目錄下存在armeabi/libx.so,armeabi/liby.so,armeabi-v7a/libx.so這三個so文件,且hash的順序爲armeabi-v7a/libx.so在armeabi/liby.so以前,則apk安裝的時候liby.so根本不會被拷貝,由於按照拷貝策略,armeabi-v7a/libx.so會優先遍歷到,因爲它是主abi目錄的so文件,因此標記被設置了,當遍歷到armeabi/liby.so時,因爲標記被設置爲真,liby.so的拷貝就被忽略了,從而在加載liby.so的時候會報異常。
0x4 64位系統支持
Android在5.0以後支持64位ABI,以5.1.0系統爲例:
public static int copyNativeBinariesWithOverride(Handle handle, File libraryRoot,
String abiOverride) { try { if (handle.multiArch) { // Warn if we've set an abiOverride for multi-lib packages.. // By definition, we need to copy both 32 and 64 bit libraries for // such packages. if (abiOverride != null && !CLEAR_ABI_OVERRIDE.equals(abiOverride)) { Slog.w(TAG, "Ignoring abiOverride for multi arch application."); } int copyRet = PackageManager.NO_NATIVE_LIBRARIES; if (Build.SUPPORTED_32_BIT_ABIS.length > 0) { copyRet = copyNativeBinariesForSupportedAbi(handle, libraryRoot, Build.SUPPORTED_32_BIT_ABIS, true /* use isa specific subdirs */); if (copyRet < 0 && copyRet != PackageManager.NO_NATIVE_LIBRARIES && copyRet != PackageManager.INSTALL_FAILED_NO_MATCHING_ABIS) { Slog.w(TAG, "Failure copying 32 bit native libraries; copyRet=" +copyRet); return copyRet; } } if (Build.SUPPORTED_64_BIT_ABIS.length > 0) { copyRet = copyNativeBinariesForSupportedAbi(handle, libraryRoot, Build.SUPPORTED_64_BIT_ABIS, true /* use isa specific subdirs */); if (copyRet < 0 && copyRet != PackageManager.NO_NATIVE_LIBRARIES && copyRet != PackageManager.INSTALL_FAILED_NO_MATCHING_ABIS) { Slog.w(TAG, "Failure copying 64 bit native libraries; copyRet=" +copyRet); return copyRet; } } } else { String cpuAbiOverride = null; if (CLEAR_ABI_OVERRIDE.equals(abiOverride)) { cpuAbiOverride = null; } else if (abiOverride != null) { cpuAbiOverride = abiOverride; } String[] abiList = (cpuAbiOverride != null) ? new String[] { cpuAbiOverride } : Build.SUPPORTED_ABIS; if (Build.SUPPORTED_64_BIT_ABIS.length > 0 && cpuAbiOverride == null && hasRenderscriptBitcode(handle)) { abiList = Build.SUPPORTED_32_BIT_ABIS; } int copyRet = copyNativeBinariesForSupportedAbi(handle, libraryRoot, abiList, true /* use isa specific subdirs */); if (copyRet < 0 && copyRet != PackageManager.NO_NATIVE_LIBRARIES) { Slog.w(TAG, "Failure copying native libraries [errorCode=" + copyRet + "]"); return copyRet; } } return PackageManager.INSTALL_SUCCEEDED; } catch (IOException e) { Slog.e(TAG, "Copying native libraries failed", e); return PackageManager.INSTALL_FAILED_INTERNAL_ERROR; } }複製代碼
copyNativeBinariesWithOverride分別處理32位和64位so的拷貝,內部函數copyNativeBinariesForSupportedAbi首先會根據abilist去找對應的abi。
public static int copyNativeBinariesForSupportedAbi(Handle handle, File libraryRoot,
String[] abiList, boolean useIsaSubdir) throws IOException {
createNativeLibrarySubdir(libraryRoot); /*
* If this is an internal application or our nativeLibraryPath points to
* the app-lib directory, unpack the libraries if necessary.
*/
int abi = findSupportedAbi(handle, abiList); if (abi >= 0) { /*
* If we have a matching instruction set, construct a subdir under the native
* library root that corresponds to this instruction set.
*/
final String instructionSet = VMRuntime.getInstructionSet(abiList[abi]); final File subDir; if (useIsaSubdir) { final File isaSubdir = new File(libraryRoot, instructionSet);
createNativeLibrarySubdir(isaSubdir);
subDir = isaSubdir;
} else {
subDir = libraryRoot;
} int copyRet = copyNativeBinaries(handle, subDir, abiList[abi]); if (copyRet != PackageManager.INSTALL_SUCCEEDED) { return copyRet;
}
} return abi;
}複製代碼
findSupportedAbi內部實現是native函數,首先遍歷apk,若是so的全路徑中包含abilist中的abi字符串,則記錄該abi字符串的索引,最終返回全部記錄索引中最靠前的,即排在abilist中最前面的索引。
static int findSupportedAbi(JNIEnv *env, jlong apkHandle, jobjectArray supportedAbisArray) { const int numAbis = env->GetArrayLength(supportedAbisArray);
VectorsupportedAbis; for (int i = 0; i < numAbis; ++i) {
supportedAbis.add(new ScopedUtfChars(env,
(jstring) env->GetObjectArrayElement(supportedAbisArray, i)));
}
ZipFileRO* zipFile = reinterpret_cast(apkHandle); if (zipFile == NULL) { return INSTALL_FAILED_INVALID_APK;
} UniquePtr it(NativeLibrariesIterator::create(zipFile)); if (it.get() == NULL) { return INSTALL_FAILED_INVALID_APK;
}
ZipEntryRO entry = NULL; char fileName[PATH_MAX]; int status = NO_NATIVE_LIBRARIES; while ((entry = it->next()) != NULL) { // We're currently in the lib/ directory of the APK, so it does have some native // code. We should return INSTALL_FAILED_NO_MATCHING_ABIS if none of the // libraries match. if (status == NO_NATIVE_LIBRARIES) { status = INSTALL_FAILED_NO_MATCHING_ABIS; } const char* fileName = it->currentEntry(); const char* lastSlash = it->lastSlash(); // Check to see if this CPU ABI matches what we are looking for. const char* abiOffset = fileName + APK_LIB_LEN; const size_t abiSize = lastSlash - abiOffset; for (int i = 0; i < numAbis; i++) { const ScopedUtfChars* abi = supportedAbis[i]; if (abi->size() == abiSize && !strncmp(abiOffset, abi->c_str(), abiSize)) { // The entry that comes in first (i.e. with a lower index) has the higher priority. if (((i < status) && (status >= 0)) || (status < 0) ) { status = i; } } } } for (int i = 0; i < numAbis; ++i) { delete supportedAbis[i]; } return status; }複製代碼
舉例說明,在某64位測試手機上的abi屬性顯示以下,它有2個abilist,分別對應該手機支持的32位和64位abi的字符串組。
當處理32位so拷貝時,findSupportedAbi索引返回以後,若返回爲0,則拷貝armeabi-v7a目錄下的so,若是爲1,則拷貝armeabi目錄下so。
拷貝so策略:
分別處理32位和64位abi目錄的so拷貝,abi由遍歷apk結果的全部so中符合abilist列表的最靠前的序號決定,而後拷貝該abi目錄下的so文件。
策略問題:
策略假定每一個abi目錄下的so都放置徹底的,這是和2.3.6同樣的處理邏輯,存在遺漏拷貝so的可能。
0x5 建議
針對android系統的這些拷貝策略的問題,咱們給出了一些配置so的建議:
1)針對armeabi和armeabi-v7a兩種ABI
方法1:因爲armeabi-v7a指令集兼容armeabi指令集,因此若是損失一些應用的性能是能夠接受的,同時不但願保留庫的兩份拷貝,能夠移除armeabi-v7a目錄和其下的庫文件,只保留armeabi目錄;好比apk使用第三方的so只有armeabi這一種abi時,能夠考慮去掉apk中lib目錄下armeabi-v7a目錄。
方法2:在armeabi和armeabi-v7a目錄下各放入一份so;
2)針對x86
目前市面上的x86機型,爲了兼容arm指令,基本都內置了libhoudini模塊,即二進制轉碼支持,該模塊負責把ARM指令轉換爲X86指令,因此若是是出於apk包大小的考慮,而且能夠接受一些性能損失,能夠選擇刪掉x86庫目錄,x86下配置的armeabi目錄的so庫同樣能夠正常加載使用;
3)針對64位ABI
若是app開發者打算支持64位,那麼64位的so要放全,不然能夠選擇不單獨編譯64位的so,所有使用32位的so,64位機型默認支持32位so的加載。好比apk使用第三方的so只有32位abi的so,能夠考慮去掉apk中lib目錄下的64位abi子目錄,保證apk安裝後正常使用。
0x6 備註
其實本文是由於在Android的so加載上遇到不少坑,相信不少朋友都遇到過UnsatisfiedLinkError這個錯誤,反應在用戶的機型上也是千差萬別,可是有沒有想過,可能不是apk邏輯的問題,而是Android系統在安裝APK的時候,因爲PackageManager的問題,並無拷貝相應的SO呢?能夠參考下面第4個連接,做者給出瞭解決方案,就是當出現UnsatisfiedLinkError錯誤時,手動拷貝so來解決的。
參考文章:
android源碼:https://android.googlesource.com/platform/frameworks/base
apk安裝過程及原理說明:http://blog.csdn.net/hdhd588/article/details/6739281
UnsatisfiedLinkError的錯誤及解決方案:
更多網易技術、產品、運營經驗分享請點擊。
相關文章:
【推薦】 快速上手JS-SDK自動化測試
【推薦】 2017年內容安全十大事件盤點