java.lang.NullPointerException: Cannot invoke "String.length()" because "<parameter1>" is null
Asked Answered
C

7

9

Today I was not able to compile my application. This is the error that I obtain if I try to Rebuild my project.

java.lang.NullPointerException: Cannot invoke "String.length()" because "<parameter1>" is null

Execution failed for task ':app:dexBuilderDebug'.
 Could not resolve all files for configuration ':app:detachedConfiguration18'.
    Failed to transform jetified-appcompat-resources-1.7.0-beta01-runtime.jar to match attributes {artifactType=ext-dex-dexBuilderDebug, org.gradle.libraryelements=jar, org.gradle.usage=java-runtime}.
       Execution failed for DexingExternalLibArtifactTransform: C:\Users\John Doe\.gradle\caches\transforms-3\a17cb0bdbb9802eb5b30084992aad901\transformed\jetified-appcompat-resources-1.7.0-beta01-runtime.jar.
          Error while dexing.
    Failed to transform appcompat-1.7.0-beta01-runtime.jar to match attributes {artifactType=ext-dex-dexBuilderDebug, org.gradle.libraryelements=jar, org.gradle.usage=java-runtime}.
       Execution failed for DexingExternalLibArtifactTransform: C:\Users\John Doe\.gradle\caches\transforms-3\cb6538e8f72401bf3ec35fdf09737324\transformed\appcompat-1.7.0-beta01-runtime.jar.
          Error while dexing.

enter image description here

enter image description here

enter image description here

Any ideas on what could be wrong?

Cristen answered 2/5, 2024 at 8:12 Comment(3)
Not sure but if you get a more complete error (run the Gradle command with flag -s) it could shed some more lightWhitsuntide
We are getting the same error this morning, hopefully someone finds a solution!Watthour
For all those are still looking for solution use Java 17 and gradle version 8.3.1. I was also facing same issue and resolved it this way.Hockenberry
R
4

I added following code in app build.gradle after reviewing error details. Details were as following

Could not resolve all files for configuration ':app:stagingDebugRuntimeClasspath'. > Failed to transform core-1.14.0-alpha01.aar (androidx.core:core:1.14.0-alpha01) to match attributes.

Possible Fix:

configurations.all {
        resolutionStrategy {
            force("androidx.core:core-ktx:1.9.0")
        }
    }
Rashid answered 2/5, 2024 at 13:8 Comment(0)
A
2

On our side, the problem comes from the "react-native-google-fit" package which uses the latest version of appcompat in android/build.gradle:

dependencies {
     def supportLibVersion = safeExtGet('supportLibVersion', null)
     def androidXVersion = safeExtGet('androidXVersion', null)

     implementation fileTree(include: ['*.jar'], dir: 'libs')
     implementation('com.facebook.react:react-native:+') {
         exclude group: 'com.android.support'
     }
     if (supportLibVersion && androidXVersion == null) {
         implementation "com.android.support:appcompat-v7:$supportLibVersion"
     } else {
         def defaultAndroidXVersion = "1.+"
         implementation "androidx.appcompat:appcompat:${safeExtGet(androidXVersion, defaultAndroidXVersion)}"
     }
     implementation "com.google.android.gms:play-services-auth:${safeExtGet('authVersion', '+')}"
     implementation "com.google.android.gms:play-services-fitness:${safeExtGet('fitnessVersion', '+')}"
}

The latest version 1.7.0-beta01 seems to be causing problems with our build configuration.

While waiting to find the solution, I made this temporary patch, just replace react-native-google-fit in your package.json:

"react-native-google-fit": "0.20.0" by "react-native-google-fit": "IlanAMG/react-native-google-fit"

(https://github.com/IlanAMG/react-native-google-fit)

run yarn and it works.

Follow the same method on the problematic package on your side or in your android/build.gradle

This is just a temporary patch for today

Ambassadress answered 2/5, 2024 at 13:19 Comment(1)
Thanks! It works. I dont understand why these errors keep on araising.Aileen
S
0

I solved it by upgrading to gradle 8 using the automatic version updater. Then you'll have to fix a few more cascading bugs that are minor tweaks to the build.gradle and manifest.xml. Keep commenting and I'll let you know.

Scrimmage answered 2/5, 2024 at 12:59 Comment(0)
D
0

TLDR: lock your dependency versions: replace '+' in your gradle files with a specific version.

Regarding the "today I was not able to compile my application" part of the question, we faced the same issue. Last Wednesday it was building fine, and the next day the build failed, without any source code changes. Even for previously released versions, we couldn't build it.

This is so disturbing, and in hindsight it's clear that somewhere there a non-locked version for some dependency. In one of our modules, in gradle we were using:

dependencies {
    ...
    implementation 'androidx.core:core-ktx:+'
    ...

and '+' means 'any version' (https://docs.gradle.org/current/userguide/single_versions.html). So the build was downloading a new (released last week) version 1.14.0-alpha01 that is incompatible with our project somehow.

The fix for us was changing to a fixed static version like androidx.core:core-ktx:1.13.1, (took the latest stable version from https://developer.android.com/jetpack/androidx/releases/core#1.13.1).

There are some arguments for not locking versions completely if your project is a library, but locking dependency versions for applications allows reproducible builds which is critical IMO.

The question seems to be asking about the same problem but in a different library (appcompat?), so I assume that the fix is to search which dependencies are using '+' and replace that with a specific version according to that libraries' release notes.


In the (unlikely?) case all your versions are fixed and that the problematic non-fixed dependency is imported by one of your dependencies, you can try to import it directly in your gradle with a specific version.

Denounce answered 7/5, 2024 at 16:40 Comment(0)
R
0

First things first make sure your gradle-wrapper.properties has the gradle version of 8.4, check the below line

distributionUrl=https://services.gradle.org/distributions/gradle-8.4-bin.zip

Secondly, the version of agp should be agp = "8.1.1" or any other android studio recommends, in my case 8.1.1 worked.

Roundhead answered 19/7, 2024 at 7:10 Comment(0)
M
0

Problem solved after upgrading Android Studio to the latest version (Android Studio Koala | 2024.1.1 Patch 1) and upgrading Android Gradle Plugin to version 8.5.1.

Minyan answered 24/7, 2024 at 19:0 Comment(0)
Q
0

I got this issue. After updated build.gradle(root folder) with appcombat version of 1.6.1 it work as expected.

  configurations.all {
    resolutionStrategy {
        force 'androidx.appcompat:appcompat:1.6.1'
    }
}
Quilting answered 23/9, 2024 at 22:55 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.