如何导入第三方库 [英] How to import 3rd party libraries

查看:217
本文介绍了如何导入第三方库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在另一天发现一些很酷的Android图书馆,并决定尝试一些。但是我无法正确导入库。



这是库的URL: https://github.com/dmytrodanylyk/android-process-button



我第一次尝试导入库到eclipse(并将文件在java目录中移动到src目录并将项目设置为库),并将样本导入eclipse并将其设置为使用库项目(Properties-> Android-> Libraries)。但它没有奏效。布局文件表示无法实例化[自定义小部件类]。



我尝试将.jar文件导入libs目录(并更新java构建路径),但它也不起作用。它也显示了java文件中的错误。



然后,我尝试将所有的java和布局文件复制到示例项目目录,并且它工作。但是我猜测这不是第三方图书馆的工作方式。



我第一次以为这是图书馆的一些错误,但是我尝试导入的所有其他图书馆我的项目面临着同样的问题。



有人可以带我走过如何正确导入第三方库到我的Android项目?

解决方案

您可以做的最好的选择是使用gradle作为您的依赖管理员。



您发布的图书馆正在使用Gradle,所以你可以这样链接到这个图书馆:

 依赖关系{
compile'c​​om.github。 dmytrodanylyk.android-process-button:library:0.0.7'
}

Andvoilá !您的图书馆可以在您的应用程序中使用:D



我将为您提供几个有用的链接,以正确使用Gradle:





你可以如果您不介意更改主编辑器,请直接在Android Studio(Intellij)中使用Gradle。



如果您想要使用Eclipse,那么



strong>编辑:



哦!如果您想搜索已经有Gradlized的图书馆,您可以导航到 Gradle Please


I found some cool android libraries the other day and decided to try some. But I'm having trouble correctly importing the library.

This is the URL of the library : https://github.com/dmytrodanylyk/android-process-button

I first tried importing the library to eclipse (and move the files in java directory to src directory and set the project as library) and importing the sample to eclipse and set it to use the library project (Properties->Android->Libraries). But it didn't work. The layout files said it failed to instantiate [custom widget class].

The I tried importing the .jar file to libs directory (and update the java build path) but it didn't work either. It showed errors in the java files too.

I then tried copying all the java and layout files to the sample project directory and it worked. But I'm guessing that's not the way to work with 3rd party libraries.

I first thought it's some error with the library but all the other libraries I tried to import to my projects faced the same problem.

Can someone walk me through how to correctly import a 3rd party library to my android project?

解决方案

The best option you can do is to use gradle as your dependency manager.

The library you have posted is using Gradle so you can link to this library in this way:

dependencies {
  compile 'com.github.dmytrodanylyk.android-process-button:library:0.0.7'
}

And voilá! You have your library ready to use in your app :D

I'll let you a couple of useful links to use Gradle properly:

  • Mark Allison's tutorial about Gradle It will explain step by step how Gradle works (keep in mind that is using an outdated version of Android Gradle plugin, you have to adapt the version to the current one which is 0.10)
  • Official Developer Docs about Gradle In here you can find another step by step tutorial to configure and use Gradle (this one is more updated).

You can use Gradle directly in Android Studio (Intellij) if you don't mind to change your main editor.

If you want to stick around with Eclipse then this stackoverflow link may be helpful!

EDIT:

Oh! And if you want to search already Gradlized libraries you can navigate to Gradle Please!

这篇关于如何导入第三方库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