安装rn-fetch-blob后React Native 0.62.2安卓构建失败求助
Hey there, let's work through this build failure together. The "无法删除目录" (failed to delete directory) error in the :app:processDebugResources task usually ties to cached build files, process locks, or compatibility mismatches between rn-fetch-blob, your Gradle version, and JDK setup. Here are the steps to resolve it:
Step 1: Clean Up Build Caches and Dependencies
First, let's wipe out any corrupted cached files and reinstall dependencies:
- Stop all running processes related to your project: close the Android emulator, shut down the Metro bundler, and end any Java/Gradle processes in your task manager.
- Run these commands in your project root:
For Windows users, use these commands instead:# Navigate to Android directory cd android # Clean Gradle build files ./gradlew clean # Go back to root cd .. # Remove node modules and lock file rm -rf node_modules rm package-lock.json # Reinstall dependencies npm installcd android gradlew clean cd .. rmdir /s /q node_modules del package-lock.json npm install
Step 2: Verify rn-fetch-blob Version Compatibility
React Native 0.62.2 is an older version, so not all rn-fetch-blob releases will work smoothly with it. Try downgrading to a version known to be compatible, like v0.12.0:
- Update your
package.jsonto set"rn-fetch-blob": "^0.12.0" - Run
npm installagain, then retryreact-native run-android
Step 3: Release Locked Directories
The "无法删除目录" error often happens because a system process is holding onto files in your Android build folder. To fix this:
- Windows: Open Task Manager, go to the "Details" tab, look for any
java.exeorgradlew.exeprocesses related to your project, and end them. - Mac/Linux: Use the
lsofcommand to find the process locking the directory (replace<path-to-build-dir>with your actualandroid/app/buildpath):
Then kill the process using its PID:lsof | grep <path-to-build-dir>kill -9 <PID>
Step 4: Adjust JDK and Gradle Setup
React Native 0.62.x officially recommends JDK 8 or 11, and JDK 13 might have compatibility issues with Gradle 6.3. Try switching to JDK 11:
- Install JDK 11 and update your system's
JAVA_HOMEenvironment variable to point to the JDK 11 installation. - Double-check that your
android/gradle/wrapper/gradle-wrapper.propertiesfile hasdistributionUrl=https\://services.gradle.org/distributions/gradle-6.3-all.zipto match your local Gradle version.
Step 5: Verify rn-fetch-blob Linking
While React Native 0.60+ uses auto-linking, sometimes manual linking can resolve hidden issues. Run this command to ensure rn-fetch-blob is properly linked:
react-native link rn-fetch-blob
Then run ./gradlew clean again before rebuilding.
If none of these steps work, try creating a fresh React Native 0.62.2 project, install rn-fetch-blob, and test the build. This will help you rule out any custom configuration issues in your original project.
内容的提问来源于stack exchange,提问作者Efosa

