且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在android studio中导入外部库?

更新时间:2022-12-31 10:50:32

我还在我的应用中使用了 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 apsbuild.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.