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

时间:2020-12-02 22:53:50

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. I get no errors just the floating button does not work.

如使用中所解释的那样构建.gradle然后在xml中添加代码,但不幸的是,我没有按预期的功能。我没有错误只是浮动按钮不起作用。

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.

对不起,如果这是一个简单的问题,它只是第一次使用这样的库给我。

2 个解决方案

#1


1  

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。

#2


1  

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. Check out what each snippet does and then add that to your main project.

提示:每当遇到这样的问题时,只需在Android工作室中创建一个临时项目,然后将所有代码复制并粘贴到您的项目的README.md中。查看每个代码段的功能,然后将其添加到主项目中。

#1


1  

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。

#2


1  

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. Check out what each snippet does and then add that to your main project.

提示:每当遇到这样的问题时,只需在Android工作室中创建一个临时项目,然后将所有代码复制并粘贴到您的项目的README.md中。查看每个代码段的功能,然后将其添加到主项目中。