1

I am trying to migrate from Android gradle plugin 2.3.3 to 3.0. I have a 2 projects set up where tests in ProjectB uses the test classes present in src/test/java from ProjectA. I utilizes the following setup to achieve this while using android gradle plugin 2.3.3 -

ProjectA build.gradle -

task myTestsJar(type: Jar, dependsOn: testClasses) {
   from sourceSets.test.output      
}

configurations {
  testArtifacts
}

artifacts {
   testArtifacts myTestsJar
}

ProjectB build.gradle -

dependencies {
  testCompile project(path: ':ProjectA', configuration: 'testArtifacts')
}

As you can see I am first trying to Jar all the test classes in ProjectA by using an artificat configuation and then later consuming that configuration in ProjectB. This was working as expected while using Android gradle pluign 2.3.3.

Now when migrating to AGP 3.0, my ProjectA build.gradle remains same though I have modified the projectB build.gradle to use testImplementation instead of testCompile like this -

dependencies {
      testImplementation project(path: ':ProjectA', configuration: 'testArtifacts')
}

This successfully compiles though while running any tests in ProjectB that utilizes test classes from ProjectA, I get a ClassNotFoundException for ProjectA test classes. Moreover this only happens while I am running tests in Android Studio using a Junit run configuration and no such ClassNotFoundException occurs when running tests through command line.

I am not sure what I am doing wrong while trying to get it work. So please help!

1 Answer 1

1

Turned out it was something related to Gradle cache and I solved this by deleting my project's .gradle directory.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.