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

使用React Native Navigation时配置react-native-safe-area-context报错求助

React Native 构建错误(react-native-safe-area-context 相关)

构建失败,出现异常。
出错原因:
配置项目':react-native-safe-area-context'时出现问题。

无法解析配置':react-native-safe-area-context:classpath'的所有文件。

无法下载kotlin-gradle-plugin-1.6.20.jar(org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.20)

无法获取资源'https://repo.maven.apache.org/maven2/org/jetbrains/kotlin/kotlin-gradle-plugin/1.6.20/kotlin-gradle-plugin-1.6.20.jar'。

无法发送GET请求到该资源地址。

未知主机(repo.maven.apache.org)
其余kotlin相关依赖(kotlin-android-extensions、kotlin-compiler-embeddable等)均出现相同错误,核心原因均为无法连接repo.maven.apache.org

解决方法

  • 检查网络连通性
    先验证本地网络能否访问 repo.maven.apache.org,可以直接在浏览器打开该地址,或执行命令测试:

    ping repo.maven.apache.org
    

    若无法访问,切换网络(如手机热点)或关闭VPN/代理工具后重试。

  • 替换为国内Maven镜像
    修改项目根目录下的 android/build.gradle 文件,将默认仓库替换为国内镜像(如阿里云):

    buildscript {
        repositories {
            maven { url 'https://maven.aliyun.com/repository/public' }
            google()
        }
        // 保留原有其他配置
    }
    
    allprojects {
        repositories {
            maven { url 'https://maven.aliyun.com/repository/public' }
            google()
            mavenLocal()
            maven { url "$rootDir/../node_modules/react-native/android" }
            maven { url "$rootDir/../node_modules/jsc-android/dist" }
        }
    }
    
  • 清理Gradle缓存后重建
    执行以下命令清理缓存并重新构建:

    # 清理Gradle缓存
    ./gradlew cleanBuildCache
    # 重新安装依赖并构建
    npm install && cd android && ./gradlew assembleDebug
    
  • 指定兼容的Kotlin版本(可选)
    若上述方法无效,可在 android/build.gradle 中指定较新的稳定版Kotlin:

    buildscript {
        ext {
            kotlinVersion = "1.8.22"
        }
        dependencies {
            classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"
            // 保留原有其他依赖
        }
    }
    

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.06 22:52:46