You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Android 5.1(Lollipop)国产设备运行React Native项目失败求助

Fixing React Native Build Failures on Android 5.1 (Lollipop)

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’s android/app/build.gradle and look for the minSdkVersion line. 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 clean in the android folder 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 your package.json for 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 clean
    

    Then try launching the app again with npx react-native run-android.

  • Check for aggressive build optimizations
    If the failing project has minifyEnabled or shrinkResources turned on in build.gradle without 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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.19 03:29:25