简体   繁体   English

无法在Eclipse中将库添加到Android项目

[英]Cannot Add Library to Android Project in Eclipse

I am trying to add a Library to an existing project inside eclipse. 我正在尝试将一个库添加到eclipse中的现有项目中。 I am keeping the Project Folder itself and the Library Folder in a folder marked "ANDROID" on my desktop. 我将项目文件夹本身和库文件夹保存在桌面上标记为“ANDROID”的文件夹中。 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. 当我尝试将>现有代码导入工作区>选择“ANDROID”时...添加的唯一项目是应用程序本身而不是库。 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. 我甚至右键单击了我的应用程序 - 属性> Android>并注意到该库中有一个红色的“X”,并且不允许我搜索新的库。 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。

Make sure that the libraries and the project are at the same place, ie 确保库和项目位于同一位置,即

  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 打开库> Android的属性,然后选择Is Library
  4. Open project properties > Android > Add (library) 打开项目属性> Android>添加(库)
  5. Select the library 选择库
  6. save the properties 保存属性

If this does not work for you copy the jar files from its lib folder and paste it in the projects lib. 如果这不起作用,则从其lib文件夹中复制jar文件并将其粘贴到项目lib中。 This should only be done if the above method doesn't work 只有在上述方法不起作用时才应该这样做

Import Library project in eclipse . 在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 Library Check that box. 然后右键单击项目并转到属性 - > Android(左侧菜单) - >在底部(项目构建目标下方),您将看到一个名为“ 检查”框的复选框。 Now you've made your project a 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. 然后在您要添加库的orignal项目中再次转到属性 - > Android(左侧菜单) - >在底部(项目构建目标下方)单击添加按钮,您将看到该库项目可见。

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. 希望它能解决问题。

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 . 首先将文件夹结构从Android切换到Project

在此输入图像描述

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

在此输入图像描述

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

在此输入图像描述

Now you can start using the library in your project. 现在您可以开始在项目中使用该库。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM