Android的摇篮建立与子项目 [英] Android Gradle build with sub projects
问题描述
我目前在从行家将我们的项目之一,摇篮的过程。该文件夹结构如下:
I am currently in the process of converting one of our projects to Gradle from maven. The folder structure is as follows:
gitRoot
settings.gradle
build.gradle
ProjectA
build.gradle
src/main/java
Libraries
SomeLib (git submodule)
ProjectBRoot (git submodule)
settings.gradle
build.gradle
ProjectB
build.gradle
src/main/java
Libraries
FacebookSDK/facebook
build.gradle
src
所以已经看起来比较复杂。但这个想法是,项目B是一个库项目,它应该能够建立和独立包装的,这就是为什么它有它自己的settings.gradle并尽可能我可以告诉它似乎是工作好,我有它的建筑它的发现Facebook的就好了。
So already it looks complicated. But the idea is that ProjectB is a library project and it should be able to be built and packaged separately, which is why it has its own settings.gradle and as far as i can tell it seems to be working ok, i have it building and its finding facebook just fine.
该项目B / build.gradle包含此行
The ProjectB/build.gradle contains this line
compile project(':libraries:facebook-android-sdk:facebook')
在ProjectBRoot / settings.gradle包含此行
The ProjectBRoot/settings.gradle contains this line
include ':ProjectB', ':libraries:facebook-android-sdk:facebook'
在gitRoot / settings.gradle包含此行
The gitRoot/settings.gradle contains this line
include ':ProjectA', ':Libraries:ProjectBRoot:ProjectB'
该项目A / build.gradle包含此行
The ProjectA/build.gradle contains this line
compile project(':Libraries:ProjectBRoot:ProjectB')
当我运行构建我得到这个错误
When I run the build i get this error
The TaskContainer.add() method has been deprecated and is scheduled to be removed in Gradle 2.0. Please use the create() method instead.
FAILURE: Build failed with an exception.
* Where:
Build file '/gitRoot/Libraries/ProjectBRoot/ProjectB/build.gradle' line: 17
* What went wrong:
A problem occurred evaluating project ':Libraries:ProjectBRoot:ProjectB'.
> Project with path ':libraries:facebook-android-sdk:facebook' could not be found in project ':Libraries:ProjectBRoot:ProjectB'.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
Total time: 4.652 secs
所以我的猜测,什么是错的是,Facebook是不是从项目B直接的子文件夹......但在ProjectBRoot建设时也没有关系。这可能是因为,我直接而不是引用项目B通过ProjectBRoot / gradle.build的脸,但我想,它也没有工作。是否有人可以帮助我,我通过文件已经看过,并没有谈论有自己的settings.gradle文件,我认为是这是搞乱我的事情多个项目。
So my guess as to whats wrong is that facebook is not in a direct subfolder from ProjectB...but that doesn't matter when building within ProjectBRoot. This is probably due to the face that I am referencing ProjectB directly and not through the ProjectBRoot/gradle.build but I tried that and it also did not work. Can someone please help me out, I have looked through the documentation and it doesn't talk about multiple projects that have their own settings.gradle files and I think thats the thing that is messing me up.
更新:
所以我也跟着XAV的答案,我现在能够建立具有但是我无法导入/建立与机器人工作室的命令行。我知道这个问题还是与facebook的项目。我得到的错误是,它无法配置项目B。
So I followed Xav's answer and I am now able to build with the command line however i can't import/build with android studio. I know the problem is still with the facebook project. The error i get is that it could not configure ProjectB.
Gradle: A problem occurred configuring project ':ProjectA'.
> Failed to notify project evaluation listener.
> A problem occurred configuring project ':Libraries:ProjectBRoot:ProjectB'.
> Failed to notify project evaluation listener.
> Configuration with name 'default' not found.
的错误是由行
The error is caused by the line
compile project(':facebook-sdk')
该项目B / build.gradle里面
inside the ProjectB/build.gradle
推荐答案
settings.gradle必须定义所有的模块。它不会加载在树中加载更多模块等settings.gradle。
settings.gradle must define all the modules. It won't load other settings.gradle found in the tree to load more module.
您将不得不为
-
在顶层settings.gradle定义为Facebook SDK模块。是的,它是多余的与其他settings.gradle。
define a module for the facebook SDK in the top level settings.gradle. Yes it's redundant with the other settings.gradle.
发布项目B以某种方式(以及它的依赖所以在这种情况下,Facebook的SDK库),地方(企业神器库为例),并从项目A的访问它。
publish Project B somehow (as well as its dependencies so in this case the facebook SDK library), somewhere (a corporate artifact repository for instance) and access it from Project A.
虽然#1是更好的,它使项目B - > Facebook的依赖棘手的路径不同,具体取决于所使用的settings.gradle。解决这个问题的一种方法是从磁盘上的实际位置分割模块名称/路径。这是settings.gradle文件中完成的。
While #1 is better, it makes the ProjectB -> Facebook dependency tricky as the path will be different depending on the settings.gradle used. One way to fix this is to split the module name/path from its actual location on disk. this is done inside the settings.gradle file.
在你的顶层settings.gradle文件,执行
In your top level settings.gradle file, do
include 'facebook-sdk'
project(':facebook-sdk').projectDir = new File('Libraries/ProjectBRoot/Libraries/FacebookSDK/facebook')
在您的项目B的内部setting.gradle文件,用不同的相对路径做相同的:
In the setting.gradle file inside your Project B, do the same with the different relative path:
include 'facebook-sdk'
project(':facebook-sdk').projectDir = new File('Libraries/FacebookSDK/facebook')
这使得无论项目设置定义相同的'Facebook的SDK模块位于磁盘上的相同的绝对位置。
This makes both project setup define the same 'facebook-sdk' module located at the same absolute location on disk.
根据该模块上的所有项目应该只是声明依赖为
All projects depending on this module should just declare the dependency as
compile project(':facebook-sdk')
这篇关于Android的摇篮建立与子项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!