Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to remove a class from an imported gradle library?

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.

like image 285
David Avatar asked Feb 20 '20 11:02

David


People also ask

How do you exclude specific classes in dependency gradle?

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.

How do I remove a library from gradle?

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 .

What is the difference between api and implementation scopes in gradle?

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.


1 Answers

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

like image 50
Damien LeBerrigaud Avatar answered Oct 10 '22 04:10

Damien LeBerrigaud