ReLinker


Source link: https://github.com/KeepSafe/ReLinker


ReLinker

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.

Installation

ReLinker is distributed using jcenter.

repositories {

 jcenter()
 
}

  dependencies {

 compile 'com.getkeepsafe.relinker:relinker:1.2.3'
 
}

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. 

Resources

Common re-usable module repository for the convenience of Android application development.

HorizontalPicker is an open source android library that enables users to select single item by scrolling or tapping left and right to move between an array of items.

A practical and easy-to-use Android application to apply several filters to an image at once.

Features:

  • Applying several filters
  • Undoing filters one by one
  • Maintaining maximum image quality
  • Taking photos using camera or choosing from SD-Card

Filters: Boost-Up Colors, Brightness, Color Depth, Color Filter, Contrast, Emboss, Flip and Rotation, Gamma, Gaussian Blur, Grayscale, Hue, Invert, Noise, Saturation, Sepia, Sharpen, Sketch, Tint, Vignette

Simple events bus (publish–subscribe) implementation based on regular Android BroadcastReceivers mechanism.

The recommended pattern for Android's equivalent to cron jobs and Windows scheduled tasks is to use AlarmManager. This works well when coupled with an IntentService, as the service will do its work on a background thread and shut down when there is no more work to do.

There's one small problem: IntentService does nothing to keep the device awake. If the alarm was a WAKEUP variant, the phone will only stay awake on its own while the BroadcastReceiver handling the alarm is in its onReceive() method. Otherwise, the phone may fall back asleep.

WakefulIntentService attempts to combat this by combining the ease of IntentService with a partial WakeLock.

ViewPager with custom aspect ratio.

Topics


2D Engines   3D Engines   9-Patch   Action Bars   Activities   ADB   Advertisements   Analytics   Animations   ANR   AOP   API   APK   APT   Architecture   Audio   Autocomplete   Background Processing   Backward Compatibility   Badges   Bar Codes   Benchmarking   Bitmaps   Bluetooth   Blur Effects   Bread Crumbs   BRMS   Browser Extensions   Build Systems   Bundles   Buttons   Caching   Camera   Canvas   Cards   Carousels   Changelog   Checkboxes   Cloud Storages   Color Analysis   Color Pickers   Colors   Comet/Push   Compass Sensors   Conferences   Content Providers   Continuous Integration   Crash Reports   Credit Cards   Credits   CSV   Curl/Flip   Data Binding   Data Generators   Data Structures   Database   Database Browsers   Date &   Debugging   Decompilers   Deep Links   Dependency Injections   Design   Design Patterns   Dex   Dialogs   Distributed Computing   Distribution Platforms   Download Managers   Drawables   Emoji   Emulators   EPUB   Equalizers &   Event Buses   Exception Handling   Face Recognition   Feedback &   File System   File/Directory   Fingerprint   Floating Action   Fonts   Forms   Fragments   FRP   FSM   Functional Programming   Gamepads   Games   Geocaching   Gestures   GIF   Glow Pad   Gradle Plugins   Graphics   Grid Views   Highlighting   HTML   HTTP Mocking   Icons   IDE   IDE Plugins   Image Croppers   Image Loaders   Image Pickers   Image Processing   Image Views   Instrumentation   Intents   Job Schedulers   JSON   Keyboard   Kotlin   Layouts   Library Demos   List View   List Views   Localization   Location   Lock Patterns   Logcat   Logging   Mails   Maps   Markdown   Mathematics   Maven Plugins   MBaaS   Media   Menus   Messaging   MIME   Mobile Web   Native Image   Navigation   NDK   Networking   NFC   NoSQL   Number Pickers   OAuth   Object Mocking   OCR Engines   OpenGL   ORM   Other Pickers   Parallax List   Parcelables   Particle Systems   Password Inputs   PDF   Permissions   Physics Engines   Platforms   Plugin Frameworks   Preferences   Progress Indicators   ProGuard   Properties   Protocol Buffer   Pull To   Purchases   Push/Pull   QR Codes   Quick Return   Radio Buttons   Range Bars   Ratings   Recycler Views   Resources   REST   Ripple Effects   RSS   Screenshots   Scripting   Scroll Views   SDK   Search Inputs   Security   Sensors   Services   Showcase Views   Signatures   Sliding Panels   Snackbars   SOAP   Social Networks   Spannable   Spinners   Splash Screens   SSH   Static Analysis   Status Bars   Styling   SVG   System   Tags   Task Managers   TDD &   Template Engines   Testing   Testing Tools   Text Formatting   Text Views   Text Watchers   Text-to   Toasts   Toolkits For   Tools   Tooltips   Trainings   TV   Twitter   Updaters   USB   User Stories   Utils   Validation   Video   View Adapters   View Pagers   Views   Watch Face   Wearable Data   Wearables   Weather   Web Tools   Web Views   WebRTC   WebSockets   Wheel Widgets   Wi-Fi   Widgets   Windows   Wizards   XML   XMPP   YAML   ZIP Codes