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

安装react-native-reanimated@3.12.0后Android项目编译失败求助

解决react-native-reanimated ^3.12.0 与RN 0.72.7的Android编译错误

问题描述

安装react-native-reanimated@^3.12.0后,构建React Native Android项目时出现编译错误,具体报错信息如下:

Deprecated Gradle features were used in this build, making it incompatible with Gradle 9.0.

You can use '--warning-mode all' to show the individual deprecation warnings and determine if they come from your own scripts or plugins.

See https://docs.gradle.org/8.0.1/userguide/command_line_interface.html#sec:command_line_warnings
157 actionable tasks: 2 executed, 155 up-to-date

info 💡 Tip: Make sure that you have set up your development environment correctly, by running react-native doctor. To read more about doctor command visit: https://github.com/react-native-community/cli/blob/main/packages/cli-doctor/README.md#doctor 

/Users/olabanjoolakunori/Documents/PersonalReactNativeProjects/Plant_Brunch/node_modules/react-native-reanimated/android/src/reactNativeVersionPatch/ReactHost/72/com/swmansion/reanimated/DevMenuUtils.java:5: error: cannot find symbol
    private void addDevMenuOption(ReactApplicationContext context, DevOptionHandler handler) {
                                  ^
  symbol:   class ReactApplicationContext
  location: class DevMenuUtils
/Users/olabanjoolakunori/Documents/PersonalReactNativeProjects/Plant_Brunch/node_modules/react-native-reanimated/android/src/reactNativeVersionPatch/ReactHost/72/com/swmansion/reanimated/DevMenuUtils.java:5: error: cannot find symbol
    private void addDevMenuOption(ReactApplicationContext context, DevOptionHandler handler) {
                                                                   ^
  symbol:   class DevOptionHandler
  location: class DevMenuUtils
/Users/olabanjoolakunori/Documents/PersonalReactNativeProjects/Plant_Brunch/node_modules/react-native-reanimated/android/src/main/java/com/swmansion/reanimated/nativeProxy/NativeProxyCommon.java:85: error: addDevMenuOption(ReactApplicationContext,DevOptionHandler) has private access in DevMenuUtils
    DevMenuUtils.addDevMenuOption(mContext.get(), this::toggleSlowAnimations);
                ^
/Users/olabanjoolakunori/Documents/PersonalReactNativeProjects/Plant_Brunch/node_modules/react-native-reanimated/android/src/reactNativeVersionPatch/ReactHost/72/com/swmansion/reanimated/DevMenuUtils.java:7: error: cannot find symbol
    if (context.getApplicationContext() instanceof ReactApplication) {
                                                   ^
  symbol:   class ReactApplication
  location: class DevMenuUtils
/Users/olabanjoolakunori/Documents/PersonalReactNativeProjects/Plant_Brunch/node_modules/react-native-reanimated/android/src/reactNativeVersionPatch/ReactHost/72/com/swmansion/reanimated/DevMenuUtils.java:8: error: cannot find symbol
      final DevSupportManager devSupportManager =
            ^
  symbol:   class DevSupportManager
  location: class DevMenuUtils
/Users/olabanjoolakunori/Documents/PersonalReactNativeProjects/Plant_Brunch/node_modules/react-native-reanimated/android/src/reactNativeVersionPatch/ReactHost/72/com/swmansion/reanimated/DevMenuUtils.java:9: error: cannot find symbol
          ((ReactApplication) context.getApplicationContext())
            ^
  symbol:   class ReactApplication
  location: class DevMenuUtils
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
6 errors

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':react-native-reanimated:compileDebugJavaWithJavac'.
> Compilation failed; see the compiler error output for details.

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 27s here

已尝试的无效方案

在Android根目录的build.gradle中添加强制RN版本的配置,但问题未解决:

allprojects {
    repositories { /* ... */ }
    configurations.all {
        resolutionStrategy {
            force 'com.facebook.react:react-native:0.72.7'
        }
    }
}

项目环境

  • React Native版本:0.72.7
  • react-native doctor检测结果:
Common
 ✓ Node.js - Required to execute JavaScript code
 ✓ npm - Required to install NPM dependencies
 ✓ Watchman - Used for watching changes in the filesystem when in development mode

Android
 ✓ Adb - Required to verify if the android device is attached correctly
 ✓ JDK - Required to compile Java code
 ✓ Android Studio - Required for building and installing your app on Android
 ✖ Android SDK - Required for building and installing your app on Android
   - Versions found: N/A
   - Version supported: 33.0.0
 ✓ ANDROID_HOME - Environment variable that points to your Android SDK installation

iOS
 ✓ Xcode - Required for building and installing your app on iOS
 ✓ Ruby - Required for installing iOS dependencies
 ✓ CocoaPods - Required for installing iOS dependencies
 ✓ ios-deploy - Required for installing your app on a physical device with the CLI
 ✖ .xcode.env - File to customize Xcode environment

有效解决方案

方案1:降级react-native-reanimated到兼容版本

react-native-reanimated 3.12.0对RN 0.72.x的兼容性存在问题,降级到3.10.1版本:

  • 卸载当前版本:npm uninstall react-native-reanimated
  • 安装指定版本:npm install react-native-reanimated@3.10.1
  • 清理缓存并重新构建:
    cd android && ./gradlew clean
    cd .. && npx react-native run-android
    

方案2:手动修复编译错误(不降级)

如果不想降级版本,可直接修改依赖包内的代码:

  1. 打开文件node_modules/react-native-reanimated/android/src/reactNativeVersionPatch/ReactHost/72/com/swmansion/reanimated/DevMenuUtils.java
  2. 在文件顶部添加缺失的导入语句:
    import com.facebook.react.ReactApplication;
    import com.facebook.react.ReactApplicationContext;
    import com.facebook.react.devsupport.DevSupportManager;
    import com.facebook.react.devsupport.DevOptionHandler;
    
  3. 将private void addDevMenuOption方法的修饰符改为public static(因为NativeProxyCommon.java中需要调用这个静态方法)
  4. 重新执行构建:npx react-native run-android

方案3:修复Android SDK环境问题

react-native doctor检测到Android SDK 33.0.0缺失,这可能间接导致依赖解析异常:

  1. 打开Android Studio,进入SDK Manager
  2. 安装Android SDK 33.0.0及对应的构建工具
  3. 重新运行npx react-native doctor确认问题修复
  4. 清理缓存后重新构建项目

内容的提问来源于stack exchange,提问作者Olabanjo Olakunori

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.22 18:05:19