使用Gradle设置项目依赖项 [英] Set project dependencies with Gradle
问题描述
我正在使用带有Eclipse的Android Gradle(不是Android Studio,请不要建议更改IDE).
I am using Gradle for Android with Eclipse (NOT Android Studio and please do not suggest to change the IDE).
我的project.properties
文件显示以下行:
android.library.reference.1=..\\google-play-services_lib
我尝试将这一行添加到build.gradle:
I tried adding this line to build.gradle:
compile project('..\\google-play-services_lib')
构建项目时出现此错误:
When building the project I get this error:
在根项目"myProject"中找不到路径为".. \ google-play-services_lib"的项目.
Project with path '..\google-play-services_lib' could not be found in root project 'myProject'.
-
我在做什么错了?
What am I doing wrong?
如何在build.gradle中定义已添加到构建路径的jar?
How do I define in the build.gradle the jars I've added to the build path?
推荐答案
如果要编译库的源代码:
1)将项目库放入根项目
If you want to compile sources of your library :
1) Put your project library in your root project
树如下:
RootProject
+- build.gradle
+- settings.gradle
+- Lib1/
+- build.gradle
+- ...
+- Project/
+- build.gradle
+- ...
2)编辑您的设置.gradle
2) Edit your settings.gradle
include ':Lib1'
include ':Project'
3)在项目的build.gradle文件中添加依赖项
3) Add dependency in your Project's build.gradle file
dependencies {
[...]
compile project(':Lib1')
}
如果要添加罐子:
1)在项目的目录中创建一个libs文件夹
If you want to add jars :
1) Create a libs folder in your Project's dir
2)将此目录作为礼物添加到gradle文件中
2) Add this dir as reprositories in your gradle file
repositories {
flatDir {
dirs 'libs'
}
}
3)将jar放入此目录,并在项目的build.gradle中添加依赖项
3) Put your jar in this dir and add dependencies in your Project's build.gradle
dependencies {
compile(name:'mylib',ext:'jar')
}
这篇关于使用Gradle设置项目依赖项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!