@Test public void throwsMissingLibraryExceptionWhenABIIsMissing() throws IOException { final Context context = mock(Context.class); final ApplicationInfo appInfo = mock(ApplicationInfo.class); final ReLinkerInstance instance = mock(ReLinkerInstance.class); final ApkLibraryInstaller installer = new ApkLibraryInstaller(); final File destination = tempFolder.newFile("test"); final String[] abis = new String[] {"armeabi-v7a"}; when(context.getApplicationInfo()).thenReturn(appInfo); appInfo.sourceDir = getClass().getResource("/fake.apk").getFile(); try { installer.installLibrary(context, abis, "libtest.so", destination, instance); } catch (MissingLibraryException e) { assertEquals("Could not find 'libtest.so'. Looked for: [armeabi-v7a], but only found: [x86].", e.getMessage()); } }
@SuppressWarnings("ResultOfMethodCallIgnored") @Override public void installLibrary(final Context context, final String[] abis, final String mappedLibraryName, final File destination, final ReLinkerInstance instance) { ZipFileInZipEntry found = null; try { found = findAPKWithLibrary(context, abis, mappedLibraryName, instance); if (found == null) { String[] supportedABIs; try { supportedABIs = getSupportedABIs(context, mappedLibraryName); } catch (Exception e) { supportedABIs = new String[1]; supportedABIs[0] = e.toString(); } throw new MissingLibraryException(mappedLibraryName, abis, supportedABIs); } int tries = 0; while (tries++ < MAX_TRIES) { instance.log("Found %s! Extracting...", mappedLibraryName); try { if (!destination.exists() && !destination.createNewFile()) { continue; } } catch (IOException ignored) { continue; } InputStream inputStream = null; FileOutputStream fileOut = null; try { inputStream = found.zipFile.getInputStream(found.zipEntry); fileOut = new FileOutputStream(destination); final long written = copy(inputStream, fileOut); fileOut.getFD().sync(); if (written != destination.length()) { continue; } } catch (FileNotFoundException e) { continue; } catch (IOException e) { continue; } finally { closeSilently(inputStream); closeSilently(fileOut); } destination.setReadable(true, false); destination.setExecutable(true, false); destination.setWritable(true); return; } instance.log("FATAL! Couldn't extract the library from the APK!"); } finally { try { if (found != null && found.zipFile != null) { found.zipFile.close(); } } catch (IOException ignored) {} } }
ApkLibraryInstaller implements ReLinker.LibraryInstaller { @SuppressWarnings("ResultOfMethodCallIgnored") @Override public void installLibrary(final Context context, final String[] abis, final String mappedLibraryName, final File destination, final ReLinkerInstance instance) { ZipFileInZipEntry found = null; try { found = findAPKWithLibrary(context, abis, mappedLibraryName, instance); if (found == null) { String[] supportedABIs; try { supportedABIs = getSupportedABIs(context, mappedLibraryName); } catch (Exception e) { supportedABIs = new String[1]; supportedABIs[0] = e.toString(); } throw new MissingLibraryException(mappedLibraryName, abis, supportedABIs); } int tries = 0; while (tries++ < MAX_TRIES) { instance.log("Found %s! Extracting...", mappedLibraryName); try { if (!destination.exists() && !destination.createNewFile()) { continue; } } catch (IOException ignored) { continue; } InputStream inputStream = null; FileOutputStream fileOut = null; try { inputStream = found.zipFile.getInputStream(found.zipEntry); fileOut = new FileOutputStream(destination); final long written = copy(inputStream, fileOut); fileOut.getFD().sync(); if (written != destination.length()) { continue; } } catch (FileNotFoundException e) { continue; } catch (IOException e) { continue; } finally { closeSilently(inputStream); closeSilently(fileOut); } destination.setReadable(true, false); destination.setExecutable(true, false); destination.setWritable(true); return; } instance.log("FATAL! Couldn't extract the library from the APK!"); } finally { try { if (found != null && found.zipFile != null) { found.zipFile.close(); } } catch (IOException ignored) {} } } }
ApkLibraryInstaller implements ReLinker.LibraryInstaller { @SuppressWarnings("ResultOfMethodCallIgnored") @Override public void installLibrary(final Context context, final String[] abis, final String mappedLibraryName, final File destination, final ReLinkerInstance instance) { ZipFileInZipEntry found = null; try { found = findAPKWithLibrary(context, abis, mappedLibraryName, instance); if (found == null) { String[] supportedABIs; try { supportedABIs = getSupportedABIs(context, mappedLibraryName); } catch (Exception e) { supportedABIs = new String[1]; supportedABIs[0] = e.toString(); } throw new MissingLibraryException(mappedLibraryName, abis, supportedABIs); } int tries = 0; while (tries++ < MAX_TRIES) { instance.log("Found %s! Extracting...", mappedLibraryName); try { if (!destination.exists() && !destination.createNewFile()) { continue; } } catch (IOException ignored) { continue; } InputStream inputStream = null; FileOutputStream fileOut = null; try { inputStream = found.zipFile.getInputStream(found.zipEntry); fileOut = new FileOutputStream(destination); final long written = copy(inputStream, fileOut); fileOut.getFD().sync(); if (written != destination.length()) { continue; } } catch (FileNotFoundException e) { continue; } catch (IOException e) { continue; } finally { closeSilently(inputStream); closeSilently(fileOut); } destination.setReadable(true, false); destination.setExecutable(true, false); destination.setWritable(true); return; } instance.log("FATAL! Couldn't extract the library from the APK!"); } finally { try { if (found != null && found.zipFile != null) { found.zipFile.close(); } } catch (IOException ignored) {} } }  }
ApkLibraryInstaller implements ReLinker.LibraryInstaller { @SuppressWarnings("ResultOfMethodCallIgnored") @Override public void installLibrary(final Context context, final String[] abis, final String mappedLibraryName, final File destination, final ReLinkerInstance instance) { ZipFileInZipEntry found = null; try { found = findAPKWithLibrary(context, abis, mappedLibraryName, instance); if (found == null) { String[] supportedABIs; try { supportedABIs = getSupportedABIs(context, mappedLibraryName); } catch (Exception e) { supportedABIs = new String[1]; supportedABIs[0] = e.toString(); } throw new MissingLibraryException(mappedLibraryName, abis, supportedABIs); } int tries = 0; while (tries++ < MAX_TRIES) { instance.log("Found %s! Extracting...", mappedLibraryName); try { if (!destination.exists() && !destination.createNewFile()) { continue; } } catch (IOException ignored) { continue; } InputStream inputStream = null; FileOutputStream fileOut = null; try { inputStream = found.zipFile.getInputStream(found.zipEntry); fileOut = new FileOutputStream(destination); final long written = copy(inputStream, fileOut); fileOut.getFD().sync(); if (written != destination.length()) { continue; } } catch (FileNotFoundException e) { continue; } catch (IOException e) { continue; } finally { closeSilently(inputStream); closeSilently(fileOut); } destination.setReadable(true, false); destination.setExecutable(true, false); destination.setWritable(true); return; } instance.log("FATAL! Couldn't extract the library from the APK!"); } finally { try { if (found != null && found.zipFile != null) { found.zipFile.close(); } } catch (IOException ignored) {} } }  @SuppressWarnings("ResultOfMethodCallIgnored") @Override void installLibrary(final Context context,
                               final String[] abis,
                               final String mappedLibraryName,
                               final File destination,
                               final ReLinkerInstance instance); }
