How do I add a library project to Android Studio?

前端 未结 30 3902
梦谈多话
梦谈多话 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:56

    Use menu File -> Project Structure -> Modules.

    I started using it today. It is a bit different.

    For Sherlock, maybe you want to delete their test directory, or add the junit.jar file to the classpath.

    To import the library using gradle, you can have to add it to the dependencies section of your build.gradle (the module's one).

    E.g.

    dependencies {
        compile fileTree(dir: 'libs', include: ['*.jar'])
        compile 'com.android.support:appcompat-v7:22.1.0'
        compile 'com.actionbarsherlock:actionbarsherlock:4.4.0@aar'
    }
    

    Android Studio is changing.

    There exist a section named "Open module settings" if you right-click on a module folder in the project section of Android Studio (I'm using the version 0.2.10).

    0 讨论(0)
  • 2020-11-21 04:57

    The easiest way I found to include external library project is (for example to include a Facebook library which is stored one directory up in the dependencies folder):

    1. In settings.gradle add

      include ':facebook'
      
      project(':facebook').projectDir = new File(settingsDir, '../dependencies/FacebookSDK')
      
    2. In build.gradle dependencies section, add

      compile project ('facebook')
      

    All left to do is synchronise the project with gradle files.

    0 讨论(0)
  • 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')
        ...
    }
    
    0 讨论(0)
  • 2020-11-21 04:59

    After importing the ABS Module (from File > Project Structure) and making sure it has Android 2.2 and Support Library v4 as dependencies, I was still getting the following error as you @Alex

    Error retrieving parent for item: No resource found that matches the given name 'Theme.Sherlock.Light.DarkActionBar'
    

    I added the newly imported module as a dependency to my main app module and that fixed the problem.

    0 讨论(0)
  • First Way This is working for MacBook.

    First select your builder.gradle file as given screen:

    Add dependencies like as on the selected screen:

    Select sync project.

    If you are getting an error like "Project with path':signature-pad' could not be found in project ':app'", then please use the second way:

    Select menu File -> New -> Import Module...:

    After clicking on Import Module,

    give the path of library like as my MacBook path:

    Click on Finish. Now your library are added.

    0 讨论(0)
  • 2020-11-21 05:00

    I found the solution. It's so simple. Follow froger_mcs instructions.

    Make sure that you make the src folder a Source folder in Project Structure -> Modules (Sources).

    Enter image description here

    0 讨论(0)
提交回复
热议问题