All Projects → KeepSafe → Relinker

KeepSafe / Relinker

Licence: apache-2.0
A robust native library loader for Android.

Programming Languages

java
68154 projects - #9 most used programming language

Projects that are alternatives of or similar to Relinker

Keepalive
Fighting against force-stop kill process on Android with binder ioctl / Android高级保活
Stars: ✭ 376 (-85.6%)
Mutual labels:  ndk, jni
Android Luajit Launcher
Android NativeActivity based launcher for LuaJIT, implementing the main loop within Lua land via FFI
Stars: ✭ 87 (-96.67%)
Mutual labels:  ndk, jni
Hp Socket
High Performance TCP/UDP/HTTP Communication Component
Stars: ✭ 4,420 (+69.22%)
Mutual labels:  ndk, android-ndk
Mwengine
Audio engine and DSP for Android, written in C++ providing low latency performance in a musical context, supporting both OpenSL and AAudio.
Stars: ✭ 190 (-92.73%)
Mutual labels:  ndk, android-ndk
Jpegkit Android
Efficient JPEG operations for Android without the risk of an OutOfMemoryException.
Stars: ✭ 154 (-94.1%)
Mutual labels:  ndk, jni
Jnioor
基于C++模板函数与Fluent API设计的JNI反射库,极大的简化JNI反射调用,提高JNI开发效率与稳定性
Stars: ✭ 278 (-89.36%)
Mutual labels:  ndk, jni
Bugsnag Android Ndk
DEPRECATED - this project now lives at bugsnag/bugsnag-android
Stars: ✭ 42 (-98.39%)
Mutual labels:  ndk, android-ndk
Camera2GLPreview
Android camera preview application using Camera2 API and OpenGL ES/Vulkan
Stars: ✭ 140 (-94.64%)
Mutual labels:  ndk, jni
Androiddevwithcpp
Android Develop With C++
Stars: ✭ 106 (-95.94%)
Mutual labels:  ndk, jni
Termux Ndk
android-ndk for termux
Stars: ✭ 91 (-96.52%)
Mutual labels:  ndk, android-ndk
Jni4android
JNI Generater for Android
Stars: ✭ 261 (-90.01%)
Mutual labels:  ndk, jni
Native Opencv Android Template
A tutorial for setting up OpenCV 4.5.0 (and other 4.x.y version) for Android in Android Studio with Native Development Kit (NDK) support.
Stars: ✭ 131 (-94.98%)
Mutual labels:  ndk, jni
SecurityDemo
ndk进行简单的签名校验,密钥保护demo,android应用签名校验
Stars: ✭ 22 (-99.16%)
Mutual labels:  ndk, jni
Jni.hpp
A modern, type-safe, header-only, C++14 wrapper for JNI
Stars: ✭ 313 (-88.02%)
Mutual labels:  ndk, jni
premake-android-studio
premake5 module for android-studio and gradle build.
Stars: ✭ 24 (-99.08%)
Mutual labels:  ndk, jni
Anyndk
🔥 Android native library, make your development faster and easier. Android各种native库,让你的开发更快更简单
Stars: ✭ 35 (-98.66%)
Mutual labels:  ndk, jni
ChangeVoice
NDK语音消息的变声处理
Stars: ✭ 33 (-98.74%)
Mutual labels:  ndk, jni
NativeGL demo
此程序使用android native代码实现EGL,并使用SurfaceView作为OpenGL绘图窗口。即可提高图形渲染性能,又可使用java层定义的图形界面
Stars: ✭ 43 (-98.35%)
Mutual labels:  ndk, jni
Ndcrash
A powerful crash reporting library for Android NDK. Don't forget to run git submodule update --init --recursive after checking out.
Stars: ✭ 91 (-96.52%)
Mutual labels:  ndk, android-ndk
Googleserialport
Android串口通信:抱歉,学会它真的可以为所欲为 ! ! !
Stars: ✭ 130 (-95.02%)
Mutual labels:  ndk, jni

ReLinker
ReLinker

Build Status Maven Central Release

A robust native library loader for Android. More information can be found in our blog post

