Reputation: 14206
Is it, or would it be possible to modify a libraries' packagename at compile time using a gradle task similar to how jarjar works for changing the packagenames of a .jar file.
The library is pretty standard and included as follows:
dependencies {
compile 'com.scottyab:rootbeer-lib:0.0.6'
}
The purpose of this would be to change the name to avoid static detection of the library by root cloaking apps.
Any advice or guidance much appreciated! Thanks
Upvotes: 1
Views: 1678
Reputation: 1149
There is already a Gradle plugin that does something similar. It relocates dependencies, Shadow.
It bundles and relocates common dependencies in libraries to avoid classpath conflicts.Shadow uses the ASM library to modify class byte code to replace the package name and any import statements for a class. Any non-class files that are stored within a package structure are also relocated to the new location.
This is how you relocate a package:
shadowJar {
relocate 'junit.framework', 'shadow.junit'
}
The code snippet will rewrite the location for any class in the junit.framework to be shadow.junit. For example, the class junit.textui.TestRunner becomes shadow.junit.TestRunner. In the resulting JAR, the class file is relocated from junit/textui/TestRunner.class to shadow/junit/TestRunner.class.
Upvotes: 1
Reputation: 1149
There is already a Gradle plugin that does something similar. It relocates dependencies, Shadow.
It bundles and relocates common dependencies in libraries to avoid classpath conflicts.Shadow uses the ASM library to modify class byte code to replace the package name and any import statements for a class. Any non-class files that are stored within a package structure are also relocated to the new location.
This is how you relocate a package:
shadowJar {
relocate 'junit.framework', 'shadow.junit'
}
The code snippet will rewrite the location for any class in the junit.framework to be shadow.junit. For example, the class junit.textui.TestRunner becomes shadow.junit.TestRunner. In the resulting JAR, the class file is relocated from junit/textui/TestRunner.class to shadow/junit/TestRunner.class.
Upvotes: 2
Reputation: 5348
I can see the library you are using is an open source library. You can simply clone the repo from here https://github.com/scottyab/rootbeer and modify it to use any name you want. You don't even need to build your changes as a aar library. Simply import it as a module in Android Studio.
Gradle tasks are very powerful as well and it should be possible to do it with gradle but I don't know how.
Upvotes: 0