gradle dependencies in folder above project

2019-06-09 15:48发布

问题:

How would I reference gradle dependencies that are stored in a folder above the build.gradle file?

There must be some syntax for this correct? all the references I see look like

compile ':libs:thirdparty'

but this isn't really what I'm going for

so now I've tried this in my settings.gradle file

include ':app', ':android-volley'

project(':android-volley').projectDir=new File('../../shared-components/android-volley')

where I am trying to link my android-volley project, it is heavily modified so using the maven link will be no good for me, and I want to use these files between this project and other projects I work on

this does not allow my project to "sync" properly any more, and the import statements for volley do not work because it cannot find the dependencies

here is the .iml file Android Studio / IntelliJ creates

<?xml version="1.0" encoding="UTF-8"?>
<module external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$/.." external.system.id="GRADLE" external.system.module.group="whosay" external.system.module.version="unspecified" type="JAVA_MODULE" version="4">
 <component name="FacetManager">
  <facet type="android-gradle" name="Android-Gradle">
  <configuration>
    <option name="GRADLE_PROJECT_PATH" value=":android-volley" />
  </configuration>
</facet>
<facet type="java-gradle" name="Java-Gradle">
  <configuration>
    <option name="BUILD_FOLDER_PATH" />
  </configuration>
</facet>
</component>
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
  <excludeFolder url="file://$MODULE_DIR$/.gradle" />
  <excludeFolder url="file://$MODULE_DIR$/build" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

what is wrong?

回答1:

Open your settings.gradle file and you should see include:app. The "app" part is your main module for your app but say you want to add a gradle library: you would add the lib folder to the same location where the "app" module is stored, then go to settings.gradle and below the include:app, type include:<your lib name here>. Then sync gradle files and you should be good to go. Make sure that the app module and your lib module is using the same android version and sdk version.



回答2:

Probably you forgot to add dependencies in app build.grade file:

Something like this:

dependencies {
     compile project(path: ':android-volley')
}