
Developing our Mobile Bank, we once encountered such a
problem .
Namely: when using the GSON library for serialization / deserialization to / from JSON on some devices from HTC in runtime, we received a crash. The reason for this behavior is that some HTC devices have in their firmware their own version of GSON, which is older than the one we used in our projects. And the Androids java class loader, when loading a class into memory, prefers the “system” version instead of the version in the project.
In addition, on some devices there is a similar problem with OkHttp - also quite a popular library in the world of Android development.
')
To solve the problem, you need to repack GSON (or any other library) using the
JarJar utility. After repacking, the artifact will have a new package structure that must be used in import directives in your project. To do this, you need to connect the repacked jar to your project instead of the original one.
We wanted to automate this task and eventually the
Gradle JarJar Plugin appeared , available at
Maven Central . The plugin allows you to specify jar-libraries and rules for repacking them with JarJar.
Add the plugin to the dependencies of the script:
buildscript { repositories { jcenter() } dependencies { classpath 'ru.tinkoff.gradle:jarjar:1.1.0' } }
We connect it in the project module:
apply plugin: 'ru.tinkoff.gradle.jarjar'
Specify the list of artifacts for repackaging:
dependencies {
Customize:
jarJar {