Set project dependencies with Gradle

风流意气都作罢 提交于 2019-12-11 23:47:22

问题


I am using Gradle for Android with Eclipse (NOT Android Studio and please do not suggest to change the IDE).

My project.properties file got this line:

android.library.reference.1=..\\google-play-services_lib

I tried adding this line to build.gradle:

compile project('..\\google-play-services_lib')

When building the project I get this error:

Project with path '..\google-play-services_lib' could not be found in root project 'myProject'.

  1. What am I doing wrong?

  2. 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

Tree is like the following :

RootProject
  +- build.gradle
  +- settings.gradle
  +- Lib1/
      +- build.gradle
      +- ...
  +- Project/
      +- build.gradle
      +- ...

2) Edit your settings.gradle

include ':Lib1'
include ':Project'

3) Add dependency in your Project's build.gradle file

dependencies {
    [...]
    compile project(':Lib1')
}

If you want to add jars :

1) Create a libs folder in your Project's dir

2) Add this dir as reprositories in your gradle file

repositories { 
    flatDir {
        dirs 'libs' 
    } 
}

3) Put your jar in this dir and add dependencies in your Project's build.gradle

dependencies {
    compile(name:'mylib',ext:'jar')
}


来源:https://stackoverflow.com/questions/40451312/set-project-dependencies-with-gradle

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!