Exemple #1
0
  // 加载提取出来的SO文件
  static boolean _loadUnzipSo(String libname, int version) {
    boolean initSuc = false;
    try {

      // 尝试libwebp.so
      Log.w(LOGTAG, "init my so libray:" + libname);
      if (isExist(libname, version)) {
        System.load(_targetSoFile(libname, version));
      } else {
        Log.e(LOGTAG, "so not in fetched place:" + libname);
        TBS.Ext.commitEvent(EventID_SO_INIT, "so not in fetched place:" + libname);
      }
      initSuc = true;
    } catch (Exception e) {
      initSuc = false;
      Log.e(LOGTAG, "init so failed library:" + libname + ",e=" + e.getMessage());
      e.printStackTrace();
      TBS.Ext.commitEvent(
          EventID_SO_INIT, "so not in fetched place:" + libname + ",e=" + e.getMessage());
    } catch (java.lang.UnsatisfiedLinkError e2) {
      initSuc = false;
      Log.e(LOGTAG, "init so failed failed(UnsatisfiedLinkError):" + e2.getMessage());
      e2.printStackTrace();
      TBS.Ext.commitEvent(
          EventID_SO_INIT, "so not in fetched place:" + libname + ",e=" + e2.getMessage());

    } catch (java.lang.Error e3) {
      initSuc = false;
      e3.printStackTrace();
      TBS.Ext.commitEvent(
          EventID_SO_INIT, "so not in fetched place:" + libname + ",e=" + e3.getMessage());
    }
    return initSuc;
  }
 // Load the cpp library that implements the native methods
 static {
   try {
     System.loadLibrary("TOOLVisionLink");
     visionLinkSuccessful = true;
     System.out.println("TOOLVisionLink lib loaded successfuly");
   } catch (UnsatisfiedLinkError e) {
     visionLinkSuccessful = false;
     System.err.print("Vision Link Failed to initialize: ");
     System.err.println(e.getMessage());
   }
 }
  /**
   * Loads the SWIG-generated libSBML Java module when this class is loaded, or reports a sensible
   * diagnostic message about why it failed.
   */
  static {
    String varname;
    String shlibname;

    if (System.getProperty("os.name").startsWith("Mac OS")) {
      varname = "DYLD_LIBRARY_PATH"; // We're on a Mac.
      shlibname = "'libsbmlj.jnilib'";
    } else {
      varname = "LD_LIBRARY_PATH"; // We're not on a Mac.
      shlibname = "'libsbmlj.so' and/or 'libsbml.so'";
    }

    try {
      System.loadLibrary("sbmlj");
      // For extra safety, check that the jar file is in the classpath.
      Class.forName("org.sbml.libsbml.libsbml");
    } catch (UnsatisfiedLinkError e) {
      System.err.println("Error encountered while attempting to load libSBML:");
      e.printStackTrace();
      System.err.println(
          "Please check the value of your "
              + varname
              + " environment variable and/or"
              + " your 'java.library.path' system property"
              + " (depending on which one you are using) to"
              + " make sure it list the directories needed to"
              + " find the "
              + shlibname
              + " library file and the"
              + " libraries it depends upon (e.g., the XML parser).");
      System.exit(1);
    } catch (ClassNotFoundException e) {
      System.err.println(
          "Error: unable to load the file 'libsbmlj.jar'."
              + " It is likely that your -classpath command line "
              + " setting or your CLASSPATH environment variable "
              + " do not include the file 'libsbmlj.jar'.");
      System.exit(1);
    } catch (SecurityException e) {
      System.err.println("Error encountered while attempting to load libSBML:");
      e.printStackTrace();
      System.err.println(
          "Could not load the libSBML library files due to a" + " security exception.\n");
      System.exit(1);
    }
  }
  public static void loadLibrary(String libName)
      throws WWRuntimeException, IllegalArgumentException {
    if (WWUtil.isEmpty(libName)) {
      String message = Logging.getMessage("nullValue.LibraryIsNull");
      throw new IllegalArgumentException(message);
    }

    try {
      System.loadLibrary(libName);
    } catch (java.lang.UnsatisfiedLinkError ule) {
      String message = Logging.getMessage("generic.LibraryNotLoaded", libName, ule.getMessage());
      throw new WWRuntimeException(message);
    } catch (Throwable t) {
      String message = Logging.getMessage("generic.LibraryNotLoaded", libName, t.getMessage());
      throw new WWRuntimeException(message);
    }
  }
