How do I add a library project to Android Studio?

前端 未结 30 4917
梦谈多话
梦谈多话 2020-11-21 04:24

How do I add a library project (such as Sherlock ABS) to Android Studio?

(Not to the old ADT Eclipse-based bundle, but to the new Android Studio.)

30条回答
  •  深忆病人
    2020-11-21 04:57

    This is how it works for me in Android Studio 1.5+

    In the project where you want to add external library project, go to menu File -> New -> *Import new Module**, navigate to the library project which you want to add to your project, select to add 'library' module in your project. You will get settings.gradle in your projects, beside app, included library, something like this:

    include ':app', ':library'
    

    Add in build.gradle(Module :app) in the dependencies section:

    Compile project(':library')

    Rebuild the project, and that's it.

    *You can add as many libraries (modules) as you want. In that case in settings.gradle you will have:

     include ':app', ':lib1', ':lib2', ...
    

    And in build.gradle, you'll need to have:

    dependencies {
        compile fileTree(dir: 'libs', include: ['*.jar'])
    
        // Some other dependencies...
    
        compile project(':lib1')
        compile project(':lib2')
        ...
    }
    

提交回复
热议问题