Search code examples
androidgradlekotlinandroid-testingandroidx

Release build variant failed with debugImplementation for "androidx.fragment:fragment-testing" library


Expected

Debug and release build variants of the app to build and compile successfully.

Observed

In the release build variant the app does not compile due to the androidx.fragment:fragment-testing library.

Library implementation

build.gradle (:app)

debugImplementation "androidx.fragment:fragment-testing:1.2.2"

The full implementation can be found in the GitHub repository for Coinverse.

Error

The build fails due to unresolved references to androidx libraries.

i.e. import androidx.activity.viewModels, import androidx.lifecycle.AbstractSavedStateViewModelFactory, import androidx.lifecycle.SavedStateHandle, import androidx.lifecycle.lifecycleScope, import androidx.fragment.app.activityViewModels, and etc.

Environment details

  • Gradle version: 3.6.1
  • Android Studio: 3.6.1
  • Build #AI-192.7142.36.36.6241897
  • Runtime version: 1.8.0_212-release-1586-b4-5784211 x86_64
  • VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
  • macOS 10.15.3
  • GC: ParNew, ConcurrentMarkSweep
  • Memory: 1979M
  • Cores: 16
  • Registry: ide.new.welcome.screen.force=true
  • Non-Bundled Plugins: com.android.tool.sizereduction.plugin, mobi.hsz.idea.gitignore, org.jetbrains.kotlin, cn.wjdghd.unique.plugin.id, com.developerphil.adbidea, com.google.services.firebase

Solution

  • The app builds and compiles as expected in the release build variant when adding the following library.

    implementation "androidx.fragment:fragment-ktx:$fragment_version"

    This library was present in earlier releases, but recently removed as everything was working as expected in the debug build variant without it.

    Now fragment-testing may be edited to use debugImplementation.

    debugImplementation "androidx.fragment:fragment-testing:1.2.2"