/** * 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); } }
/** * 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; }
class JNIGlue { static { System.loadLibrary("foo"); } }
static { System.loadLibrary("stlport_shared"); System.loadLibrary("foo"); System.loadLibrary("bar"); }
/** * 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); } }
/** * 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); } }
/** * 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()); }
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"); } }
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)); } }
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)); } }
static void loadLibrary() { try { System.loadLibrary(BASE_LIBRARY_NAME); } catch (final UnsatisfiedLinkError e) { ReLinker.loadLibrary(getContext()); } } }
class HelloWorld { private native void print(); public static void main(String[] args) { new HelloWorld().print(); } static { System.loadLibrary("HelloWorld"); } }
/** * 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); }
/** * 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); }
/** * 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); }
/** * 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); }
/** * 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); }
/** * 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); }
/** 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); } } }
/** 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); } } }