Android studio add external project to build.gradle(引用其他工程作为库工程)

这篇博客介绍了如何不使用图形界面,直接通过修改settings.gradle文件将外部项目添加到Android Studio的构建配置中。首先,在settings.gradle中包含模块,如:include ':module1' 并指定模块路径。然后,在build.gradle(Module:app)的dependencies中加入模块依赖。如果遇到编译问题,检查依赖库是否正确。此外,还提到了在Project Structure中添加模块的图形界面方法作为补充。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Android studio add external project to build.gradle | Newbedevz

实际操作:

讲的很清楚,不需要图形界面导入。直接修改settings.gradle,如果没有,直接创建一个。然后加“

include ':module1'
project(':module1').projectDir = new File(settingsDir, '../Project B/Module 1') “

dependence,也许gradle可以加,之前貌似还在project structrue成功过。本次成功是发现没有依赖库文件导致编译不通过,直接找到对应代码自动修复。

Assuming that Some Other Folder is a gradle project you could add something like the following to your settings.gradle file:

include ':module1'
project(':module1').projectDir = new File(settingsDir, '../Project B/Module 1')

You have to put in your file settings.gradle this lines:

include ':module2'
project(':module2').projectDir = new File(settingsDir, '../Project 2/Module2')

Then you have to add in your builde.gradle (Module: app) in the dependencies tree, this line:

implementation project(':module2')

or go into the Project Structure > app > Dependencies, click on Add, choose 3 Module Dependencies and select your module

Right click on project - Select "Open Module Settings" - Select "Modules" in left pane - Click on "+" symbol on top - Choose "Import Module".

After importing Module. You need to add it as a dependency for your current project.

Keep "Modules" Selected in left pane and click on your project - Now Go in dependencies tab and click on "+" symbol that is located at bottom - Choose third option "Module Dependencies" and if you have imported your project correctly, it will show you the all available module that can be added as a dependency to your current project.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值