Search code examples
react-nativegradlecachingandroid-gradle-pluginmetro-bundler

React-native android build fails due to missing files in the gradle cache?


I am currently working on a react-native for ios and android. I wanted to add 4 new packages (react-native-gesture-handler, react-native-reanimated, react-native-safe-area-context and @gorhom/bottom-sheet) which then caused me some trouble when installing so I switched to another package which would replace these 4 without any trouble.
The problem now is that even after rolling back the project to exactly how it was before, it's still crashing when running npm run-android with the error:

> [email protected] android
> react-native run-android

info Running jetifier to migrate libraries to AndroidX. You can disable it using "--no-jetifier" flag.
Jetifier found 1001 file(s) to forward-jetify. Using 8 workers...
info JS server already running.
info Launching emulator...
info Successfully launched emulator.
info Installing the app...
> Task :app:checkDebugAarMetadata FAILED

Deprecated Gradle features were used in this build, making it incompatible with Gradle 8.0.

You can use '--warning-mode all' to show the individual deprecation warnings and determine if they come from your own scripts or plugins.

See https://docs.gradle.org/7.3.3/userguide/command_line_interface.html#sec:command_line_warnings
12 actionable tasks: 2 executed, 10 up-to-date

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:checkDebugAarMetadata'.
> Multiple build operations failed.
      java.nio.file.NoSuchFileException: /Users/private/.gradle/caches/transforms-3/acdba564cab10d0f31716104c08ecbee/results.bin
      java.nio.file.NoSuchFileException: /Users/private/.gradle/caches/transforms-3/0051ba15206e71d5f2b7a6f0ed776860/results.bin
      java.nio.file.NoSuchFileException: /Users/private/.gradle/caches/transforms-3/4e2e869708901347ef158aa1a9aed1f4/results.bin
      java.nio.file.NoSuchFileException: /Users/private/.gradle/caches/transforms-3/f684783603be85eb4c827960e04e8a60/results.bin
      java.nio.file.NoSuchFileException: /Users/private/.gradle/caches/transforms-3/e027a88f08932b9116d6e1bd45f24a79/results.bin
      java.nio.file.NoSuchFileException: /Users/private/.gradle/caches/transforms-3/c08ba6ec0daadcde11699fa34d40b295/results.bin
      java.nio.file.NoSuchFileException: /Users/private/.gradle/caches/transforms-3/c0b89d21d6409c50b59e277bb5915751/results.bin
      java.nio.file.NoSuchFileException: /Users/private/.gradle/caches/transforms-3/f38a0e4adb2cb6c27096544b7d9f257a/results.bin
      java.nio.file.NoSuchFileException: /Users/private/.gradle/caches/transforms-3/49b1d43dd024794a47163e54aa8a0a89/results.bin
      java.nio.file.NoSuchFileException: /Users/private/.gradle/caches/transforms-3/52f1cba1c3b05bb59b006a525e2f4d4d/results.bin
      ...and 87 more failures.
   > java.nio.file.NoSuchFileException: /Users/private/.gradle/caches/transforms-3/acdba564cab10d0f31716104c08ecbee/results.bin
   > java.nio.file.NoSuchFileException: /Users/private/.gradle/caches/transforms-3/0051ba15206e71d5f2b7a6f0ed776860/results.bin
   > java.nio.file.NoSuchFileException: /Users/private/.gradle/caches/transforms-3/22f4e52b551ac1cfb5cd025e9c5de9c1/results.bin
   > java.nio.file.NoSuchFileException: /Users/private/.gradle/caches/transforms-3/d4405dbab538bff995a2a0c862019c94/results.bin
   [... and so on for about ~50 more files]

* 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.

* Get more help at https://help.gradle.org

BUILD FAILED in 4s

