React Native多库包名冲突致react-native-device-info构建失败求助
Hey there, let's work through these two React Native project issues you're hitting:
问题1:存在多个包名为react native的库
This usually happens when your dependencies have conflicting versions or duplicate entries of React Native-related packages. Here's how to fix it:
- Clean your project cache first: Run
npx react-native start --reset-cacheto clear the Metro bundler cache. Then delete thenode_modulesfolder and lock file withrm -rf node_modules package-lock.json yarn.lock(adjust for Windows:rmdir /s node_modulesand delete the lock files manually). - Audit your package.json: Check for duplicate entries of packages like
react-nativeor any related libraries. Make sure you only have one declared version ofreact-nativein your dependencies. - Reinstall dependencies: Run
npm installoryarn installbased on your package manager, then rebuild your project withnpx react-native run-android(or iOS if needed).
问题2:
:react-native-device-info:processReleaseResources失败(多com.google.android.gms.license库冲突) This conflict typically arises because different native dependencies are pulling in different versions of Google Play Services libraries. Try these steps:
- Force a unified Google Play Services version: Add this to your
android/build.gradlefile under theallprojectsblock, replacing the version with the one compatible with your project:subprojects { project.configurations.all { resolutionStrategy.eachDependency { details -> if (details.requested.group == 'com.google.android.gms') { details.useVersion '17.0.0' // Use the version that works for your setup } } } } - Exclude conflicting dependencies from react-native-device-info: If forcing the version doesn't work, modify your
android/app/build.gradleto exclude the conflicting license library from the package:implementation(project(':react-native-device-info')) { exclude group: 'com.google.android.gms', module: 'license' } - Clean Gradle caches: Run
cd android && ./gradlew clean && ./gradlew build --refresh-dependenciesto wipe old Gradle artifacts and refresh dependencies. - Update react-native-device-info: Make sure you're using the latest stable version of the package, as newer versions often fix dependency conflicts. Run
npm update react-native-device-infooryarn upgrade react-native-device-info.
内容的提问来源于stack exchange,提问作者Atif Aziz
相关产品推荐
相关产品推荐

