示例#1
0
 private boolean extractLibResources(String libFile, String destDir) {
   Log.d(TAG, "Extract from " + libFile);
   ZipFile zipFile = null;
   try {
     zipFile = new ZipFile(libFile);
     for (String resource : XWALK_LIB_RESOURCES) {
       String entryDir = "";
       if (isNativeLibrary(resource)) {
         if (Build.CPU_ABI.equalsIgnoreCase("armeabi")) {
           // We build armeabi-v7a native lib for both armeabi & armeabi-v7a
           entryDir = "lib" + File.separator + "armeabi-v7a" + File.separator;
         } else {
           entryDir = "lib" + File.separator + Build.CPU_ABI + File.separator;
         }
       } else if (isAsset(resource)) {
         entryDir = "assets" + File.separator;
       }
       Log.d(TAG, "unzip " + entryDir + resource);
       ZipEntry entry = zipFile.getEntry(entryDir + resource);
       saveStreamToFile(zipFile.getInputStream(entry), new File(destDir, resource));
     }
   } catch (IOException | NullPointerException e) {
     Log.d(TAG, e.getLocalizedMessage());
     return false;
   } finally {
     try {
       zipFile.close();
     } catch (IOException | NullPointerException e) {
     }
   }
   return true;
 }
示例#2
0
  public static boolean extractResource(String libFile, String destDir) {
    Log.d(TAG, "Extract resource from Apk " + libFile);
    long start = SystemClock.uptimeMillis();

    ZipFile zipFile = null;
    try {
      zipFile = new ZipFile(libFile);

      for (String resource : MANDATORY_RESOURCES) {
        String entryDir = "";
        if (isNativeLibrary(resource)) {
          if (Build.CPU_ABI.equalsIgnoreCase("armeabi")) {
            // We build armeabi-v7a native lib for both armeabi & armeabi-v7a
            entryDir = "lib" + File.separator + "armeabi-v7a" + File.separator;
          } else {
            entryDir = "lib" + File.separator + Build.CPU_ABI + File.separator;
          }
        } else if (isAsset(resource)) {
          entryDir = "assets" + File.separator;
        }
        Log.d(TAG, "Extracting " + entryDir + resource);

        ZipEntry entry = zipFile.getEntry(entryDir + resource);
        if (entry == null) {
          Log.e(TAG, resource + " not found");
          return false;
        }
        extractStreamToFile(zipFile.getInputStream(entry), new File(destDir, resource));
      }
    } catch (IOException e) {
      Log.d(TAG, e.getLocalizedMessage());
      return false;
    } finally {
      try {
        zipFile.close();
      } catch (IOException | NullPointerException e) {
      }
    }
    Log.d(TAG, "Time to extract : " + (SystemClock.uptimeMillis() - start) + " ms");
    return true;
  }