0

I am trying to import this library my Android Studio project, but am not having any luck because it doesn't have any gradle files. https://github.com/xibsked/android-numberpicker

I found these posts, (Using library products without gradle files in Android Studio, How to import project files without Gradle files into Android Studio) but they are either unanswered or the answers involve exporting from Eclipse, which isn't my case. I'm not migrating from Eclipse, just want to use this library.

Thanks!

Community
  • 1
  • 1
AceInventor
  • 129
  • 1
  • 2
  • 10

3 Answers3

2

That libary does appear to be published to Maven:

http://mvnrepository.com/artifact/net.simonvt/android-numberpicker/1.0.0

So you just need to add that dependency to your project's build.gradle file:

dependencies {
    'net.simonvt:android-numberpicker:1.0.0'
}

If that's not an option for some reason, then you'll have to grab a copy of the source and import it into your project, as fractalwrench suggested.

Mike Paxton
  • 108
  • 8
  • This might have worked, but I wanted to be able to alter some of the files in the library, so needed to download and import it. Thanks for the good response, though! – AceInventor Nov 05 '15 at 16:43
  • No worries, run into that myself from time to time and have always wished there was a better way to do that. Glad you got it working! – Mike Paxton Nov 05 '15 at 16:44
1

One option would be to include the source files directly in your project, by copying to your app/src/main/ directory. If you want to add an extra layer of separation, you could create a new module before copying the files in.

Community
  • 1
  • 1
fractalwrench
  • 4,028
  • 7
  • 33
  • 49
  • This worked, thanks! I tried it before but didn't create a build.gradle file. Should've done that the first time. Oh well. – AceInventor Nov 05 '15 at 16:42
1

in general you can do:

  • create a new module and copy the source in your project app/main/src
  • clone or copy the module library in your project and add the build.gradle file

In the second case just config the right source set in your build.gradle file

apply plugin: 'com.android.library'

android {

    sourceSets {
        main {
            manifest.srcFile 'AndroidManifest.xml'
            java.srcDirs = ['src']
            resources.srcDirs = ['src']
            aidl.srcDirs = ['src']
            renderscript.srcDirs = ['src']
            res.srcDirs = ['res']
            assets.srcDirs = ['assets']
        }
    }
} 

In both scenario you have to add a module in your project:

root
|--app
|----build.gradle
|--library
|--build.gradle
|--settings.gradle

In settings.gradle just add:

include include ':library', 'app'

and in your app/build.gradle add

dependencies{
 compile project(':library')
}
Gabriele Mariotti
  • 320,139
  • 94
  • 887
  • 841