Android Studio:如何使用相对路径添加项目? [英] Android Studio: How to add a project using relative path?

查看:137
本文介绍了Android Studio:如何使用相对路径添加项目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想迁移到 Android Studio 而不是 Eclipse 来处理我们应用程序的 Android 版本.我尝试了很多东西,但我实际上无法将项目引用添加到我的 Android Studio 项目中.

I want to migrate to Android Studio instead of Eclipse to work on our Android version of our Application. I tried a lot of stuff but i cannot actually add a project reference into my Android Studio Project.

详情:

我有一个由这些文件夹组成的 mercurial 存储库:

I have a mercurial repository consisting of theses folders:

  • 根/项目
  • 根目录/PROJECTB

注意,其实在eclipse中,projectB是PROJECTA的一个项目引用.然后,当我编译时,PROJECTB 被编译并在 PROJECTA 之后.如果我对这些项目中的任何一个进行了更改,我的源代码控制会跟踪所有更改.

Note that actually, in eclipse, projectB is a project reference of PROJECTA. Then, when i compile, the PROJECTB is compiled and after the PROJECTA. If i made change in any of theses projects, my source control track all the changes.

迁移到 Android Studio 时,PROJECTB 成为 PROJECTA 中的子文件夹.所以我删除了 PROJECTB 并尝试将其包含为对 PROJECTA 的引用,但它不起作用.我让它工作的唯一方法是让 PROJECTB 成为 PROJECTA 下的子文件夹.

When migrating to Android Studio, PROJECTB becomes a subfolder in PROJECTA. So i delete the PROJECTB and try to include it as a reference to PROJECTA but it just does not work. The only way i made it works is to have the PROJECTB being a subfolder under PROJECTA.

但这不是解决方案,因为我们有 20 个项目使用 PROJECTB 作为依赖项,我必须能够将其添加到每个项目中作为参考.

But this isn't a solution because we have 20 projects that uses PROJECTB as dependancy and I must be able to add it in each project as a reference.

有没有人有解决这种阻塞行为的方法?

Does anyone has a solution to that blocking behaviour?

有一些我已经尝试过的解决方案:

1- 使用具有许多不同参数的 gradle 文件:

1- Using gradle files with many different parameters:

包括':PROJECTB'project(':PROJECTB).projectDir = new File(settingsDir, '../PROJECTB)

include ':PROJECTB' project(':PROJECTB).projectDir = new File(settingsDir, '../PROJECTB)

2- 使用许多 Android Studio 导入

2- Using many Android Studio importations

3- 求上帝帮助我

现在我问你们!

推荐答案

要在 PROJECTA 中使用 PROJECTB,您必须执行以下操作:

To use PROJECTB in PROJECTA you have to do following:

修改您的PROJECTA settings.gradle 以包含PROJECTB 并定义PROJECTB 路径

Modify your PROJECTA settings.gradle to include PROJECTB and define PROJECTB path

include ':app', ':PROJECTB'
project(':PROJECTB').projectDir = new File(settingsDir, '../PROJECTB')

然后将 PROJECTB 作为依赖添加到您的 PROJECTA build.gradle

and then add PROJECTB as dependency to your PROJECTA build.gradle

dependencies {
    ...
    compile project(':PROJECTB')
}

这篇关于Android Studio:如何使用相对路径添加项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