无法在 Eclipse 中向 Android 项目添加库

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15018977/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 20:02:54  来源:igfitidea点击:

Cannot Add Library to Android Project in Eclipse

androideclipseprojectlibraries

提问by Taylor

I am trying to add a Library to an existing project inside eclipse. I am keeping the Project Folder itself and the Library Folder in a folder marked "ANDROID" on my desktop. When I try to Import > Existing Code into Workspace > Select "ANDROID".. the only project that gets added is the App itself and NOT the library. I even try to add the library on its own and it will show up on the import list but will not have a "ticked box" with the option of "Finish". I even right clicked my App - Properties > Android > and noticed that the library is there with a red "X" and does not allow me to search for a new library. What am I doing wrong? This Identical App and library is working with the same version of eclipse for a friend and not me.

我正在尝试向 eclipse 中的现有项目添加一个库。我将项目文件夹本身和库文件夹保存在我桌面上标记为“ANDROID”的文件夹中。当我尝试导入 > 现有代码到工作区 > 选择“ANDROID”时..唯一添加的项目是应用程序本身而不是库。我什至尝试自己添加库,它会显示在导入列表中,但不会有带有“完成”选项的“勾选框”。我什至右键单击我的应用程序 - 属性 > Android > 并注意到该库在那里有一个红色的“X”,并且不允许我搜索新库。我究竟做错了什么?这个相同的应用程序和库正在为朋友而不是我使用相同版本的 eclipse。

回答by Umar Ahmad

Make sure that the libraries and the project are at the same place, i.e.

确保库和项目在同一个地方,即

  1. Copy the libraries in the same folder as your project
  2. Import the libraries (file > Import > Existing Project in workspace)
  3. Open properties of library > Android and select Is Library
  4. Open project properties > Android > Add (library)
  5. Select the library
  6. save the properties
  1. 将库复制到与项目相同的文件夹中
  2. 导入库(文件 > 导入 > 工作区中的现有项目)
  3. 打开库的属性 > Android 并选择 Is Library
  4. 打开项目属性 > Android > 添加(库)
  5. 选择图书馆
  6. 保存属性

If this does not work for you copy the jar files from its lib folder and paste it in the projects lib. This should only be done if the above method doesn't work

如果这对您不起作用,请从其 lib 文件夹中复制 jar 文件并将其粘贴到项目库中。只有在上述方法不起作用时才应该这样做

回答by Jan

Import Library project in eclipse . Then right click on project and go to properties->Android (Menu on left side) --> At the bottom(below project build target) you will see a check box named is LibraryCheck that box. Now you've made your project a library .

在 eclipse 中导入库项目。然后右键单击项目并转到属性-> Android(左侧菜单)--> 在底部(在项目构建目标下方),您将看到一个名为库的复选框选中该框。现在您已将项目设为 library 。

Then in your orignal project where you want to add library go again to to properties->Android (Menu on left side) --> At the bottom(below project build target) Click add button and you will find that library project visible.

然后在您想要添加库的原始项目中再次转到属性-> Android(左侧菜单)-> 在底部(在项目构建目标下方)单击添加按钮,您会发现该库项目可见。

回答by Aakriti Sayal

This happens when you import the project from some location. If we import some project then it doesn't refer to the supporting library of that workspace. So always check the check box( copy projects to workspace) Go to file>import project>browse>select a project>Check the copy project into workspace. Hope it solve the issue.

当您从某个位置导入项目时会发生这种情况。如果我们导入某个项目,那么它不会引用该工作区的支持库。所以总是选中复选框(将项目复制到工作区)转到文件>导入项目>浏览>选择一个项目>将项目复制到工作区。希望它能解决问题。

回答by capt.swag

A late answer, although I thought of giving an in-depth answer to this question.

一个迟到的答案,虽然我想对这个问题给出一个深入的答案。

  1. First switch your folder structure from Android to Project.
  1. 首先将您的文件夹结构从 Android 切换到Project

enter image description here

在此处输入图片说明

  1. Now search for the libs folderinside app - build folder.
  1. 现在在 app - build 文件夹中搜索libs 文件夹。

enter image description here

在此处输入图片说明

  1. Once you have pasted the .jar file inside libs folder. Right click on the jar file and at end click on Add as library. This will take care of adding compile files('libs/library_name.jar') in build.gradle
  1. 将 .jar 文件粘贴到 libs 文件夹中后。右键单击 jar 文件,最后单击Add as library。这将负责在 build.gradle 中添加编译文件('libs/library_name.jar')

enter image description here

在此处输入图片说明

Now you can start using the library in your project.

现在您可以开始在您的项目中使用该库。