admin管理员组

文章数量:1310420

'm facing an issue while building my Android project with Gradle. The build fails with a NullPointerException related to error_prone_annotations-2.36.0.jar. Here’s the full error message:

ERROR: C:\Users\habib\.gradle\caches\transforms-3\e646cb792b71c76b98054fc8aca82c16\transformed\jetified-error_prone_annotations-2.36.0.jar: 

D8: java.lang.NullPointerException: Cannot invoke "String.length()" because "" is null

FAILURE: Build failed with an exception.

What went wrong: Execution failed for task ':app:mergeExtDexDebug'. Could not resolve all files for configuration ':app:debugRuntimeClasspath'.

Failed to transform error_prone_annotations-2.36.0.jar (com.google.errorprone:error_prone_annotations:2.36.0) to match attributes {artifactType=android-dex, asm-transformed-variant=NONE, dexing-enable-desugaring=true, dexing-enable-jacoco-instrumentation=false, dexing-is-debuggable=true, dexing-min-sdk=21, .gradle.category=library, .gradle.libraryelements=jar, .gradle.status=release, .gradle.usage=java-runtime}. Execution failed for DexingWithClasspathTransform: C:\Users\habib.gradle\caches\transforms-3\e646cb792b71c76b98054fc8aca82c16\transformed\jetified-error_prone_annotations-2.36.0.jar. > Error while dexing.

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

BUILD FAILED in 1m 40s Error: Gradle task assembleDebug failed with exit code 1

'm facing an issue while building my Android project with Gradle. The build fails with a NullPointerException related to error_prone_annotations-2.36.0.jar. Here’s the full error message:

ERROR: C:\Users\habib\.gradle\caches\transforms-3\e646cb792b71c76b98054fc8aca82c16\transformed\jetified-error_prone_annotations-2.36.0.jar: 

D8: java.lang.NullPointerException: Cannot invoke "String.length()" because "" is null

FAILURE: Build failed with an exception.

What went wrong: Execution failed for task ':app:mergeExtDexDebug'. Could not resolve all files for configuration ':app:debugRuntimeClasspath'.

Failed to transform error_prone_annotations-2.36.0.jar (com.google.errorprone:error_prone_annotations:2.36.0) to match attributes {artifactType=android-dex, asm-transformed-variant=NONE, dexing-enable-desugaring=true, dexing-enable-jacoco-instrumentation=false, dexing-is-debuggable=true, dexing-min-sdk=21, .gradle.category=library, .gradle.libraryelements=jar, .gradle.status=release, .gradle.usage=java-runtime}. Execution failed for DexingWithClasspathTransform: C:\Users\habib.gradle\caches\transforms-3\e646cb792b71c76b98054fc8aca82c16\transformed\jetified-error_prone_annotations-2.36.0.jar. > Error while dexing.

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

BUILD FAILED in 1m 40s Error: Gradle task assembleDebug failed with exit code 1

Share Improve this question asked Feb 3 at 7:40 Mohamed HeshamMohamed Hesham 537 bronze badges
Add a comment  | 

6 Answers 6

Reset to default 3

Add this code to ignore all errorprone.. add it in android/build.gradle inside allprojects

 configurations.all {
    exclude group: "com.google.errorprone", module: "error_prone_annotations"
}

Exclude error_prone_annotations in android/build.gradle

 subprojects { subproject ->
        if(project['name'] == 'c72-rfid-scanner'){    
            project.configurations { compile { } }
        }else{
            configurations.all {
            exclude group: "com.google.errorprone", module: "error_prone_annotations"
             }
        }
    }

This error is often caused by an incompatibility between the version of error_prone_annotations that’s being pulled in (in this case 2.36.0) and the desugaring process performed by D8. In other words, even though the dependency is present in your runtime classpath, it isn’t actually needed and is causing D8 to crash when transforming it. One common workaround is to force a different (typically older) version of error_prone_annotations that is known to work with your current build setup. For example, you can add a resolution strategy to your top-level build.gradle to force an earlier version (such as 2.5.1):

configurations.all {
    resolutionStrategy.eachDependency { DependencyResolveDetails details ->
        if (details.requested.group == "com.google.errorprone" &&
            details.requested.name == "error_prone_annotations") {
            details.useVersion "2.5.1"
        }
    }
}

Another option is to exclude error_prone_annotations from the dependencies that don’t require it at runtime. For instance, if a particular library is pulling it in transitively and you don’t need it for your app’s execution, you can do the following:

dependencies {
    implementation('com.example.some-library:version') {
         exclude group: "com.google.errorprone", module: "error_prone_annotations"
    }
}

It’s also a good idea to verify that your Android Gradle Plugin version and Gradle version are compatible with the libraries you are using. Although you may have already set your wrapper to use Gradle 8.10.2, some plugins (or transitive dependencies like error_prone_annotations) might force a downgrade to ensure compatibility. Updating your AGP to a version that officially supports Gradle 8.x (or applying the exclusion/resolution strategy above) should resolve the issue.

I have found something that has worked for me on https://issuetracker.google/issues/342522142 in comment 8. That is an internal bug and you can solve by adding these lines at the top of your android/settings.gradle :

pluginManagement {
    buildscript {
        repositories {
            mavenCentral()
            maven {
                url = uri("https://storage.googleapis/r8-releases/raw")
            }
        }
        dependencies {
            classpath("com.android.tools:r8:8.1.44")
        }
    }
}

I hope it will helpful to you as it has been for me.

You are having issues for the 'com.google.errorprone' library during the dexing process. Maybe there are conflicts or issues for this package.

configurations.all {
exclude group: 'com.google.errorprone', module: 'error_prone_annotations'}

Add this into your build.gradle (app level), and it will exclude this package in the build process.

I faced an issue where my project, which was working fine before, suddenly stopped building successfully. To fix this, I added the following code inside the dependencies block in my build.gradle file :

dependencies {
    ///add this code here ...
    configurations.all {
    exclude group: 'com.google.errorprone', module: 'error_prone_annotations'
    }
    ///end...
}

本文标签: javaGradle Build Failed NullPointerException in errorproneannotations2360jar during DexingStack Overflow