Min SDK: 9

JavaDoc

Overview

The Android PackageManager's native library loading is unreliable. Occasionally when using native libraries, you will encounter a stack trace like this:

java.lang.UnsatisfiedLinkError: Couldn't load stlport_shared from loader dalvik.system.PathClassLoader: findLibrary returned null
at java.lang.Runtime.loadLibrary(Runtime.java:365)
at java.lang.System.loadLibrary(System.java:535)
at com.your.app.NativeClass.<clinit>(Native.java:16)
... 63 more

Caused by: java.lang.UnsatisfiedLinkError: Library stlport_shared not found
at java.lang.Runtime.loadLibrary(Runtime.java:461)
at java.lang.System.loadLibrary(System.java:557)
at com.your.app.NativeClass.<clinit>(Native.java:16)
... 5 more

ReLinker fixes these issues by replacing the standard System.loadLibrary call with a more reliable implementation.

Note that this library fixes intermittent link errors; if you get an error every time you use your app, you may have a configuration issue. See this StackOverflow question for more information.

Who needs ReLinker?

If your app includes native libraries, and your minimum SDK is below API 23 (Marshmallow), you need ReLinker.

There are a number of different bugs addressed by ReLinker; the last of these was resolved as of Marshmallow. As long as your app's min SDK is at or above it, loading libraries via System.loadLibrary("foo") is safe.

Installation

ReLinker is distributed using MavenCentral.

   repositories { 
        mavenCentral()
   }
   
   dependencies {
         compile 'com.getkeepsafe.relinker:relinker:x.x.x'
   }

If you wish, you may also use ReLinker with jitpack

Usage

Simply replace a call to System.loadLibrary like this:

System.loadLibrary("mylibrary");

With a call to ReLinker.loadLibrary like this:

ReLinker.loadLibrary(context, "mylibrary");

Advanced Usage

Asynchronous loading

ReLinker can load libraries asynchronously. Simply pass a LoadListener instance to the loadLibrary call:

ReLinker.loadLibrary(context, "mylibrary", new ReLinker.LoadListener() {
    @Override
    public void success() { /* Yay */ }

    @Override
    public void failure(Throwable t) { /* Boo */ }
});

Recursive loading

On older versions of Android, the system's library loader may fail to resolve intra-library dependencies. In this instance, ReLinker can resolve those dependencies for you. This will recursively load all libraries defined as "needed" by each library.

For example, if you have a library libchild that relies on libparent, then libchild will have an entry in its shared object file defining that. ReLinker will parse the shared object file and determine that libchild needs libparent. ReLinker will then proceed to load libparent (and any dependencies it may have) and then libchild.

To allow ReLinker to recursively load and resolve intra-library dependencies simply modify your loadLibrary call with the recursively modifier, like so:

ReLinker.recursively().loadLibrary(context, "mylibrary");

Logging

To help facilitate debugging, ReLinker can log messages to a Logger instance you provide:

ReLinker.log(myLogger).loadLibrary(context, "mylibrary");

Which will log the following messages during a normal / successful execution:

D/ReLinker: Beginning load of mylibrary...
D/ReLinker: mylibrary was not loaded normally, re-linking...
D/ReLinker: Looking for lib/x86/libmylibrary.so in APK...
D/ReLinker: Found lib/x86/libmylibrary.so! Extracting...
D/ReLinker: mylibrary was re-linked!

Versioning

In the event that your library's code is changed, it is a good idea to specify a specific version. Doing so will allow ReLinker to update the workaround library file successfully. In the case that the system handles the library loading appropriately, the version specified is not used as all library files are extracted and replaced on update or install.

To specify a version for your library simply provide it as an additional parameter for loadLibrary like:

ReLinker.loadLibrary(context, "mylibrary", "1.0");

This will cause ReLinker to look for, and load libmylibrary.so.1.0. Subsequent version updates will automatically clean up all other library versions.

Sample application

See the sample application under sample/ for a quick demo.

Acknowledgements

Special thanks to Jeff Young for the awesome logo!

License

Copyright 2015 - 2016 Keepsafe Software Inc.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].