React Native项目Android Gradle构建失败(react-native-reanimated报错)
Hey there, let's work through this build error you're facing after installing react-native-material-ripple. The error points to line 89 in react-native-reanimated's build.gradle, and it's almost certainly related to path parsing issues or dependency conflicts. Here are the most likely fixes:
1. Move Your Project to a Path Without Special Characters
Looking at your project path: C:\Users\D'errah\Documents\Code\React\dowProjectMatcher — the single quote in D'errah is probably tripping up Gradle's path parsing. Groovy (which Gradle uses) treats single quotes as literal string delimiters, so paths with embedded single quotes often cause syntax errors.
- Create a new folder without special characters (e.g.,
C:\Users\Derrah\Documents\Code\React\dowProjectMatcher) - Copy all your project files to this new location
- Reinstall dependencies and rebuild with these commands:
rmdir /s /q node_modules npm cache clean --force npm install cd android && gradlew clean npm run android
2. Clean Caches and Rebuild Dependencies
Corrupted caches can sometimes cause unexpected build issues, even if the code itself looks correct. Try these steps:
- Delete your project's
node_modulesfolder - Clear npm's cache:
npm cache clean --force - Delete Gradle caches:
- Remove the
android/.gradlefolder in your project - Remove the global Gradle cache at
C:\Users\<YourUsername>\.gradle
- Remove the
- Reinstall dependencies and rebuild:
npm install cd android && gradlew clean npm run android
3. Check React Native Reanimated Compatibility
react-native-material-ripple might be pulling in a version of react-native-reanimated that's incompatible with your React Native version. Here's how to fix that:
- Look up the compatible
react-native-reanimatedversion for your React Native release (match versions based on official compatibility notes) - Lock the version in your
package.json, for example:"react-native-reanimated": "^2.10.0" - Reinstall dependencies and rebuild:
rmdir /s /q node_modules npm install cd android && gradlew clean npm run android
4. Temporary Fix: Modify the Reanimated Build.gradle
If moving your project isn't an option right now, you can patch the problematic line to handle the single quote in your path:
Open node_modules/react-native-reanimated/android/build.gradle and replace line 89:
classpath += files(android.bootClasspath)
With:
classpath += files(android.bootClasspath.collect { it.toString().replace("'", "\\'") })
This escapes the single quote in the path so Gradle can parse it correctly. Note that this change will be overwritten if you reinstall dependencies, so it's only a short-term fix.
Why This Happens
Gradle uses Groovy for its build scripts, and embedded single quotes in file paths break string parsing logic. When Gradle tries to resolve android.bootClasspath, it's pulling in system paths that include your user directory with the single quote, leading to the syntax error.
内容的提问来源于stack exchange,提问作者Dee

