如何将库项目添加到Android Studio?

本文翻译自:How do I add a library project to Android Studio?

How do I add a library project (such as Sherlock ABS) to Android Studio ? 如何将库项目(例如Sherlock ABS)添加到Android Studio

(Not to the old ADT Eclipse-based bundle, but to the new Android Studio .) (不是旧的基于ADT Eclipse的捆绑包,而是新的Android Studio 。)


#1楼

参考:https://stackoom.com/question/17bJQ/如何将库项目添加到Android-Studio


#2楼

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. 对于Sherlock,也许您想删除其测试目录,或将junit.jar文件添加到类路径。

To import the library using gradle, you can have to add it to the dependencies section of your build.gradle (the module's one). 要使用gradle导入库,您必须将其添加到build.gradledependencies部分(该模块的一个)。

Eg 例如

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. Android Studio正在改变。

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). 如果在Android Studio的项目部分中右键单击模块文件夹,则存在一个名为“打开模块设置”的部分(我使用的是0.2.10版)。


#3楼

  1. Press F4 to show Project Structure , click libraries or Global libraries, and click + to add the JAR file. F4键显示“ 项目结构” ,单击“库”或“全局库”,然后单击“ +”添加JAR文件。
  2. Click Modules what you want add jar, select the Dependencies tab, click + , and add Library. 单击模块,你要加什么罐子,选择Dependencies选项卡,单击+,并添加库。

#4楼

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 导入ABS模块(从“文件”>“项目结构”)并确保其具有Android 2.2和支持库v4作为依赖关系后,由于您@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. 我将新导入的模块作为依赖项添加到主应用程序模块中,从而解决了该问题。


#5楼

如果需要访问库项目的资源(如使用ABS一样),请确保将库项目/模块添加为“模块依赖项”而不是“库”。


#6楼

To add to the answer: If the IDE doesn't show any error, but when you try to compile, you get something like: 补充一下答案:如果IDE没有显示任何错误,但是当您尝试编译时,您将得到类似以下内容的信息:

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". 菜单文件 -> 项目结构 -> -> [库名称]->选中“库模块”。

发布了0 篇原创文章 · 获赞 75 · 访问量 56万+

猜你喜欢

转载自blog.csdn.net/w36680130/article/details/105414874