Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android fragment-testing dependency causes release build to fail compilation

I followed the android tutorial on testing fragments and added the gradle dependency as debugImplementation

    def fragmentVersion = "1.2.5"
    implementation "androidx.fragment:fragment-ktx:$fragmentVersion"
    debugImplementation "androidx.fragment:fragment-testing:$fragmentVersion"

Now my release unit test task won't compile because the methods that i call to launch fragments don't exist on the release classpath..


> Task :app:compileReleaseUnitTestKotlin FAILED
e: C:\Users\....kt: (5, 30): Unresolved reference: testing
e: C:\Users\....kt: (58, 9): Unresolved reference: launchFragmentInContainer
e: C:\Users\....kt: (65, 9): Unresolved reference: launchFragmentInContainer

I understand why they make it debug only, so you don't have the testing stuff in your release build. But how do I fix this compilation issue?

like image 973
OliverDeLange Avatar asked Sep 14 '25 07:09

OliverDeLange


1 Answers

Facing the same problem I ended up with the following workaround:

Use the depency as suggested in the documentation:

debugImplementation "androidx.fragment:fragment-testing:$fragmentVersion"

Then I moved all my tests that depend on lib androidx.fragment:fragment-testing at the testDebug flavor.

Pros:

  • Can build and test both for debug and release

Cons:

  • Lower code coverage for release :(
  • Minification errors that may caught without that requirement it will not :(

This is how the project structure looks after that:

enter image description here

like image 121
madlymad Avatar answered Sep 16 '25 23:09

madlymad