简体   繁体   中英

How to import 3rd party libraries

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 !

I see the library uses gradle. So if you use gradle for dependency management or Android Studio (which uses gradle by default) importing will be a breeze. The installation instruction for gradle is even available at the github project site.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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