error Failed to install the app. Make sure you have the Android development environment set up: https://reactnative.dev/docs/environment-setup.
Error: Command failed: ./gradlew app:installDebug -PreactNativeDevServerPort=8081

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:checkDebugAarMetadata'.
> Multiple build operations failed.
      java.nio.file.NoSuchFileException: /Users/private/.gradle/caches/transforms-3/acdba564cab10d0f31716104c08ecbee/results.bin
      java.nio.file.NoSuchFileException: /Users/private/.gradle/caches/transforms-3/0051ba15206e71d5f2b7a6f0ed776860/results.bin
      java.nio.file.NoSuchFileException: /Users/private/.gradle/caches/transforms-3/4e2e869708901347ef158aa1a9aed1f4/results.bin
      java.nio.file.NoSuchFileException: /Users/private/.gradle/caches/transforms-3/f684783603be85eb4c827960e04e8a60/results.bin
      java.nio.file.NoSuchFileException: /Users/private/.gradle/caches/transforms-3/e027a88f08932b9116d6e1bd45f24a79/results.bin
      java.nio.file.NoSuchFileException: /Users/private/.gradle/caches/transforms-3/c08ba6ec0daadcde11699fa34d40b295/results.bin
      java.nio.file.NoSuchFileException: /Users/private/.gradle/caches/transforms-3/c0b89d21d6409c50b59e277bb5915751/results.bin
      java.nio.file.NoSuchFileException: /Users/private/.gradle/caches/transforms-3/f38a0e4adb2cb6c27096544b7d9f257a/results.bin
      java.nio.file.NoSuchFileException: /Users/private/.gradle/caches/transforms-3/49b1d43dd024794a47163e54aa8a0a89/results.bin
      java.nio.file.NoSuchFileException: /Users/private/.gradle/caches/transforms-3/52f1cba1c3b05bb59b006a525e2f4d4d/results.bin
      ...and 87 more failures.
   > java.nio.file.NoSuchFileException: /Users/private/.gradle/caches/transforms-3/acdba564cab10d0f31716104c08ecbee/results.bin
   > java.nio.file.NoSuchFileException: /Users/private/.gradle/caches/transforms-3/0051ba15206e71d5f2b7a6f0ed776860/results.bin
   > java.nio.file.NoSuchFileException: /Users/private/.gradle/caches/transforms-3/22f4e52b551ac1cfb5cd025e9c5de9c1/results.bin
   > java.nio.file.NoSuchFileException: /Users/private/.gradle/caches/transforms-3/d4405dbab538bff995a2a0c862019c94/results.bin
   [... and so on for about ~50 more files]

* 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.

* Get more help at https://help.gradle.org

BUILD FAILED in 4s

    at makeError (/Volumes/privateWorkspace/hbmggmbh/LF2Frontend/node_modules/@react-native-community/cli-platform-android/node_modules/execa/index.js:174:9)
    at /Volumes/privateWorkspace/hbmggmbh/LF2Frontend/node_modules/@react-native-community/cli-platform-android/node_modules/execa/index.js:278:16
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async runOnAllDevices (/Volumes/privateWorkspace/hbmggmbh/LF2Frontend/node_modules/@react-native-community/cli-platform-android/build/commands/runAndroid/runOnAllDevices.js:109:5)
    at async Command.handleAction (/Volumes/privateWorkspace/hbmggmbh/LF2Frontend/node_modules/@react-native-community/cli/build/index.js:192:9)
info Run CLI with --verbose flag for more details.

During the time as I was fixing the other errors I got when trying to implement the 4 packages I was talking about I ran rm -r $HOME/.gradle/caches/ which was a solution I found here on stackoverflow and worked at the time. Since it's just deleting the cache I didnt think much of it.

The project now "runs" on:

"dependencies": {
    "prop-type": "^0.0.1",
    "react": "18.0.0",
    "react-native": "0.69.0",
    "react-native-geolocation-service": "^5.3.0",
    "react-native-maps": "^0.31.1"
  },
  "devDependencies": {
    "@babel/core": "^7.12.9",
    "@babel/runtime": "^7.12.5",
    "@react-native-community/eslint-config": "^2.0.0",
    "babel-jest": "^26.6.3",
    "eslint": "^7.32.0",
    "jest": "^26.6.3",
    "metro-react-native-babel-preset": "^0.70.3",
    "react-native-sass-transformer": "^2.0.0",
    "react-test-renderer": "18.0.0"
  }

Versions used by me:

------------------------------------------------------------
Gradle 7.4.2
------------------------------------------------------------

Build time:   2022-03-31 15:25:29 UTC
Revision:     540473b8118064efcc264694cbcaa4b677f61041

Kotlin:       1.5.31
Groovy:       3.0.9
Ant:          Apache Ant(TM) version 1.10.11 compiled on July 10 2021
JVM:          18.0.1.1 (Homebrew 18.0.1.1+0)
OS:           Mac OS X 12.1 x86_64

List of things I tried to fix this:

  • Reinstall gradle
  • Reinstall android studio and all of my emulators
  • Running gradle --build-cache
  • Running gradle cleanBuildCache
    • This resulted in a Task 'cleanBuildCache' not found in root project 'LF2Frontend'. error
  • Removing node_modules/ and package-lock.json and then running npm i again
  • Clearing react-native cache
  • Clearing npm cache
  • And most desperately: I tried copying the gradle cache .gradle/caches/transforms-3/ from one of my teammates into my cache folder, hoping this might do something.

At this point I am completely lost and also very confused how something like this could even happen.
Does anyone know how to help with this? Thanks in advance


Solution

  • I was in exact same situation after performing rm -rf ~/.gradle/caches/.

    Eventually solved it by removing the entire ~/.gradle folder, not just caches subdirectory.

    Then, after running react-native run-android again, React Native started with rebuilding Gradle artifacts automatically. Then my RN Android builds were successful again.

    Hope this helps!