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?
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.
This is how the project structure looks after that:
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