你说过你已经为所有ABI构建了应用程序,但请仔细检查jniLibs文件夹中是否有所有子文件夹:armeabi、armeabi-v7a、x86、mips…或者至少有与设备崩溃时相同的ABI文件夹。
如果它们都存在,则ABI匹配。问题可能来自安装应用程序时解压缩库。
您可以尝试手动解压缩库进行以下操作:
public static int loadLibrary(Context context, String library){
try {
System.loadLibrary(library);
return 0;
} catch (UnsatisfiedLinkError ignored) {
ignored.printStackTrace();
}
File workaroundFile;
try {
workaroundFile = getWorkaroundLibFile(context, library);
if (!workaroundFile.exists()) {
unpackLibrary(context, library, workaroundFile);
}
try {
System.load(workaroundFile.getAbsolutePath());
return 1;
} catch (Throwable e) {
e.printStackTrace();
}
} catch (Exception e) {
e.printStackTrace();
}
return -1;
}
public static File getWorkaroundLibFile(final Context context, final String library) throws PackageManager.NameNotFoundException {
final String libName = System.mapLibraryName(library);
return new File(context.getDir("my_libs", Context.MODE_PRIVATE), libName);
}
@TargetApi(Build.VERSION_CODES.DONUT)
private static void unpackLibrary(final Context context, final String library, final File outputFile) throws IOException {
ZipFile zipFile = null;
try {
final ApplicationInfo appInfo = context.getApplicationInfo();
zipFile = new ZipFile(new File(appInfo.sourceDir), ZipFile.OPEN_READ);
InputStream inputStream = null;
FileOutputStream fileOut = null;
try {
inputStream = getInputStreamFromApk(zipFile, library);
fileOut = new FileOutputStream(outputFile);
copyStream(inputStream, fileOut);
} finally {
closeSilently(inputStream);
closeSilently(fileOut);
}
if (Build.VERSION.SDK_INT >= 9) {
outputFile.setReadable(true, false);
outputFile.setExecutable(true, false);
outputFile.setWritable(true);
}
} finally {
try {
if (zipFile != null) {
zipFile.close();
}
} catch (IOException ignored) {}
}
}
private static void copyStream(InputStream in, OutputStream out) throws IOException {
byte[] buf = new byte[4096];
while (true) {
int read = in.read(buf);
if (read == -1) {
break;
}
out.write(buf, 0, read);
}
}
private static void closeSilently(final Closeable closeable) {
try {
if (closeable != null) {
closeable.close();
}
} catch (IOException ignored) {}
}