Android 5.1(Lollipop)国产设备运行React Native项目失败求助
Hey, I’ve run into this exact scenario before—one RN project runs fine on an old Android device, another (same "type") bombs out with that vague "BUILD FAILED" error. Let’s dig into the most likely fixes, since the problem’s almost certainly in the second project’s setup, not your device:
Double-check the minimum SDK requirement
Android 5.1 corresponds to API level 22. Pop open your failing project’sandroid/app/build.gradleand look for theminSdkVersionline. If it’s set to 23 or higher, that’s the issue—your device can’t meet the minimum bar. Change it to 22, then run./gradlew cleanin theandroidfolder and rebuild the project.Match React Native versions to your device’s OS
Newer RN versions (like 0.70+) dropped support for Android versions below API 23. If your working project uses an older RN release (say 0.68.x, which supports down to API 21) but the failing one is on a newer version, that’s a conflict. You can either downgrade the failing project’s RN version or add compatibility polyfills for missing Android APIs.Audit native dependencies
The second project might be using a native module that requires a higher API level. Scan yourpackage.jsonfor libraries like camera, location, or biometric tools—many of these started requiring API 23+. Try replacing those modules with older, compatible versions, or check their docs for a way to configure them to work with API 22.Wipe build caches (they’re often the culprit)
Stale cache files can cause random inconsistencies between projects. Run these commands in your project root:cd android && ./gradlew clean cd .. && npx react-native cleanThen try launching the app again with
npx react-native run-android.Check for aggressive build optimizations
If the failing project hasminifyEnabledorshrinkResourcesturned on inbuild.gradlewithout proper ProGuard rules, it might be stripping code that Android 5.1 needs. Disable those flags temporarily to test, or update your ProGuard config to keep essential classes for older OS versions.Debug with a fresh test project
Spin up a brand new RN project and run it on your device. If that works, the problem is isolated to your second project’s specific setup. Start copying files/components from the failing project to the new one incrementally—this will help you pinpoint exactly which part is breaking the build.
If none of these steps fix it, share the full error log (the lines right after "FAILURE: Build failed with an exception.")—the actual error details will tell us exactly what’s going wrong, instead of just that something went wrong.
内容的提问来源于stack exchange,提问作者Lollo

