lostintranslation
lostintranslation

Reputation: 24583

Import another android studio project as a dependency

I am trying to slowly migrate to Android Studio. I exported two projects from eclipse to be imported as android studio projects. I imported both projects into android studio, both are separate projects.

Project 1 is dependent on Project 2. In eclipse both projects lived in eclipse and I was able to add Project as an android lib project for Project 1.

I have no idea how to do this in android studio.

I opened the main project (Project 1). I want to add Project 2 as an android lib. I have tried adding a new module but that does not really seem to do what I want. I still end up with compile errors in Project 1 as it cannot find files from project 2.

Upvotes: 0

Views: 655

Answers (1)

Scott Barta
Scott Barta

Reputation: 80010

In general, importing modules into existing projects doesn't work right yet, so you have two general approaches. One is to set up the build files by hand and then import the properly configured project into Android Studio. If you go that route, be aware that since v0.5.0, which is pretty recent, things have gotten better. Previously, all of the modules in your project needed to live under the same directory in the filesystem, but with recent improvements, this restriction is lifted. See How to share a single library source across multiple projects for some guidance on making this work, especially post 0.5.0.

To do this, you'll need to craft build.gradle files for each module and link them together with a single settings.gradle file in your main project. Rather than creating all that infrastructure from whole cloth, you might want to take some cues from the second approach:

Open your main project, and use the wizard to create a new minimal module for it. That will set up the build.gradle for the new module and add it to settings.gradle. Then take the second module's code and paste it into the new module, overwriting anything that was previously there, and patch up any problems. You can look at using facebook sdk in android studio for inspiration on how to make that work.

I realize these descriptions are a little vague; I'd recommend choosing an approach and seeing how far you get with it, and if you have problems, amend your question with more details on what you're having problems with.

Upvotes: 1

Related Questions