在机器人工作室(v0.8.9)引用外部库项目 [英] Referencing external library projects in Android Studio (v0.8.9)

查看:214
本文介绍了在机器人工作室(v0.8.9)引用外部库项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个需要约10个项目中引用自定义库。一切工作正常,在Eclipse,但我想他们到Android Studio的迁移,以便采取构建系统的优势。我已经检查

I have a custom library that needs to be referenced in about 10 projects. Everything works fine in Eclipse but I want to migrate them to Android Studio in order to take advantage of the build system. I've already check

<一个href="http://stackoverflow.com/questions/17479076/android-studio-add-external-project-to-build-gradle">Android工作室添加外部项目build.gradle

<一个href="http://stackoverflow.com/questions/22243269/android-studio-0-5-how-to-share-a-single-library-source-across-multiple-proje">Android 。工作室0.5 +:如何

和其他一些链接和文档的Gradleware,但我没有得到让我的项目编译。

and some other links and docs in Gradleware but I don't get to make my projects compile.

我的文件结构是这样的:

My file structure is like:

+项目

| + libraryProject

|+libraryProject

| + ---工作区

|+---workspace

| + ------ projectSrc

|+------projectSrc

|

| + project0

|+project0

| + ---工作区

|+---workspace

| + ------ projectSrc0

|+------projectSrc0

|

| + PROJECT1

|+project1

| + ---工作区

|+---workspace

| + ------ projectSrc1

|+------projectSrc1

| + projectN

|+projectN

| + ---工作区

|+---workspace

| + ------ projectSrcN

|+------projectSrcN

每个项目包含的文档,设计文档,等等,因而没有方便的在同一个根目录下的SRC。

Each project contains docs, design files, etc... and therefore is no convenient to have the src in the same root folder.

在我的PROJECT1, settings.gradle 文件我用:

In my "project1", settings.gradle file I've used:

include ':module-custom-lib'
project(':module-custom-lib').projectDir = new File(settingsDir, '../../../libraryProject/workspace/projectSrc')

在我的 build.gradle 文件,相依第一节补充:

In my build.gradle file, dependencies section I add:

dependencies {
    compile project(':..:..:..:libraryProject:workspace:projectSrc')
    ....
}

不过,我得到一个错误说未找到该项目。

But I get an error saying that the project wasn't found.

我也用下面的办法:

def customLib = file('../../../libraryProject/workspace/projectSrc')
settings.createProjectDescriptor(rootProjectDescriptor, 'module-custom-lib', customLib)
include ':module-custom-lib'

然后在 build.gradle

dependencies {
    compile project(':module-custom-lib')
    ....
}

请帮忙。感谢您的时间。

Please help. Thanks for your time.

编辑:我已经成功地得到它的工作通过添加模块应用作为项目目录后缀:

I've managed to get it working by adding the module app as a suffix in the project dir.:

include ':module-custom-lib'
project(':module-custom-lib').projectDir = new File(settingsDir, '../../../libraryProject/workspace/projectSrc/app')

现在的库成员解析完美,但该项目的R资源类无法得到解决。所以,如果我做的:

Now the library members resolve perfectly, but the project's 'R' resource class can not be resolved. So if I do:

setContentView(R.layout.main);

没有找到该资源。清理并重建项目不修复该问题。

it fails to find that resource. Cleaning and rebuilding the project doesn't fixes the issue.

编辑2:很显然,有一个与清单合并使问题得到了解决,一旦我调整这两个项目的minSdk和targetSdk一个问题。在previous解决方案很好地工作。

EDIT 2: Apparently, there was a problem with the manifest merging 'cause the problem was fixed once I adjusted the minSdk and targetSdk of both projects. The previous solution work perfectly.

推荐答案

您第一次尝试有一个简单的语法,并应工作。您的 settings.gradle 的文件看起来不错:

Your first attempt has a simpler syntax, and should work. Your settings.gradle file looks okay:

include ':module-custom-lib'
project(':module-custom-lib').projectDir = new File(settingsDir, '../../../libraryProject/workspace/projectSrc')

但应谨慎对待,包括相对路径存在 - 机器人工作室不得使用相同的工作目录,你在命令行进行构建,因此参考相关的事情,以 ROOTDIR 可能有助于缓解问题。

though you should be cautious about including a relative path there -- Android Studio may not use the same working directory as a build you do from the command line, so referencing things relative to rootDir may help alleviate problems.

依赖模块的构建文件的块,你需要引用一个模块你做 settings.gradle以同样的方式,所以你会使用这样的:

In the dependencies block of a module's build file, you need to reference a module the same way you do in settings.gradle, so you'd use something like this:

dependencies {
    compile project(':module-custom-lib')
}

依赖块,你链接到项目中使用摇篮的项目命名空间,因为你已经明确地设置了库模块的根目录下,你不'T需要尝试在这里找到它在文件系统中。这:..:..:.. 语法不会无论如何努力来引用模块是你的项目的根目录之外,这个人是

In dependencies blocks, you're linking to projects using Gradle's project namespace, and since you've already explicitly set up the root directory of the library module, you don't need to try to locate it in the filesystem here. That :..:..:.. syntax wouldn't work anyway to reference a module that's outside of your project's root directory, as this one is.

这篇关于在机器人工作室(v0.8.9)引用外部库项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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