包括整个项目的库机器人工作室 [英] Including entire project as library android studio

查看:121
本文介绍了包括整个项目的库机器人工作室的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图导入我自己的图书馆到我的工作室的Andr​​oid应用程序之一。我已经看到了几个地方的指令,基本上等同于:

I am trying to import my own library into one of my apps in Android Studio. I have seen instructions in several places that basically amount to :

1 将文件移动到您的项目diectory库中的文件夹。 2 添加包括项目名称:夹folderName:库名称您settings.gradle文件
3 添加编制项目(夹folderName:库名称')下依赖于项目级build.gradle文件

1 Move the files into a library folder within your project diectory.
2 Add include 'projectName:folderName:libraryName to your settings.gradle file
3 Add compile project('folderName:libraryName') under dependencies to your project level build.gradle file

这工作对我来说,如果我导入模块...我认为它的一个模块。我还在试图找出摇篮。我的图书馆结构是这样的:

This works for me if I am importing a module... I think its a module. I'm still trying to figure out gradle. My library structure looks like this:

ProjectName
    Module1
        Classes
    Module2
        Classes2

如果我以这种方式导入模块1或模块2分开(如模块1是在上述说明我的库名称),他们将工作。但是,如果我尝试将整个项目导入为一体的图书馆中,我得到的错误。

If I import Module1 or Module2 separately in this fashion (where Module1 is my 'libraryName' in the instructions above), they will work. But if I try to import the whole project as one library I get errors.

我是什么做错了吗? 我想导入整个项目作为我想它有许多模块。有另一种/更好的方式来做到这一点?我是什么误会?

What am I doing wrong? I would like to import the entire project as I would like it to have many modules. Is there another/better way to do this? What am I misunderstanding?

更新:
按@ScottBarta的指示,我合并settings.gradle文件。 这似乎在我的主要项目合作,因为摇篮同步完成正确的,但我不准备好运行该项目。 于是我做了一个测试项目,并使用相同的步骤导入库。 这一次,我得到的错误:

Update:
As per @ScottBarta 's instructions I merged settings.gradle files. This appears to have worked in my main project because the gradle sync completed properly but I'm not ready to run that project. So I made a tester project and imported the library using the same steps. This time I get the error:

Gradle 'Tester' project refresh failed:
Build script error, unsupported Gradle DSL method found. 'compile()'!

尽可能接近我可以告诉大家,这些文件是在这两个项目中等价的:

As near as I can tell, the files are equivalent in the two projects:

主营:

include ':Eed'
include ':Eed:libraries:Overt:Visible'
include ':Eed:libraries:Overt:Control'

测试:

include ':app'
include ':app:libraries:Overt:Visible'
include ':app:libraries:Overt:Control'

主营:

dependencies {
    compile 'com.android.support:appcompat-v7:+'
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile project('libraries:Overt:Visible')
    compile project('libraries:Overt:Control')
}

测试

dependencies {
    compile 'com.android.support:appcompat-v7:19.+'
    compile fileTree(dir: 'libs', include: ['*.jar'])
    complie project('libraries:Overt:Visible')
    complie project('libraries:Overt:Control')

}

这是在测试项目中的文件结构的截图

And here's a screenshot of the file structure in the Tester project.

推荐答案

您只能有一个 settings.gradle 每个项目文件,所以如果你有一个多模块库有自己的 settings.gradle 中,你不能用一个单一的包括语句把它研究。你需要合并库的 settings.gradle 成,你把它包含在项目的。

You can only have one settings.gradle file per project, so if you have a multi-module library with its own settings.gradle, you can't bring it in with a single include statement. You'll need to merge the library's settings.gradle into that of the project you're including it in.

当您执行合并,请确保所有的包括报表合并 settings.gradle 有合理的路径,将找到自己的音乐库相对于项目的根。也请记住,在你的 settings.gradle 的文件中指定的路径必须匹配什么在你的依赖块。所以,如果你有这样的:

When you do the merge, make sure that all the include statements in the merged settings.gradle have sensible paths that will locate their libraries relative to the project root. Also keep in mind that the paths specified in your settings.gradle file have to match what's in your dependencies block. So if you have this:

include ':app'
include ':app:libraries:Overt:Visible'
include ':app:libraries:Overt:Control'

您需要这样的:

dependencies {
    compile 'com.android.support:appcompat-v7:19.+'
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile project(':app:libraries:Overt:Visible')
    compile project(':app:libraries:Overt:Control')
}

在你张贴在你的问题中生成脚本,有一个错字:它说 complie ,而不是的编译。如果这是在生成脚本中一个错字,而不是只是一个错字在这里你的问题,这将是一个问题。

In the build script you posted in your question, there's a typo: it says complie instead of compile. If that's a typo in your build script and not just a typo in your question here, that will be a problem.

这篇关于包括整个项目的库机器人工作室的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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