Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
495 views
in Technique[技术] by (71.8m points)

dependencies - Add local Library Project as a dependency to multiple Projects in Android Studio

I created a library project in Android Studio (currently 0.5.2) by choosing File > New Project... > "Mark this project as a library".

enter image description here

I have two other non-library projects that I would like to add a dependency to this library project.

-My Library
-Project 1 (depends on My Library)
-Project 2 (depends on My Library)

My goal is to keep each project independent and avoid duplicating modules/code. How can this be done without copying the library module into the other projects?

Update: Android Studio 0.6.0 allows you to Import a module, though, this simply copies the module source into the Project.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You can also refer to a library outside of your project folder using the project().projectDir property. If your external library is relative to your project like so

- MyLibrary
   - library
- MyProject
    - app

in MyProject/settings.gradle

include ':library'
project(':library').projectDir = new File(settingsDir, '../MyLibrary/library')

in MyProject/app/build.gradle

dependencies {
   compile project(':library')
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...