diff --git a/java/com/facebook/soloader/DirectApkSoSource.java b/java/com/facebook/soloader/DirectApkSoSource.java index 05b2a77..6679905 100644 --- a/java/com/facebook/soloader/DirectApkSoSource.java +++ b/java/com/facebook/soloader/DirectApkSoSource.java @@ -174,8 +174,8 @@ protected void prepare(int flags) throws IOException { } private void prepare() throws IOException { - String subDir = null; for (String directApkLdPath : mDirectApkLdPaths) { + String subDir = null; if (!TextUtils.isEmpty(directApkLdPath)) { final int i = directApkLdPath.indexOf('!'); if (i >= 0 && i + 2 < directApkLdPath.length()) { @@ -203,14 +203,18 @@ private void prepare() throws IOException { } private void buildLibDepsCache(String directApkLdPath, String soName) throws IOException { - try (ZipFile mZipFile = new ZipFile(getApkPathFromLdPath(directApkLdPath))) { - Enumeration entries = mZipFile.entries(); - while (entries.hasMoreElements()) { - ZipEntry entry = entries.nextElement(); - if (entry != null && entry.getName().endsWith("/" + soName)) { - buildLibDepsCacheImpl(directApkLdPath, mZipFile, entry, soName); - } + final String apkPath = getApkPathFromLdPath(directApkLdPath); + + try (ZipFile mZipFile = new ZipFile(apkPath)) { + final String path = getLibraryPathInApk(directApkLdPath, soName); + final ZipEntry entry = mZipFile.getEntry(path); + + if (entry == null) { + LogUtil.e(SoLoader.TAG, path + " not found in " + apkPath); + return; } + + buildLibDepsCacheImpl(directApkLdPath, mZipFile, entry, soName); } } @@ -273,6 +277,11 @@ private static String getApkPathFromLdPath(String ldPath) { return ldPath.substring(0, ldPath.indexOf('!')); } + private static String getLibraryPathInApk(String directApkLdPath, String soName) { + final int index = directApkLdPath.indexOf('!'); + return directApkLdPath.substring(index + 2) + File.separator + soName; + } + @Override public SoSource recover(Context context) { DirectApkSoSource recovered = new DirectApkSoSource(context);