Exemple #5
0
  /**
   * 完成加载so库的操作,先尝试用loadlibrary加载,如果失败则从apk中提取出armebi下的so,再加载。
   *
   * @param libname 库名字,例如webp,不必为libwep.so
   * @param version 版本号,正整数,新的版本>老的版本
   */
  public static boolean initSo(String libName, int version) {

    boolean InitSuc = false;

    // 首先,通过System.loadLibrary方法,从libs下库加载
    try {

      Log.i(LOGTAG, "init libray: " + libName);
      System.loadLibrary(libName);
      Log.i(LOGTAG, "init libray sucess:" + libName);

      InitSuc = true;
    } catch (Exception e) {
      InitSuc = false;
      Log.e(LOGTAG, "init libray failed:" + e.getMessage());
      e.printStackTrace();
    } catch (java.lang.UnsatisfiedLinkError e2) {
      InitSuc = false;
      Log.e(LOGTAG, "init library failed(UnsatisfiedLinkError):" + e2.getMessage());
      e2.printStackTrace();

    } catch (java.lang.Error e3) {
      InitSuc = false;
      e3.printStackTrace();
      Log.e(LOGTAG, "init library failed(Error):" + e3.getMessage());
    }

    try {

      if (!InitSuc) {

        // 从apk中提取的文件已经存在
        if (isExist(libName, version)) {
          boolean res = _loadUnzipSo(libName, version);
          if (res) return res;
          else {
            removeSoIfExit(libName, version);
            // 以有的SO有问题,删除然后尝试再解
            TBS.Ext.commitEvent(EventID_SO_INIT, "the exist target so is bad lib:" + libName);
          }
        }

        // 从libs下加载失败,则从apk中读出SO,加载
        String cpuType = _cpuType();
        if (cpuType.equalsIgnoreCase(MIPS) || cpuType.equalsIgnoreCase(X86)) {
          Log.w(LOGTAG, "cpu type" + cpuType + " no so in libs");
          TBS.Ext.commitEvent(
              EventID_SO_INIT, "no so in libs for cpu:" + cpuType + " ,lib:" + libName);

        } else {
          try {
            InitSuc = unZipSelectedFiles(libName, version);
          } catch (ZipException e) {
            e.printStackTrace();
            TBS.Ext.commitEvent(
                EventID_SO_INIT, "no so in libs for cpu:" + cpuType + " ,lib:" + libName);
          } catch (IOException e2) {
            e2.printStackTrace();
            TBS.Ext.commitEvent(
                EventID_SO_INIT, "no so in libs for cpu:" + cpuType + " ,lib:" + libName);
          }
        }
      }
    } catch (Exception e) {
      InitSuc = false;
      Log.e(LOGTAG, "init libray failed:" + e.getMessage());
      e.printStackTrace();
      TBS.Ext.commitEvent(
          EventID_SO_INIT, "unzip andload fail lib:" + libName + ",e=" + e.getMessage());
    } catch (java.lang.UnsatisfiedLinkError e2) {
      InitSuc = false;
      Log.e(LOGTAG, "init library failed(UnsatisfiedLinkError):" + e2.getMessage());
      e2.printStackTrace();
      TBS.Ext.commitEvent(
          EventID_SO_INIT,
          "unzip andload failed(UnsatisfiedLinkError) lib:" + libName + ",e=" + e2.getMessage());

    } catch (java.lang.Error e3) {
      InitSuc = false;
      Log.e(LOGTAG, "init library failed(Error):" + e3.getMessage());
      e3.printStackTrace();
      TBS.Ext.commitEvent(
          EventID_SO_INIT, "unzip andload failed(Error) lib:" + libName + ",e=" + e3.getMessage());
    }

    if (!InitSuc) {
      Log.e(LOGTAG, "initSo return false lib: " + libName);
      TBS.Ext.commitEvent(
          EventID_SO_INIT, "initSo return false lib: " + libName + ",cputype:" + _cpuType());
    }
    return InitSuc;
  }