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
相关产品推荐
相关产品推荐

