将Github项目作为库导入现有项目

16

我习惯将库作为 .jar 文件导入,但不知道如何使用来自 GitHub 的项目,例如:https://github.com/jfeinstein10/SlidingMenu/

我想在我的现有项目中使用它。我尝试将该项目文件包含在依赖项中,但是出现了一些错误。


请更详细地描述您的构建文件内容以及出现了什么错误。 - Scott Barta
请查看我的答案:https://dev59.com/amEh5IYBdhLWcg3w_Xv5#34963958 - deviant
1个回答

24
我已经在这篇文章中解释了如何在Android Studio中使用项目库。但是,我知道特别是在开始阶段,直到你理解AS项目的结构,这并不容易。因此,这里是您问题的解释:
通过像这样配置我的项目的gradle文件,将项目库添加到我的项目中:
  • create a folder in your root project directory named 'libs'
  • copy the complete folder 'library' of the SlidingMenu project on git into 'libs'
  • rename the folder 'library' that you just copied to e.g. "SlidingMenuLibrary" (just to avoid confusion)
  • now add this library in your settings.gradle with the following command:

    include ':libs:SlidingMenuLibrary'
    
  • go to your build.gradle file of your AppProject and add the following line to your 'dependencies':

    compile project(':libs:SlidingMenuLibrary')
    
  • at least you have to sync your gradle files: Tools -> Android -> Sync Project with Gradle Files

请尝试此操作。如果出现错误,请发布日志文件。


27
我使用你解释的方法,但是出现了这个错误: Gradle 'Surprise' 项目刷新失败 错误:找不到名称为“default”的配置。 - Saman Salehi
使用了您的方法,仍然出现了与上述相同的错误:项目刷新失败,错误:找不到名称为“default”的配置。 - n j

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接