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

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

本文整理了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

  1. /**
  2. * Delegate the calling to {@link System#load(String)} or {@link System#loadLibrary(String)}.
  3. * @param libName - The native library path or name
  4. * @param absolute - Whether the native library will be loaded by path or by name
  5. */
  6. public static void loadLibrary(String libName, boolean absolute) {
  7. if (absolute) {
  8. System.load(libName);
  9. } else {
  10. System.loadLibrary(libName);
  11. }
  12. }

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

  1. /**
  2. * Returns whether the underlying libraries are available, loading them if necessary.
  3. */
  4. public synchronized boolean isAvailable() {
  5. if (loadAttempted) {
  6. return isAvailable;
  7. }
  8. loadAttempted = true;
  9. try {
  10. for (String lib : nativeLibraries) {
  11. System.loadLibrary(lib);
  12. }
  13. isAvailable = true;
  14. } catch (UnsatisfiedLinkError exception) {
  15. // Do nothing.
  16. }
  17. return isAvailable;
  18. }

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

  1. class JNIGlue {
  2. static {
  3. System.loadLibrary("foo");
  4. }
  5. }

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

  1. static {
  2. System.loadLibrary("stlport_shared");
  3. System.loadLibrary("foo");
  4. System.loadLibrary("bar");
  5. }

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

  1. /**
  2. * Delegate the calling to {@link System#load(String)} or {@link System#loadLibrary(String)}.
  3. * @param libName - The native library path or name
  4. * @param absolute - Whether the native library will be loaded by path or by name
  5. */
  6. public static void loadLibrary(String libName, boolean absolute) {
  7. if (absolute) {
  8. System.load(libName);
  9. } else {
  10. System.loadLibrary(libName);
  11. }
  12. }

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

  1. /**
  2. * Delegate the calling to {@link System#load(String)} or {@link System#loadLibrary(String)}.
  3. * @param libName - The native library path or name
  4. * @param absolute - Whether the native library will be loaded by path or by name
  5. */
  6. public static void loadLibrary(String libName, boolean absolute) {
  7. if (absolute) {
  8. System.load(libName);
  9. } else {
  10. System.loadLibrary(libName);
  11. }
  12. }

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

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

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

  1. public class MainActivity extends Activity {
  2. @Override
  3. protected void onCreate(Bundle savedInstanceState) {
  4. super.onCreate(savedInstanceState);
  5. // A normal textview
  6. TextView textView = new TextView(getApplicationContext());
  7. // set the text of textview with the string of shared cpp code
  8. textView.setText(concateneMyStringWithCppString("Javaaaa"));
  9. // normal things
  10. setContentView(textView);
  11. // only interface things nothng important
  12. textView.setTextSize(50);
  13. textView.setTextColor(Color.BLACK);
  14. textView.setGravity(Gravity.CENTER);
  15. }
  16. // very important
  17. private native String concateneMyStringWithCppString(String myString);
  18. static {
  19. System.loadLibrary("HelloCpp");
  20. }
  21. }

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

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

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

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

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

  1. static void loadLibrary() {
  2. try {
  3. System.loadLibrary(BASE_LIBRARY_NAME);
  4. } catch (final UnsatisfiedLinkError e) {
  5. ReLinker.loadLibrary(getContext());
  6. }
  7. }
  8. }

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

  1. class HelloWorld {
  2. private native void print();
  3. public static void main(String[] args) {
  4. new HelloWorld().print();
  5. }
  6. static {
  7. System.loadLibrary("HelloWorld");
  8. } }

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

  1. /**
  2. * only support auto load lib/armeabi library from patch.
  3. * in some process, you may not want to install tinker
  4. * and you can load patch dex and library without install tinker!
  5. */
  6. public static void loadArmLibrary(ApplicationLike applicationLike, String libName) {
  7. if (libName == null || libName.isEmpty() || applicationLike == null) {
  8. throw new TinkerRuntimeException("libName or context is null!");
  9. }
  10. if (TinkerApplicationHelper.isTinkerEnableForNativeLib(applicationLike)) {
  11. if (TinkerApplicationHelper.loadLibraryFromTinker(applicationLike, "lib/armeabi", libName)) {
  12. return;
  13. }
  14. }
  15. System.loadLibrary(libName);
  16. }

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

  1. /**
  2. * The same as {@link #loadArmV7Library(Context, String)} but it can be called before
  3. * calling {@link TinkerInstaller#install}
  4. * @param appLike
  5. * @param libName
  6. */
  7. public static void loadArmV7LibraryWithoutTinkerInstalled(ApplicationLike appLike, String libName) {
  8. if (libName == null || libName.isEmpty() || appLike == null) {
  9. throw new TinkerRuntimeException("libName or appLike is null!");
  10. }
  11. if (TinkerApplicationHelper.isTinkerEnableForNativeLib(appLike)) {
  12. if (TinkerApplicationHelper.loadLibraryFromTinker(appLike, "lib/armeabi-v7a", libName)) {
  13. return;
  14. }
  15. }
  16. System.loadLibrary(libName);
  17. }

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

  1. /**
  2. * only support auto load lib/armeabi-v7a library from patch.
  3. * in some process, you may not want to install tinker
  4. * and you can load patch dex and library without install tinker!
  5. * }
  6. */
  7. public static void loadArmV7aLibrary(ApplicationLike applicationLike, String libName) {
  8. if (libName == null || libName.isEmpty() || applicationLike == null) {
  9. throw new TinkerRuntimeException("libName or context is null!");
  10. }
  11. if (TinkerApplicationHelper.isTinkerEnableForNativeLib(applicationLike)) {
  12. if (TinkerApplicationHelper.loadLibraryFromTinker(applicationLike, "lib/armeabi-v7a", libName)) {
  13. return;
  14. }
  15. }
  16. System.loadLibrary(libName);
  17. }

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

  1. /**
  2. * The same as {@link #loadArmLibrary(Context, String)} but it can be called before
  3. * calling {@link TinkerInstaller#install}
  4. * @param appLike
  5. * @param libName
  6. */
  7. public static void loadArmLibraryWithoutTinkerInstalled(ApplicationLike appLike, String libName) {
  8. if (libName == null || libName.isEmpty() || appLike == null) {
  9. throw new TinkerRuntimeException("libName or appLike is null!");
  10. }
  11. if (TinkerApplicationHelper.isTinkerEnableForNativeLib(appLike)) {
  12. if (TinkerApplicationHelper.loadLibraryFromTinker(appLike, "lib/armeabi", libName)) {
  13. return;
  14. }
  15. }
  16. System.loadLibrary(libName);
  17. }

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

  1. /**
  2. * you can use TinkerInstaller.loadArmV7Library replace your System.loadLibrary for auto update library!
  3. * only support auto load lib/armeabi-v7a library from patch.
  4. * for other library in lib/* or assets,
  5. * you can load through {@code TinkerInstaller#loadLibraryFromTinker}
  6. */
  7. public static void loadArmV7Library(Context context, String libName) {
  8. if (libName == null || libName.isEmpty() || context == null) {
  9. throw new TinkerRuntimeException("libName or context is null!");
  10. }
  11. Tinker tinker = Tinker.with(context);
  12. if (tinker.isEnabledForNativeLib()) {
  13. if (TinkerLoadLibrary.loadLibraryFromTinker(context, "lib/armeabi-v7a", libName)) {
  14. return;
  15. }
  16. }
  17. System.loadLibrary(libName);
  18. }

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

  1. /**
  2. * you can use TinkerInstaller.loadLibrary replace your System.loadLibrary for auto update library!
  3. * only support auto load lib/armeabi library from patch.
  4. * for other library in lib/* or assets,
  5. * you can load through {@code TinkerInstaller#loadLibraryFromTinker}
  6. */
  7. public static void loadArmLibrary(Context context, String libName) {
  8. if (libName == null || libName.isEmpty() || context == null) {
  9. throw new TinkerRuntimeException("libName or context is null!");
  10. }
  11. Tinker tinker = Tinker.with(context);
  12. if (tinker.isEnabledForNativeLib()) {
  13. if (TinkerLoadLibrary.loadLibraryFromTinker(context, "lib/armeabi", libName)) {
  14. return;
  15. }
  16. }
  17. System.loadLibrary(libName);
  18. }

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

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

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

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

相关文章