如何包括图书馆模块依赖于一个Android Studio项目? [英] How to include a library module dependency in an Android Studio project?

查看:358
本文介绍了如何包括图书馆模块依赖于一个Android Studio项目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我迁移从Eclipse来AndroidStudio项目。我作为这个项目的一个lib的项目。此lib中被称为PullToRefresh。

我试过很多方法导入该项目的AS,但点儿我尝试的作品。

在我的项目,我有这样的文件夹结构:

 项目的根
+  - 应用程序
| +  - 建立
| +  - 库
| | +  -  PullToRefresh(我的lib项目)
| +  -  SRC
| | +  - 主(JAVA的code和资源)
 

在build.gradle,我试图做到这一点:

 相关性{
    编制项目(:库:PullToRefresh)
}
 

不过,我收到此错误信息:

 摇篮MY_PROJECT项目刷新失败:项目与路径:库:PullToRefresh
不能在项目中找到:应用程序
 

解决方案

Android的工作室工作在项目模块的概念,所有的模块应该是一个根目录(项目目录)中。一个模块可以依赖于其他模块/模块。你的图书馆被认为是在同一个项目的不同模块和主模块(在你的情况的应用程序)依赖于他们。

更改您的项目结构有点:

 项目的根
+  - 库
    +  -  PullToRefresh(我的lib项目)
+  - 应用程序
| +  - 建立
| +  -  SRC
| | +  - 主(JAVA的code和资源)
    +  -  .....
+  -  settings.gradle
 

包括此行中的 settings.gradle

 包括':库:PullToRefresh
 

您build.gradle看起来不错。我建议你​​从库改变你的目录名库,因为使用的库为您的JAR依赖不是为模块依赖关系。

和保持这在你的主模块的build.gradle文件:

 相关性{
    编制项目(:库:PullToRefresh)
}
 

I am migrating a project from Eclipse to AndroidStudio. I have a project used as a lib in this project. This lib is called PullToRefresh.

I've tried many ways to import this project to AS, but anyting I try works.

In my project I have this folder structure:

Project Root
+-- app
|   +-- builds
|   +-- libs
|   |   +-- PullToRefresh (my lib project)
|   +-- src
|   |   +-- main (java code and resources)

In the build.gradle, I've tried to do this:

dependencies {
    compile project(":libs:PullToRefresh")
}

But I'm getting this error message:

Gradle 'my_project' project refresh failed: Project with path ':libs:PullToRefresh'
could not be found in project ':app'

解决方案

Android Studio works on project-modules concept,All your modules should be inside a root directory(Your Project Directory). One module can be depended on other module/modules. Your libraries are considered as different modules under same project and your main module(app in your case) depends on them.

Change your project structure a little bit :

Project Root
+-- libs
    +-- PullToRefresh (my lib project)
+-- app
|   +-- builds
|   +-- src
|   |   +-- main (java code and resources)
    +-- .....
+--settings.gradle

Include this line in your settings.gradle

include ':libs:PullToRefresh'

Your build.gradle looks fine. I suggest you to change your directory name from libs to library because use libs for your jar dependency not for module dependencies.

and keep this in your main module's build.gradle file :

dependencies {
    compile project(":libs:PullToRefresh")
}

这篇关于如何包括图书馆模块依赖于一个Android Studio项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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