ApkLibraryInstaller implements ReLinker.LibraryInstaller { @SuppressWarnings("ResultOfMethodCallIgnored") @Override public void installLibrary(final Context context, final String[] abis, final String mappedLibraryName, final File destination, final ReLinkerInstance instance) { ZipFileInZipEntry found = null; try { found = findAPKWithLibrary(context, abis, mappedLibraryName, instance); if (found == null) { String[] supportedABIs; try { supportedABIs = getSupportedABIs(context, mappedLibraryName); } catch (Exception e) { supportedABIs = new String[1]; supportedABIs[0] = e.toString(); } throw new MissingLibraryException(mappedLibraryName, abis, supportedABIs); } int tries = 0; while (tries++ < MAX_TRIES) { instance.log("Found %s! Extracting...", mappedLibraryName); try { if (!destination.exists() && !destination.createNewFile()) { continue; } } catch (IOException ignored) { continue; } InputStream inputStream = null; FileOutputStream fileOut = null; try { inputStream = found.zipFile.getInputStream(found.zipEntry); fileOut = new FileOutputStream(destination); final long written = copy(inputStream, fileOut); fileOut.getFD().sync(); if (written != destination.length()) { continue; } } catch (FileNotFoundException e) { continue; } catch (IOException e) { continue; } finally { closeSilently(inputStream); closeSilently(fileOut); } destination.setReadable(true, false); destination.setExecutable(true, false); destination.setWritable(true); return; } instance.log("FATAL! Couldn't extract the library from the APK!"); } finally { try { if (found != null && found.zipFile != null) { found.zipFile.close(); } } catch (IOException ignored) {} } }  @SuppressWarnings("ResultOfMethodCallIgnored") @Override void installLibrary(final Context context,
                               final String[] abis,
                               final String mappedLibraryName,
                               final File destination,
                               final ReLinkerInstance instance);  }