7

I'm struggling badly with moving from Eclipse to Android Studio.

Basically, I get that an Android Studio project is more like a workspace and a module more like a project...

However, in the Android Studio start page you can only create projects, so how do you share a module (i.e. a project in eclipse terms) across projects?

Basically, I have a number of apps that use a shared library I've created, in Eclipse all I do is flag it as a library and in each project simply link to it.

I have absolutely no idea how to do this in Android Studio. The examples for creating modules seem to take you as far as creating a module for no real purpose other than to use it within one app.

I first imported my library as a project in android studio, but that proved pointless, thinking that was how to do it because I want it kept separate in my version control system.

I then created a temporary module inside my app, but then it stores it within the project and in my other apps I cannot find a way to import the modules, so I really don't see what the point of a module is when it's embedded in a project and can't be separated or referenced anywhere else.

Thanks for any help.

Neil Walker
  • 6,400
  • 14
  • 57
  • 86
  • possible duplicate of [Android studio add external project to build.gradle](http://stackoverflow.com/questions/17479076/android-studio-add-external-project-to-build-gradle) – Scott Barta Aug 14 '14 at 16:48

1 Answers1

1

Consider your library project name common-lib

Open build.gradle of the projects to which you want to add library add add the following

dependencies {    
    compile project(':common-lib')    
}

and sync gradle

sujithvm
  • 2,351
  • 3
  • 15
  • 16
  • 1
    When I do that it's looking for my 'common-lib' in my project ':app' but it's not there. That's my question. I have absolutely no idea how to have a common module, in it's own folder structure, shared across many projects. Preferably using the IDE, i.e. like in eclipse to reference another project. I keep banging my head against a brick wall. Surely it can't be that difficult. – Neil Walker Aug 14 '14 at 16:28
  • @Neil do you have the library imported into your project/workspace? – sujithvm Aug 14 '14 at 16:30
  • In eclipse I have a workspace with projects. One of which is an android common library I've created. For any project to use this code all I do is right-click, go to properties and reference the common library and it's job done. I've been at this all after in Android Studio. Surely it can't be that difficult? My code is also nicely separated and each project is under revision control in it's own folder structure. – Neil Walker Aug 14 '14 at 16:39
  • @Neil It is not difficult at all. Do the following. i) Import project (your app) and the library you using android studio (it would now automatically restructure and generate gradle files). ii) Open `build.gradle` of project (your app) and add the above code snippet to dependencies section with `common-lib` replaced with name of libary that you see in the workspace. – sujithvm Aug 14 '14 at 16:42