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

React Native 0.63.3项目构建失败:CookieManagerModule未实现invalidate()

解决React Native 0.63.3 Android构建失败:CookieManagerModule未实现invalidate()方法

问题背景

维护的React Native 0.63.3项目未修改任何代码,突然出现Android构建失败,报错如下:

/Users/ME/DIR/CLIENT_NAME/PROJECT_NAME/node_modules/@unimodules/react-native-adapter/android/src/main/java/org/unimodules/adapters/react/services/CookieManagerModule.java:13: error: CookieManagerModule is not abstract and does not override abstract method invalidate() in NativeModule

此前因Kotlin版本不一致警告更换过Kotlin版本,尝试将Gradle发行版从6.2更换为6.9后问题仍未解决。项目buildscript配置如下:

buildscript {
    ext {
        buildToolsVersion = "29.0.2"
        minSdkVersion = 23
        compileSdkVersion = 30
        targetSdkVersion = 30
        googlePlayServicesVersion = "16.+"
        firebaseVersion = "17.6.0"
        androidXAnnotation = "1.1.0"
        androidXBrowser = "1.0.0"
        androidXCore = "1.0.2"
        kotlinVersion = "1.6.10"
    }
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath('com.android.tools.build:gradle:3.5.4')
        classpath 'com.google.gms:google-services:4.3.4'
        classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.10'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

问题原因

  1. 版本不匹配:@unimodules/react-native-adapter版本与React Native 0.63.3不兼容,新版本RN的NativeModule接口新增了invalidate()方法,但旧版unimodules未实现该方法。
  2. Gradle与Kotlin版本冲突:使用的Kotlin 1.6.10版本过高,与React Native 0.63.3对应的Gradle插件3.5.4不兼容;同时Gradle发行版6.9超出了该插件支持的版本范围。

解决方案

1. 锁定适配的@unimodules/react-native-adapter版本

在项目根目录的package.json中,将@unimodules/react-native-adapter版本固定为适配RN 0.63的版本(推荐~5.7.0):

"@unimodules/react-native-adapter": "~5.7.0"

执行命令重新安装依赖:

npm install
# 或使用yarn
yarn install

2. 调整Kotlin与Gradle版本至兼容范围

  • 修改buildscript中的kotlinVersion为1.3.72(与Gradle插件3.5.4兼容):
kotlinVersion = "1.3.72"
  • 修改gradle/wrapper/gradle-wrapper.properties中的distributionUrl为Gradle 5.6.4(Gradle插件3.5.4对应的推荐发行版):
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.4-all.zip

3. 清理缓存并重新构建

执行以下命令清理缓存,避免残留依赖影响构建:

# 删除node_modules
rm -rf node_modules
# 清理Android构建缓存
cd android && ./gradlew clean
# 清除npm缓存
npm cache clean --force
# 或清除yarn缓存
# yarn cache clean
# 回到根目录重新安装依赖
cd .. && npm install
# 重新构建Android项目
cd android && ./gradlew assembleDebug

内容的提问来源于stack exchange,提问作者Mathias Bradiceanu

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.13 15:31:01