如何将 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
How to import eclipse library project from github to android studio project?
提问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 中做到这一点?
回答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),因此您必须为库编写自己的构建文件。实际上,使用“新建模块”向导设置构建文件和目录结构可能更容易,然后您可以将其修剪并复制文件。这组步骤应该可以让您启动并运行。这看起来像很多步骤,但希望它应该很快。
- From the Filemenu, choose New Module...
- From the wizard that comes up, choose Android Library
- From the next page of the wizard, give it the module name HoloCircularProgressBar, and uncheck the options for Create custom launcher iconand Create activity.
- Click Finish on the wizard.
- 从文件菜单中,选择新建模块...
- 从出现的向导中,选择Android Library
- 在向导的下一页中,为其指定模块名称 HoloCircularProgressBar,并取消选中Create custom launcher icon和Create activity的选项。
- 单击向导上的完成。
It should add the new module to your project, so you'll end up with something like this:
它应该将新模块添加到您的项目中,因此您最终会得到如下内容:
- Delete everything inside the src/main folder.
- Now copy
AndroidManfiest.xml
,ic_launcher-web.png
,res
, andsrc
from the HoloCircularProgressBar source into thesrc/main
folder. - Rename the
src
folder that you just copied intosrc/main
tojava
. - The New Module wizard left some things in the
build.gradle
file in yourHoloCircularProgresBar
module/directory (make sure you're editing that one, not the one for your main app module) we don't need. Remove thedependencies
block and therelease
block.
- 删除 src/main 文件夹中的所有内容。
- 现在,复制
AndroidManfiest.xml
,ic_launcher-web.png
,res
,并src
从HoloCircularProgressBar源到src/main
文件夹中。 - 将
src
刚刚复制到的文件夹重命名src/main
为java
. - 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:
此时,您应该希望能够成功构建。现在,如果您想实际使用该模块:
- Go to File> Project Structure...> Modules> Your main module> Dependencies.
- Click on the + button to add a dependency, choose Module dependency, and select
HoloCircularProgressBar
from the list.
- 转到File> Project Structure...> Modules> Your main module> Dependencies。
- 单击 + 按钮添加依赖项,选择Module dependency,然后
HoloCircularProgressBar
从列表中进行选择。
Now import
statements and usages of the library should work, and you should be good to go.
现在import
库的语句和用法应该可以工作了,你应该很高兴。