gradle dependencies in folder above project

允我心安 提交于 2019-12-23 05:59:11

问题


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')
}


来源:https://stackoverflow.com/questions/24898060/gradle-dependencies-in-folder-above-project

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