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

React Native自定义模块添加私有Maven仓库的正确位置

React Native Native模块依赖仓库配置位置解决方案

正确的配置位置是根项目的build.gradle或settings.gradle,具体取决于你使用的Gradle版本:

Gradle 7.0+(React Native 0.70及以上)

打开根项目的settings.gradle,在dependencyResolutionManagement的repositories块中添加仓库配置:

dependencyResolutionManagement {
    repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
    repositories {
        google()
        mavenCentral()
        // 新增第三方仓库
        maven {
            url '你的仓库地址'
            credentials {
                username '你的用户名'
                password '你的密码'
            }
        }
    }
}

Gradle 7.0以下(React Native 0.69及以下)

打开根项目的build.gradle,在allprojects的repositories块中添加:

allprojects {
    repositories {
        google()
        mavenCentral()
        // 新增第三方仓库
        maven {
            url '你的仓库地址'
            credentials {
                username '你的用户名'
                password '你的密码'
            }
        }
    }
}

原因说明

当你的MyModule作为依赖被app模块引用时,Gradle构建app时会统一从根项目配置的仓库列表中查找所有依赖(包括MyModule的依赖)。仅在MyModule自身的build.gradle中配置仓库,app模块的构建流程不会读取这个配置,导致找不到对应依赖。

额外检查

确保MyModule的build.gradle中已正确声明依赖:

dependencies {
    implementation '库的groupId:artifactId:指定版本'
}

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.03 15:07:03