Monday, April 11, 2016

So, ever since moving from Eclipse to Android Studio, I've been annoyed by the fact that importing an old project copies all the libraries under the project directory. This makes sharing libraries a bit more difficult, since you now need to manage them in two locations.

Apparently Gradle likes dependencies is under its root, for example:
Project
  |--build.gradle
  |--settings.gradle
  |--Dependency
  |    |--build.gradle
Now in most of my cases, I have my libraries as separate projects that I DO NOT want located under the app's root. So today, I finally got off my ass to figure out how to do that. (Yes, I've been very lazy about this)

The fix it turns out is rather simple. To achieve a directory structure like this:
Project
  |--build.gradle
  |--settings.gradle
Dependency
  |--build.gradle

In the project/settings.gradle, add the following:
include ':Dependency'
project(':Dependency').projectDir = new File(settingsDir, '../Dependency/module_build_gradle_location')
If you've just finished an import, you can now manually delete the imported module and rebuild the project.

No comments:

Post a Comment