简体   繁体   English

如何将github库包含到Android Studio项目中

[英]How to include github library to Android Studio project

I am trying to use this library for Floating Action Buttons.I add 我正在尝试将此库用于浮动操作按钮。我添加

compile 'com.github.clans:fab:1.6.4'

to build.gradle as explained in usage and then add the code in xml, but unfortunately for me there is no functionality as expected. 按用法中的说明来构建build.gradle,然后将其添加到xml中,但是对我来说不幸的是,没有预期的功能。 I get no errors just the floating button does not work. 我没有任何错误,只是浮动按钮不起作用。

So I start wondering if I should add the code of the library as well, although this makes no sense to me since I add dependency. 所以我开始怀疑我是否也应该添加该库的代码,尽管这对我来说没有意义,因为我添加了依赖项。 Should I add the code to my project and how exactly should I make the connection between the library I added and my source code. 我应该将代码添加到我的项目中,还是应该如何精确地在添加的库和源代码之间建立连接。

Sorry if this is a simple question, its just first time using such library for me. 抱歉,如果这是一个简单的问题,那是我第一次使用这样的库。

Yes. 是。 You also need to add the code. 您还需要添加代码。 Adding 添加

`compile 'com.github.clans:fab:1.6.4'

only adds the library to your project files. 仅将库添加到您的项目文件中。 To use it, you have to call it by creating an element in one of your layouts XML file. 要使用它,必须通过在一个布局XML文件中创建一个元素来调用它。

tip : Whenever you get stuck in a problem like this, simply create a temporary project in Android studio and simply copy and paste all the code to your README.md to your project. 提示 :每当遇到此类问题时,只需在Android Studio中创建一个临时项目,然后将所有代码复制并粘贴到README.md即可。 Check out what each snippet does and then add that to your main project. 检查每个代码段的功能,然后将其添加到您的主项目中。

If by "it doesn't work" you mean you don't have access to any of its classes in your code, make sure you also have the JitPack maven repository in your Project-level Gradle build file. 如果“不起作用”表示您无法在代码中访问其任何类,请确保在项目级Gradle构建文件中也具有JitPack maven存储库

// Include repositories here for which dependencies can be retrieved from.
repositories {
    maven {
        url "https://jitpack.io"
    }
    // For example:
    // google()
    // jcenter()
}

If you do have access to the library in your code, and the library itself is not working as expected, I would check its github issues page for help. 如果您确实可以在代码中访问该库,并且该库本身未按预期运行,则请查看其github问题页面以寻求帮助。

As a last resort, you can pull the GitHub repository and compile the library yourself into an .AAR for your project. 作为最后的选择,您可以拉出GitHub存储库并将您自己的库编译为项目的.AAR

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM