I'm searching and trying already one day long to remove a class from an imported library over gradle without really getting it to work, should this be possible with Android+gradle? How to do this?
For example if I include a library like so:
implementation 'org.bouncycastle:bcpkix-jdk15on:1.64'
How to remove a class by name from it? The latest thing I tried was setting in build.gradle:
android {
sourceSets.main.java.filter.exclude '**/QTeslaKeyEncodingTests.*'
}
Following also doesn't work:
jar {
sourceSets {
main {
java {
exclude '**/QTeslaKeyEncodingTests.java'
exclude '**/QTeslaKeyEncodingTests.class'
}
}
}
}
This also doesn't:
android{
packagingOptions {
exclude 'org.bouncycastle/pqc/crypto/qtesla/QTeslaKeyEncodingTests.class'
}
}
Context: why do I need this currently: when you execute "gradlew testDebug" all tests in the project run, including those present in the imported libs. I also don't know if this is a bug from bouncyCastle that they included those tests in the library but it's a problem because many tests fail.
If you just want to exclude one class for a dependency jar, take a look at the jar jar links tool and its Gradle plugin. It allows you to alter included jars, e.g. to change packages or remove classes.
gradle file and then delete it from the project structure. Show activity on this post. Go to File > Project Structure > Select the module in modules and press minus(-) on the top left. This will remove the library but you will have to manually remove the files form your project .
The api configuration should be used to declare dependencies which are exported by the library API, whereas the implementation configuration should be used to declare dependencies which are internal to the component.
Exclude a specific package from the instrumentation tests (connectedAndroidTest
gradle task) with the notPackage
option.
For example:
android {
defaultConfig {
testInstrumentationRunnerArguments = ["notPackage": "com.example.somelibrary"]
}
}
There are plenty of potential options for filtering. The official documentation that documents all of them is at -
https://developer.android.com/reference/androidx/test/runner/AndroidJUnitRunner
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With