Android(安卓)gradle 动态添加模块依赖
16lz
2021-01-26
Android 开发过程,可能会遇到依赖模块太多,手动的添加修改依赖就会觉得有点麻烦,这个时候可以考虑使用动态添加模块依赖,也是适用像 Jenkins
自动打包构建,就不需要频繁的去修改模块依赖,提高构建效率。
工程根目录 build.gradle
def modules = getSubprojects()//def modules = getAllprojects()def filter = ['libraryA', 'libraryB']// app 是主工程模块名project(':app') { p -> p.afterEvaluate { modules.each() { module -> if (!filter.contains(module.name)) { if (module != rootProject && module.parent == rootProject) { println p.name + "添加的依赖模块:" + module.name p.dependencies.add("compile", project(':' + module.name)) } } } }}
拓展学习:依赖外部模块工程
1、工程 settings.gradle
动态添加模块工程
include ':app'include ':lib-react-native'include ':lib-hybrid'project(':lib-hybrid').projectDir = new File('App_Android/framework/lib-hybrid')project(':lib-react-native').projectDir = new File('App_Android/framework/lib-react-native')
2、 app 模块 build.gradle
依赖使用
dependencies { compile project(':lib-react-native') compile project(':lib-hybrid')}
Gradle dependencies: compile project by relative path
Android studio add external project to build.gradle
更多相关文章
- Android(安卓)cocos2d-x开发(三)之创建Android工程和编译
- Android(安卓)依赖注入: Dagger 2 实例讲解(一)
- Android导入工程提示Invalid project description错误
- Android(安卓)Build Target no Target available
- android gradle导入依赖的另一个方法
- Android(安卓)Studio Error "UNEXPECTED TOP-LEVEL EXCEPTION"
- Android(安卓)Arduino 蓝牙模块通信源代码
- Android(安卓)使用动态加载框架DL进行插件化开发
- Android(安卓)开发中遇到的Error:Execution failed for task ':