如何在 Android Studio 中添加一个库项目?

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.)

转载于:https://stackoverflow.com/questions/16588064/how-do-i-add-a-library-project-to-android-studio

csdnceshi77
狐狸.fox Here is a video which I found to be really useful: youtube.com/watch?v=1MyBO9z7ojk
接近 6 年之前 回复
csdnceshi75
衫裤跑路 If you're using Gradle, see this StackOverflow answer.
大约 6 年之前 回复
csdnceshi59
ℙℕℤℝ The YouTube video How to Add Libraries to Android Studio explains the process.
接近 7 年之前 回复
csdnceshi55
~Onlooker yeah figuring this out was way more confusing than it should have been... not like it was any better in eclipse.
7 年多之前 回复

30个回答

To add to the answer: If the IDE doesn't show any error, but when you try to compile, you get something like:

No resource found that matches the given name 'Theme.Sherlock.Light'

Your library project is probably compiled as an application project. To change this, go to:

Menu File -> Project structure -> Facets -> [Library name] -> Check "Library module".

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

Simply import the Android library project as a module and in Build.gradle.

Apply plugin: 'com.android.library'

After that, follow these steps:

  1. Right click on Module & select open Module settings
  2. Select dependencies, click on +, select library dependencies, and add the previously imported module.

An example of succesfully adding another library (PullToRefresh). Also works for ABS libproject.

This SO Question

This post

https://www.dropbox.com/s/1e3eteu3h0pmkf7/Android%20studio%20_doc.doc?dl=0 is the Dropbox link of how to add a JAR file and library project in the latest version of Android Studio 1.0.1.

Please see the documentation with screenshots. It's very easy for a new user.

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.

csdnceshi66
必承其重 | 欲带皇冠 I'm migrate to IDEA 13 from 12 and have this error too. Only re-import for all my dependencies will help. Manually remove all modules, remove related *.iml files and re-import your libs
7 年多之前 回复
csdnceshi79
python小菜 Same here. Who can solved this?
7 年多之前 回复
csdnceshi57
perhaps? I tried all steps inclusing adding the module as a dependency but I still have Gradle: Error retrieving parent for item: No resource found that matches the given name 'Theme.Sherlock.Light'.. It seems like my main project does not see the resources of the library project (ABS). The IDE however does recognize the references to classes and resources. Screenshot
7 年多之前 回复

First Way This is working for MacBook.

First select your builder.gradle file as given screen:

Enter image description here

Add dependencies like as on the selected screen:

Enter image description here

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...:

Enter image description here

After clicking on Import Module,

Enter image description here

give the path of library like as my MacBook path:

Enter image description here

Click on Finish. Now your library are added.

I had a different cause of the problem so for people:

repositories {
    mavenCentral()
}

change mavenCentral() to jcenter() and add

allprojects {
    repositories {
        jcenter()
    }
}

Option 1: Drop Files Into Project's libs/directory

The relevant build.gradle file will then update automatically.

Option 2: Modify build.gradle File Manually

Open your build.gradle file and add a new build rule to the dependencies closure. For example, if you wanted to add Google Play Services, your project's dependencies section would look something like this:

dependencies {
     compile fileTree(dir: 'libs', include: ['*.jar'])
     compile 'com.google.android.gms:play-services:6.5.+'
   }

Option 3: Use Android Studio's User Interface

In the Project panel, Control + click the module you want to add the dependency to and select Open Module Settings.

Enter image description here

Select the Dependencies tab, followed by the + button in the bottom-left corner. You can choose from the following list of options:

  • Library Dependency
  • File Dependency
  • Module Dependency

You can then enter more information about the dependency you want to add to your project. For example, if you choose Library Dependency, Android Studio displays a list of libraries for you to choose from.

Once you've added your dependency, check your module-level build.gradle file. It should have automatically updated to include the new dependency.

Source

If you need access to the resources of a library project (as you do with ABS) ensure that you add the library project/module as a "Module Dependency" instead of a "Library".

csdnceshi78
程序go Yes! You sir win the Internet! Thanks! I have just wasted a couple of hours of my life because I didn't know that.
6 年多之前 回复
共30条数据 首页 2 尾页
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