Is there (or will be) a way to reference extern Library Project in Android Studio?

398 views
Skip to first unread message

Angels Victory

unread,
Dec 10, 2014, 6:48:18 AM12/10/14
to adt...@googlegroups.com
Hello everyone,

i am a two-years Android App Developer and struggling of converting from Eclipse to Android Studio.

I agree that there are many cool features in new AS IDE which could improve the work greatly.

But one things plagued me very much:

I could not reference a private Android Library Project direct into my developing Project without creating a another copy.

I already create dosens of private Android Library Project with eclipse and want to reuse it for always.

What i would do in Eclipse is just rightclick Project->Properties->Android->Add.. ->Choose library project.

It takes no more than 10 sec and another 30 s to rebuild eclipse project.

By following instructions from Google Developers page I can create or import module in a AS Project as library. I could add module depencey of library to the application module.

But what Android Studio do is import the source of my existing old library project and make a hard copy in my new AS Project folder.

I can also not figure out how could a library module of one project be reused in another AS Project. Will it means that once i improved my library project code, i must copy it into each AS Projects which contains the hard copy of that library? What worse is some of my private librarys could have reference to the other!

As i searched by google, what i could do to this situation is uploading the lib project to a maven resposity and reference via Gadle.This will cost too much time compare to 10+30s in eclipse - > Just for maybe a small change of the library project. Or i have to develop all my android app (application and library) in the same AS Project?

I am very appreciate if anyone can tell me that Android Studio has already such function or is this will be a future consideration of Android Studio developer team ?

Because it is too important for me! The Eclipse could be slow and stupid but it allow me to reuse my 2 years code simply.












Artem Zinnatullin

unread,
Dec 10, 2014, 12:42:01 PM12/10/14
to adt...@googlegroups.com
Don't worry, of course you can add dependencies on other projects.
First, take an overview of Gradle documentation.

Then add build.gradle into your library project and add it as dependency in app's build.gradle and add 'include' block to the settings.gradle.

I'd recommend you to read "Gradle Multi-project Builds": https://gradle.org/docs/current/userguide/multi_project_builds.html
Also, check Android Gradle Plugin User Guide: http://tools.android.com/tech-docs/new-build-system/user-guide

Angels Victory

unread,
Dec 11, 2014, 7:56:47 AM12/11/14
to adt...@googlegroups.com
How can i add a library project (lib1), which is a module of one AndroidStudioProject(A), into another AndroidStudioProject (we say project B)?

Wenn i use File->Import Module under Project B and choose the folder of A/lib1, the AndroidStudio make a COPY of lib1 as B/lib1.

Please forgive my poor knowledge about Gradle and AndroidStudio

Scott Barta

unread,
Dec 11, 2014, 9:45:34 AM12/11/14
to adt...@googlegroups.com
You can do it by manipulating your settings.gradle file instead of going through the UI and trying to import a module; the UI isn't there for it yet.

include ':module'
project(': module').projectDir = new File(settingsDir, '../relative/path/to/module')

I would strongly encourage you to not use a pure relative path here; in this example, the path is anchored to the "settingsDir" variable supplied by Gradle, which is defined to be the directory where settings.gradle is found. If you use a pure relative path (i.e isn't anchored to anything), you're dependent on the working directory being the same in all environments where the build file is run (command line vs. Android Studio vs. CI server), which isn't a good thing to assume.

--
You received this message because you are subscribed to the Google Groups "adt-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to adt-dev+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Angels Victory

unread,
Dec 12, 2014, 8:26:59 AM12/12/14
to adt...@googlegroups.com
That works for me, thank you very much, sbarta!

I really suggest AndroidStudio supply this method via UI for it is just a simple but very common action in Eclipse.
And i could not find this in offical tutorial, which will be very difficult for new AS user.

Regards.

Reply all
Reply to author
Forward
0 new messages