如何导入第三方库 [英] How to import 3rd party libraries
问题描述
这是库的URL: https://github.com/dmytrodanylyk/android-process-button
我第一次尝试导入库到eclipse(并将文件在java目录中移动到src目录并将项目设置为库),并将样本导入eclipse并将其设置为使用库项目(Properties-> Android-> Libraries)。但它没有奏效。布局文件表示无法实例化[自定义小部件类]。
我尝试将.jar文件导入libs目录(并更新java构建路径),但它也不起作用。它也显示了java文件中的错误。
然后,我尝试将所有的java和布局文件复制到示例项目目录,并且它工作。但是我猜测这不是第三方图书馆的工作方式。
我第一次以为这是图书馆的一些错误,但是我尝试导入的所有其他图书馆我的项目面临着同样的问题。
有人可以带我走过如何正确导入第三方库到我的Android项目?
您可以做的最好的选择是使用gradle作为您的依赖管理员。
您发布的图书馆正在使用Gradle,所以你可以这样链接到这个图书馆:
依赖关系{
compile'com.github。 dmytrodanylyk.android-process-button:library:0.0.7'
}
Andvoilá !您的图书馆可以在您的应用程序中使用:D
我将为您提供几个有用的链接,以正确使用Gradle:
- Mark Allison关于Gradle的教程它将逐步解释Gradle的工作原理(请记住,使用过时的Android Gradle插件版本,您必须将版本调整为当前版本为
0.10
) - 关于Gradle的官方开发人员文档 a>在这里你可以找到另一个一步一步的教程来配置和使用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屋!