androidgradleandroid-gradle-plugin

java.lang.NoClassDefFoundError: Failed resolution of: Landroidx/work/R when updating Gradle Android Plugin


I started updating dependencies for an older project of mine, but then noticed that the app does not start after some dep updates - it thows a java.lang.NoClassDefFoundError: Failed resolution of: Landroidx/work/R$bool exception. This might happen because on startup I reschedule a Worker to do some periodic IO.

I narrowed it down to the com.android.tools.build:gradle:3.5.1 -> com.android.tools.build:gradle:3.6.1 change in build.gradle and this does correspond with the docs but that does not help much.

A bit more context about the current set up where the problem occurs:

EDIT 1: I tried removing the androidx:work package uses and the this exception is thrown by another support library from the androidx group. This points me to there being some there being some other funky class processing going on.

EDIT 2: I've found the solution, and this would apply to any android.support libraries - a gradle plugin realm-android was messing up the build, so updating it seems to have fixed the problem. Similar problems might occur with other code-generating plugins.

Any tips on how to approach this would be appreciated


Solution

  • As the OP sayed, it could be any other plugin or dependency as well. In my case, the error came from the ObjectBox plugin.

    Updating ObjectBox from 2.5 to 2.6 solved the issue for me.

    objectboxVersion = '2.6.0'
    

    However, I needed to add the following lines to my build.gradle for ObjectBox to work again.

        kotlinOptions {
            jvmTarget = JavaVersion.VERSION_1_8
        }