4

I have an Android project that is now failing to build:

FAILURE: Build failed with an exception.

* Where:
Build file 'build.gradle' line: 28

* What went wrong:
A problem occurred evaluating root project 'X'.
> java.lang.NoClassDefFoundError: com/android/build/gradle/internal/ToolingRegistryProvider

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

The project was building fine with the following dependencies:

'com.android.tools.build:gradle:2.1.3'
'com.android.tools.build:gradle-experimental:0.7.3'

A coworker applied the updates offered by AndroidStudio. That changed the plugin versions to:

'com.android.tools.build:gradle:2.2.0'
'com.android.tools.build:gradle-experimental:0.8.0'

After this update, the project builds successfully on his development machine (Windows 7) and on mine (Ubuntu 16.04). The error occurs on the Jenkins build server (Ubuntu 16.04). I installed the available updates to the Android SDK components on the build server but the error persists.

A google search for "ToolingRegistryProvider" returns "Your search matches no documents".

dsh
  • 12,037
  • 3
  • 33
  • 51

4 Answers4

2

The problem was resolved by deleting gradle's module cache on the build server and then letting the build re-download everything.

rm -r ~/.gradle/caches/modules-2
dsh
  • 12,037
  • 3
  • 33
  • 51
1

Adding my solution to this issue: I added jcenter() to the top-level repositories tag.

We use a Nexus server that hosts lots of libraries we use here at work. So when it tried to update the gradle plugin version, it tried to do so from the Nexus server and for some reason, the update pulled the correct version but with some changes, making the gradle version and the gradle plugin version not to be in sync. So by adding jcenter() the gradle plugin was updated correctly and this error vanished.

David Rawson
  • 20,912
  • 7
  • 88
  • 124
Alon Minski
  • 1,571
  • 2
  • 19
  • 32
1

This error can come from not having the Google Maven Repository as a repository in your build.gradle file:

allprojects {
    repositories {
        google()

        // If you're using a version of Gradle lower than 4.1, you must instead use:
        // maven {
        //     url 'https://maven.google.com'
        // }
        // An alternative URL is 'https://dl.google.com/dl/android/maven2/'
    }
}

See this link for more information.

David Rawson
  • 20,912
  • 7
  • 88
  • 124
0

I had the same experience with JetpackCompose compose multiplatform Project structure

android/
    |
    - build.gradle.kts
desktop/
    |
    - build.gradle.kts
common/
    |
    - build.gradle.kts
buildSrc/
    |
    - build.gradle.kts 

Common required id("com.android.library") But was getting NoClassFound errors I had to add

buildSrc/build.gradle.kts

    // ...
    repositories{
        mavenLocal()
        mavenCentral()
        google()
    }
    dependencies{
       compileOnly("com.android.tools.build:gradle:7.0.4")
    }
    // ...

Also, make sure to have.

google() in the allprojects section or in specific build.gradle.kts files. Class might actually be missing.

Breimer
  • 506
  • 8
  • 14