如何在android studio中导入外部库? [英] How to import external library in android studio?
问题描述
我很难导入库 'PageSlidingTapStrip'(https://github.com/astuetz/PagerSlidingTabStrip).
I struggle to import library 'PageSlidingTapStrip'(https://github.com/astuetz/PagerSlidingTabStrip).
我发现了这个问题(如何将 eclipse 库项目从 github 导入到 android studio 项目?),我按照这个解决方案.
I found this question(How to import eclipse library project from github to android studio project?), and I follow this solution.
cf) 我使用的是 win 8.1,android studio 版本 0.3.6
cf)I'm using win 8.1 , android studio version 0.3.6
首先,像这样构建新项目.
First, build new project like this condition.
其次,转到 File -> New Module 点击,将新模块创建为 android library 并制作这样的条件.(未选中创建自定义启动器图标,活动)
Second, go to File -> New Module click, create new module as android library and make condition like this.( Unchecked create custom launcher icon, activity )
这部分我有一个第一个问题.我应该选择关于 'Minimum required SDK'、'Target SDK'、'Compile with' 的版本?只关注项目版本?(图像显示了我第一次创建这个窗口时的默认值.)
And this part I got a first question. Which version should I choice version about 'Minimum required SDK' , 'Target SDK', 'Compile with'? Just Follow project version? (image show default value when I create this window first.)
无论如何,我在条件'最低要求的SDK:API 9/目标SDK:API 19/编译:API 19'
Anyway, I progress under condition ' Minimum required SDK : API 9 / Target SDK : API 19 / Compile with : API 19 '
三、删除'Project/PageSlidingTabStrip/src/main/'下的文件,复制外部库'res'、'src'、'AndroidManifest.xml'下的文件夹&文件,移入'Project/PageSlidingTabStrip/src/main/' 然后将 src 重命名为 java.
Third, delete files under 'Project/PageSlidingTabStrip/src/main/' and copy folder&file under external library 'res', 'src', 'AndroidManifest.xml' and move into 'Project/PageSlidingTabStrip/src/main/' then renamed src to java.
然后项目 &文件夹变成这个样子.(我跟随问题,告诉我复制和移动文件 'ic_launcer-web.png' 除了 'res', 'src', 'manifest' ,但我找不到那个文件)
And then project & folder become like this. (what I followed question as , told me copy and move file 'ic_launcer-web.png' apart from 'res', 'src', 'manifest' , but I can't find that file)
第四步,进入'文件->项目设置->模块->点击项目模块->'+'按钮->选择模块依赖'然后应用.
Fourth, go to 'File -> Project setting -> Module -> click project module -> '+' button -> select Module dependency' then apply.
在那之后,我面临这个错误并且无法解析 R.而且我无法进行下一步,无法完成导入库.我该怎么办?
After that, I face this error and cannot resolve R. And I can't go next step, can't finish import library. What should I do?
还有其他解决办法吗?
感谢您看到冗长的问题.希望得到解决!
Thanks for seeing long question. I hope to get a solution!
推荐答案
我还在我的应用中使用了 PagerSlidingTabStrip
项目,一切正常.我不确定是否已经可以通过 IDE 添加一个库项目(-> 没有任何问题).请尝试通过像这样编辑 gradle 文件来添加库项目:
I also use the PagerSlidingTabStrip
Project in my app and everything works fine.
I'm not sure if it's already possible to add a library project via the IDE (-> without any problems).
Please try to add the library project by editing the gradle files like this:
- 首先删除你的模块
PagerSlidingTabStrip
- 然后在您的项目根目录 (->
NewOne
) 中创建一个名为libs"的文件夹 - 将 git 上
PagerSlidingTabStrip
项目的完整文件夹library"复制到libs"中 - 重命名您刚刚复制到的文件夹library",例如PagerSlidingTabStripLibrary"(只是为了避免混淆)-> 重命名后你应该有路径:NewOne/libs/PagerSlidingTabStripLibrary"
现在使用以下命令将此库添加到您的
settings.gradle
中:
- first delete your module
PagerSlidingTabStrip
- then create a folder in your root project directory (->
NewOne
) named 'libs' - copy the complete folder 'library' of the
PagerSlidingTabStrip
project on git into 'libs' - rename the folder 'library' that you just copied to e.g. "PagerSlidingTabStripLibrary" (just to avoid confusion) -> after the renaming you should have the path: "NewOne/libs/PagerSlidingTabStripLibrary"
now add this library in your
settings.gradle
with the following command:
include ':libs:PagerSlidingTabStripLibrary'
转到您的 AppProject aps
的 build.gradle
文件,并将以下行添加到您的依赖项":
go to your build.gradle
file of your AppProject aps
and add the following line to your 'dependencies':
compile project(':libs:PagerSlidingTabStripLibrary')
至少你必须同步你的 gradle 文件:Tools -> Android -> Sync Project with Gradle Files
at least you have to sync your gradle files: Tools -> Android -> Sync Project with Gradle Files
请试试这个.如果出现错误,请发布日志文件.
Please try this. If you get errors please post the log file.
这篇关于如何在android studio中导入外部库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!