如何将 eclipse 库项目从 github 导入到 android studio 项目?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20310164/
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-08-20 02:37:33  来源:igfitidea点击:

How to import eclipse library project from github to android studio project?

androideclipseandroid-studio

提问by user1685095

I want to use HoloCircullarProgressBaras a library project in my android studio project. I tried to do it by copying into pre-created "library" folder in my project and then to add it to project in "Project Structure". But it's not working somehow.

我想在我的 android studio 项目中使用HoloCircullarProgressBar作为库项目。我尝试通过复制到我的项目中预先创建的“库”文件夹中,然后将其添加到“项目结构”中的项目来做到这一点。但它以某种方式不起作用。

Could anyone give a very specific step-by-step tutorial on how to do that in android studio 0.3.6?

谁能提供一个非常具体的分步教程,说明如何在 android studio 0.3.6 中做到这一点?

enter image description here

enter image description here

回答by Scott Barta

If you're importing a library as source code into a Gradle-based project, then at the moment there's no super-easy way to do it (sorry, it's on the to-do list, see https://code.google.com/p/android/issues/detail?id=62122) so you'll have to author your own build file for the library. Actually, it might be easier to use the New Module wizard to set up the build file and directory structure, then you can trim it down and copy the files over. This set of steps should get you up and running. It seems like a lot of steps but it should hopefully go pretty quick.

如果您将库作为源代码导入到基于 Gradle 的项目中,那么目前还没有超级简单的方法来做到这一点(抱歉,它在待办事项列表中,请参阅https://code.google。 com/p/android/issues/detail?id=62122),因此您必须为库编写自己的构建文件。实际上,使用“新建模块”向导设置构建文件和目录结构可能更容易,然后您可以将其修剪并复制文件。这组步骤应该可以让您启动并运行。这看起来像很多步骤,但希望它应该很快。

  1. From the Filemenu, choose New Module...
  2. From the wizard that comes up, choose Android Library
  3. From the next page of the wizard, give it the module name HoloCircularProgressBar, and uncheck the options for Create custom launcher iconand Create activity.
  4. Click Finish on the wizard.
  1. 文件菜单中,选择新建模块...
  2. 从出现的向导中,选择Android Library
  3. 在向导的下一页中,为其指定模块名称 HoloCircularProgressBar,并取消选中Create custom launcher iconCreate activity的选项。
  4. 单击向导上的完成。

It should add the new module to your project, so you'll end up with something like this:

它应该将新模块添加到您的项目中,因此您最终会得到如下内容:

Project view after adding new empty library

Project view after adding new empty library

  1. Delete everything inside the src/main folder.
  2. Now copy AndroidManfiest.xml, ic_launcher-web.png, res, and srcfrom the HoloCircularProgressBar source into the src/mainfolder.
  3. Rename the srcfolder that you just copied into src/mainto java.
  4. The New Module wizard left some things in the build.gradlefile in your HoloCircularProgresBarmodule/directory (make sure you're editing that one, not the one for your main app module) we don't need. Remove the dependenciesblock and the releaseblock.
  1. 删除 src/main 文件夹中的所有内容。
  2. 现在,复制AndroidManfiest.xmlic_launcher-web.pngres,并src从HoloCircularProgressBar源到src/main文件夹中。
  3. src刚刚复制到的文件夹重命名src/mainjava.
  4. New Module 向导build.gradle在您的HoloCircularProgresBar模块/目录中的文件中留下了一些我们不需要的东西(确保您正在编辑那个,而不是主应用程序模块的那个)。删除dependencies块和release块。

At this point you should hopefully be able to build successfully. Now if you want to actually use the module:

此时,您应该希望能够成功构建。现在,如果您想实际使用该模块:

  1. Go to File> Project Structure...> Modules> Your main module> Dependencies.
  2. Click on the + button to add a dependency, choose Module dependency, and select HoloCircularProgressBarfrom the list.
  1. 转到File> Project Structure...> Modules> Your main module> Dependencies
  2. 单击 + 按钮添加依赖项,选择Module dependency,然后HoloCircularProgressBar从列表中进行选择。

Now importstatements and usages of the library should work, and you should be good to go.

现在import库的语句和用法应该可以工作了,你应该很高兴。