java.lang.System.loadLibrary()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(9.2k)|赞(0)|评价(0)|浏览(412)

本文整理了Java中java.lang.System.loadLibrary()方法的一些代码示例,展示了System.loadLibrary()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。System.loadLibrary()方法的具体详情如下:
包路径:java.lang.System
类名称:System
方法名:loadLibrary

System.loadLibrary介绍

[英]Loads and links the library with the specified name. The mapping of the specified library name to the full path for loading the library is implementation-dependent.
[中]加载并链接具有指定名称的库。指定库名称到加载库的完整路径的映射取决于实现。

代码示例

代码示例来源:origin: netty/netty

/**
 * Delegate the calling to {@link System#load(String)} or {@link System#loadLibrary(String)}.
 * @param libName - The native library path or name
 * @param absolute - Whether the native library will be loaded by path or by name
 */
public static void loadLibrary(String libName, boolean absolute) {
  if (absolute) {
    System.load(libName);
  } else {
    System.loadLibrary(libName);
  }
}

代码示例来源:origin: google/ExoPlayer

/**
 * Returns whether the underlying libraries are available, loading them if necessary.
 */
public synchronized boolean isAvailable() {
 if (loadAttempted) {
  return isAvailable;
 }
 loadAttempted = true;
 try {
  for (String lib : nativeLibraries) {
   System.loadLibrary(lib);
  }
  isAvailable = true;
 } catch (UnsatisfiedLinkError exception) {
  // Do nothing.
 }
 return isAvailable;
}

代码示例来源:origin: stackoverflow.com

class JNIGlue {
  static {
    System.loadLibrary("foo");
  }
}

代码示例来源:origin: stackoverflow.com

static {
  System.loadLibrary("stlport_shared");
  System.loadLibrary("foo");
  System.loadLibrary("bar");
}

代码示例来源:origin: redisson/redisson

/**
 * Delegate the calling to {@link System#load(String)} or {@link System#loadLibrary(String)}.
 * @param libName - The native library path or name
 * @param absolute - Whether the native library will be loaded by path or by name
 */
public static void loadLibrary(String libName, boolean absolute) {
  if (absolute) {
    System.load(libName);
  } else {
    System.loadLibrary(libName);
  }
}

代码示例来源:origin: wildfly/wildfly

/**
 * Delegate the calling to {@link System#load(String)} or {@link System#loadLibrary(String)}.
 * @param libName - The native library path or name
 * @param absolute - Whether the native library will be loaded by path or by name
 */
public static void loadLibrary(String libName, boolean absolute) {
  if (absolute) {
    System.load(libName);
  } else {
    System.loadLibrary(libName);
  }
}

代码示例来源:origin: redisson/redisson

/**
 * Make a call to {@link System#loadLibrary(String)} to load the native library which assumes
 * that the library is available on the path based on this {@link Bundle}'s {@link Manifest}.
 */
public void start(BundleContext context)
    throws Exception
{
  String library = System.mapLibraryName(LIBRARY_NAME);
  if (library.toLowerCase().endsWith(".dylib")) {
    // some MacOS JDK7+ vendors map to dylib instead of jnilib
    library = library.replace(".dylib", ".jnilib");
  }
  System.loadLibrary(library);
  SnappyLoader.setSnappyApi(new SnappyNative());
}

代码示例来源:origin: stackoverflow.com

public class MainActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);

  // A normal textview
  TextView textView = new TextView(getApplicationContext());
  // set the text of textview with the string of shared cpp code
  textView.setText(concateneMyStringWithCppString("Javaaaa"));
  // normal things
  setContentView(textView);

  // only interface things nothng important
  textView.setTextSize(50);
  textView.setTextColor(Color.BLACK);
  textView.setGravity(Gravity.CENTER);
}

// very important
private native String concateneMyStringWithCppString(String myString);
static {
  System.loadLibrary("HelloCpp");
}

}

代码示例来源:origin: stackoverflow.com

public class Main {
  public native int square(int i);
  public static void main(String[] args) {
    System.loadLibrary("Main");
    System.out.println(new Main().square(2));
  }
}

代码示例来源:origin: stackoverflow.com

public class Main {
  public native int intMethod(int i);
  public static void main(String[] args) {
    System.loadLibrary("Main");
    System.out.println(new Main().intMethod(2));
  }
}

代码示例来源:origin: koral--/android-gif-drawable

static void loadLibrary() {
    try {
      System.loadLibrary(BASE_LIBRARY_NAME);
    } catch (final UnsatisfiedLinkError e) {
      ReLinker.loadLibrary(getContext());
    }
  }
}

代码示例来源:origin: stackoverflow.com

class HelloWorld {
private native void print();
public static void main(String[] args) {
  new HelloWorld().print();
}
static {
  System.loadLibrary("HelloWorld");
}  }

代码示例来源:origin: Tencent/tinker

/**
 * only support auto load lib/armeabi library from patch.
 * in some process, you may not want to install tinker
 * and you can load patch dex and library without install tinker!
 */
public static void loadArmLibrary(ApplicationLike applicationLike, String libName) {
  if (libName == null || libName.isEmpty() || applicationLike == null) {
    throw new TinkerRuntimeException("libName or context is null!");
  }
  if (TinkerApplicationHelper.isTinkerEnableForNativeLib(applicationLike)) {
    if (TinkerApplicationHelper.loadLibraryFromTinker(applicationLike, "lib/armeabi", libName)) {
      return;
    }
  }
  System.loadLibrary(libName);
}

代码示例来源:origin: Tencent/tinker

/**
 * The same as {@link #loadArmV7Library(Context, String)} but it can be called before
 * calling {@link TinkerInstaller#install}
 * @param appLike
 * @param libName
 */
public static void loadArmV7LibraryWithoutTinkerInstalled(ApplicationLike appLike, String libName) {
  if (libName == null || libName.isEmpty() || appLike == null) {
    throw new TinkerRuntimeException("libName or appLike is null!");
  }
  if (TinkerApplicationHelper.isTinkerEnableForNativeLib(appLike)) {
    if (TinkerApplicationHelper.loadLibraryFromTinker(appLike, "lib/armeabi-v7a", libName)) {
      return;
    }
  }
  System.loadLibrary(libName);
}

代码示例来源:origin: Tencent/tinker

/**
 * only support auto load lib/armeabi-v7a library from patch.
 * in some process, you may not want to install tinker
 * and you can load patch dex and library without install tinker!
 * }
 */
public static void loadArmV7aLibrary(ApplicationLike applicationLike, String libName) {
  if (libName == null || libName.isEmpty() || applicationLike == null) {
    throw new TinkerRuntimeException("libName or context is null!");
  }
  if (TinkerApplicationHelper.isTinkerEnableForNativeLib(applicationLike)) {
    if (TinkerApplicationHelper.loadLibraryFromTinker(applicationLike, "lib/armeabi-v7a", libName)) {
      return;
    }
  }
  System.loadLibrary(libName);
}

代码示例来源:origin: Tencent/tinker

/**
 * The same as {@link #loadArmLibrary(Context, String)} but it can be called before
 * calling {@link TinkerInstaller#install}
 * @param appLike
 * @param libName
 */
public static void loadArmLibraryWithoutTinkerInstalled(ApplicationLike appLike, String libName) {
  if (libName == null || libName.isEmpty() || appLike == null) {
    throw new TinkerRuntimeException("libName or appLike is null!");
  }
  if (TinkerApplicationHelper.isTinkerEnableForNativeLib(appLike)) {
    if (TinkerApplicationHelper.loadLibraryFromTinker(appLike, "lib/armeabi", libName)) {
      return;
    }
  }
  System.loadLibrary(libName);
}

代码示例来源:origin: Tencent/tinker

/**
 * you can use TinkerInstaller.loadArmV7Library replace your System.loadLibrary for auto update library!
 * only support auto load lib/armeabi-v7a library from patch.
 * for other library in lib/* or assets,
 * you can load through {@code TinkerInstaller#loadLibraryFromTinker}
 */
public static void loadArmV7Library(Context context, String libName) {
  if (libName == null || libName.isEmpty() || context == null) {
    throw new TinkerRuntimeException("libName or context is null!");
  }
  Tinker tinker = Tinker.with(context);
  if (tinker.isEnabledForNativeLib()) {
    if (TinkerLoadLibrary.loadLibraryFromTinker(context, "lib/armeabi-v7a", libName)) {
      return;
    }
  }
  System.loadLibrary(libName);
}

代码示例来源:origin: Tencent/tinker

/**
 * you can use TinkerInstaller.loadLibrary replace your System.loadLibrary for auto update library!
 * only support auto load lib/armeabi library from patch.
 * for other library in lib/* or assets,
 * you can load through {@code TinkerInstaller#loadLibraryFromTinker}
 */
public static void loadArmLibrary(Context context, String libName) {
  if (libName == null || libName.isEmpty() || context == null) {
    throw new TinkerRuntimeException("libName or context is null!");
  }
  Tinker tinker = Tinker.with(context);
  if (tinker.isEnabledForNativeLib()) {
    if (TinkerLoadLibrary.loadLibraryFromTinker(context, "lib/armeabi", libName)) {
      return;
    }
  }
  System.loadLibrary(libName);
}

代码示例来源:origin: libgdx/libgdx

/** Loads a shared library for the platform the application is running on.
 * @param libraryName The platform independent library name. If not contain a prefix (eg lib) or suffix (eg .dll). */
public void load (String libraryName) {
  // in case of iOS, things have been linked statically to the executable, bail out.
  if (isIos) return;
  synchronized (SharedLibraryLoader.class) {
    if (isLoaded(libraryName)) return;
    String platformName = mapLibraryName(libraryName);
    try {
      if (isAndroid)
        System.loadLibrary(platformName);
      else
        loadFile(platformName);
      setLoaded(libraryName);
    } catch (Throwable ex) {
      throw new GdxRuntimeException("Couldn't load shared library '" + platformName + "' for target: "
        + System.getProperty("os.name") + (is64Bit ? ", 64-bit" : ", 32-bit"), ex);
    }
  }
}

代码示例来源:origin: libgdx/libgdx

/** Loads a shared library for the platform the application is running on.
 * @param libraryName The platform independent library name. If not contain a prefix (eg lib) or suffix (eg .dll). */
public void load (String libraryName) {
  // in case of iOS, things have been linked statically to the executable, bail out.
  if (isIos) return;
  synchronized (SharedLibraryLoader.class) {
    if (isLoaded(libraryName)) return;
    String platformName = mapLibraryName(libraryName);
    try {
      if (isAndroid)
        System.loadLibrary(platformName);
      else
        loadFile(platformName);
      setLoaded(libraryName);
    } catch (Throwable ex) {
      throw new GdxRuntimeException("Couldn't load shared library '" + platformName + "' for target: "
        + System.getProperty("os.name") + (is64Bit ? ", 64-bit" : ", 32-bit"), ex);
    }
  }
}

相关文章