Using ViewPagerIndicator library with Android Studio and Gradle

99,501

Solution 1

I just pushed a version inside maven central so you only need to add that dependency :

compile 'fr.avianey.com.viewpagerindicator:library:2.4.1.1@aar'

And declare maven central like this :

repositories {
    mavenCentral()
}

Hope it helps...

Solution 2

A bit late to the party, but here:

Jake Wharton hasn't released it in maven as an aar. There's a group though that has made an aar of it available through their server, you can set it up like this in your build.gradle:

Add this to your source repositories after you declare your plugins:

repositories {
    maven { url "http://dl.bintray.com/populov/maven" }
    mavenCentral()
}

This will source their maven repo, which contains a packaged aar that they put together. Once that's done, you can simply add this line to your dependencies and everything should work once you sync your project with your gradle files.

Make sure that the Maven Repo is listed above the mavenCentral() entry. Otherwise, it will first look in maven's central repository and find the wrong package.

Android Studio generates two build.gradle files for projects, make sure you put this in the right one!

dependencies {
    // ...
    compile 'com.viewpagerindicator:library:2.4.1@aar'
    // ...
}

We use it in our app if you'd like to see a working example:

https://github.com/pandanomic/SUREwalk_android/blob/master/surewalk/build.gradle

Solution 3

I'm using gradle 0.10.+ with Android Studio 0.8.2 and the accepted answer didn't work for me. These are the slight changes I had to do in order to get ABS working in my project:

In the top level build.gradle file of your project add the maven repository in the allprojects config like this:

allprojects {
   repositories {
      maven { url "http://dl.bintray.com/populov/maven" }
      mavenCentral()
   }
}

And in the module's build.gradle file add the dependency without the @aar:

dependencies {
   // ...
   compile 'com.viewpagerindicator:library:2.4.1'
   // ...
}

Solution 4

Jitpack.io is great for this situation.

First, add the following repository:

repositories {
    // ...
    maven { url "https://jitpack.io" }
}

Then, just add the dependency pointing to the GitHub repo:

dependencies {
    compile 'com.github.JakeWharton:ViewPagerIndicator:2.4.1@aar'
}

Solution 5

Add this to your dependencies in your app module's build.gradle file like so:

dependencies {
   compile 'com.github.JakeWharton:ViewPagerIndicator:2.4.1'
   ...
}
Share:
99,501
loeschg
Author by

loeschg

Updated on November 02, 2020

Comments

  • loeschg
    loeschg over 3 years

    I'm trying to use Jake Wharton's ViewPagerIndicator library, but I'm unable to get it working with my Gradle project in Android Studio.

    I add it as a dependency like so:

        dependencies {
           // ... other ommitted
           compile 'com.viewpagerindicator:library:2.4.1'
           compile 'com.android.support:support-v4:19.0.1'
           compile 'com.nineoldandroids:library:2.4.0'
           // ...
        }
    

    but the project doesn't seem to recognize any components in the library. I'm wondering if there's a dependency issue with different support-v4 versions or something in nineoldandroids...?

  • loeschg
    loeschg over 10 years
    Thanks, @pyus13. Yeah, that sync project button is my first step when adding a new dependency. That wasn't the issue. I updated my question.
  • loeschg
    loeschg over 10 years
    Yeah, this is a possibility. There's a pull request open to update the v4 support library (github.com/JakeWharton/Android-ViewPagerIndicator/pull/271)‌​. Doesn't look like this project is being actively maintained... :(
  • Piyush Agarwal
    Piyush Agarwal over 10 years
    @loeschg i did not find that jackwarton has moved viewpagerindicator in gradle. It might be a problem.
  • Eugen Martynov
    Eugen Martynov over 10 years
    Hey, but ViewPagerInidicator is android library. It means if they use maven then it is most probably apklib artefact and gradle works with war artefact only
  • Ferran Maylinch
    Ferran Maylinch over 10 years
    Thanks! Just wanted to remark that bintray repo must be above mavenCentral(). You can read this: blog.haunted-soft.com/2013/10/…
  • Luke Sleeman
    Luke Sleeman over 10 years
    This no longer seems to work - I followed the steps and when android studio refreshes the project I get "Gradle 'XYZ' project refresh failed: Artifact 'com.viewpagerindicator:library:2.4.1:library.aar' not found.
  • Luke Sleeman
    Luke Sleeman over 10 years
    After lots of mucking around I have found recent versions of android studio produce projects with two gradle files - one inside at app/build.gradle and one at /build.gradel - the one in the root directory is where you can add configuration options common to all sub-projects/modules. You need to put: allprojects { repositories { maven { url "dl.bintray.com/populov/maven" } mavenCentral() } } in the top level build.gradle for it to work
  • Zac Sweers
    Zac Sweers about 10 years
    @Johan I included a link at the bottom of my post to an example
  • Zac Sweers
    Zac Sweers about 10 years
    That's odd. I just used the same method to add it to another project earlier this week and it still works fine for me :/
  • Johan
    Johan about 10 years
    I did see the example. I take it the example are the two files from root and from app. In the app build.gradle I added repositories { maven { url "dl.bintray.com/populov/maven" }mavenCentral()} and in dependencies { compile 'com.viewpagerindicator:library:2.4.1@aar', I am probably missing something, since I get the error: Error:Artifact 'com.viewpagerindicator:library:2.4.1:library.aar' not found. (I'm using A.S. 5.8)
  • Zac Sweers
    Zac Sweers about 10 years
    Wait, were you meaning that doesn't work or that it's just not a comprehensive example?
  • Johan
    Johan about 10 years
    The example does not work with android studio 5.8 gradle 0.9.+, but it is comprehensive.
  • Johan
    Johan about 10 years
    What gradle and Android Studio versions do you use?
  • Zac Sweers
    Zac Sweers about 10 years
    0.9.+ on an older project (but it still works there). Maybe try upgrading to 0.10.+? Here's a working example with that from a gradle migration i did for a friend's project earlier this week: github.com/pandanomic/utexas-utilities/blob/master/build.gra‌​dle
  • Johan
    Johan about 10 years
    Thanks for trying to help me, changed it, but I still do not get it working, still it complains on "Error:Artifact 'com.viewpagerindicator:library:2.4.1:library.aar' not found.". I uploaded a version of my files here: textuploader.com/r346
  • Oleg Vaskevich
    Oleg Vaskevich about 10 years
    @Johan: I had the same error. I almost got it to work using compile group: 'com.viewpagerindicator', name: 'library', version: '2.4.1', ext: 'apklib', but then ran into an issue with the duplicate AndroidManifest.xml file.
  • Johan
    Johan about 10 years
    I got it working.. but not by using maven. I created a folder named libraries in my root and there I put the source code. That code I made sure worked as a library. Then I importet that as a module.
  • Ricardo Pessoa
    Ricardo Pessoa about 10 years
    attention now the dependency is compile 'com.viewpagerindicator:library:2.4.1' [reference:]mvnrepository.com/artifact/com.viewpagerindicato‌​r/library/2.4.1
  • John Hamelink
    John Hamelink about 10 years
    This is no longer correct advice, as the @aar suffix is no longer needed.
  • Zac Sweers
    Zac Sweers almost 10 years
    @RicardoPessoa You are mistaken. The whole reason it's listed with an aar is because the one in mavencentral is an apklib and doesn't have one. By specifying the bintray repo before mavenCentral(), it will use the aar one there instead. Also, to the person that edited it without checking first, please be more thorough before making edits.
  • Zac Sweers
    Zac Sweers almost 10 years
    @OlegVaskevich you are trying to compile the wrong library. You need to use the aar in the bintray repo specified in the answer above. There's a fair amount of misinformation in this thread not being helped by people making bad edits to my answer.
  • Lv.BeLeCk
    Lv.BeLeCk over 9 years
    As of today you should remove the "@aar", gradle cannot find it but it works with "compile 'com.viewpagerindicator:library:2.4.1'"
  • Zac Sweers
    Zac Sweers over 9 years
    @Lv.BeLeCk this is not correct. As you can see in the below link, the aar is still there. dl.bintray.com/populov/maven/com/viewpagerindicator/library/‌​…
  • trippedout
    trippedout over 9 years
    also note if you are using the support library elsewhere and have it added to your dependencies, you might get a weird error since viewpager also brings in its own version of support v4. refer to this link - stackoverflow.com/questions/20989317/…
  • voghDev
    voghDev over 9 years
    Brilliant. I could make it work just now. I confirm that the dependency finishes in 2.4.1@aar, that's the correct version to make it work.
  • Greg Ennis
    Greg Ennis over 9 years
    Thank you. I did not want to add some random maven repository to my build script. This much better.
  • Sam
    Sam about 9 years
    Didn't work for me; got Artifact 'library.aar (com.viewpagerindicator:library:2.4.1)' not found. Searched in the following locations: https://jcenter.bintray.com/com/viewpagerindicator/library/2‌​.4.1/library-2.4.1.a‌​ar.
  • Sam
    Sam about 9 years
    Just to clarify, library-2.4.1.aar needs to be put in your module's libs directory, which you should create if it doesn't already exist.
  • rrrocky
    rrrocky about 9 years
    I added the said dependency but it fails to resolve it on gradle build. Exact error: Failed to resolve: fr.avianey.com.viewpagerindicator:library:2.4.1 Any reason why?
  • avianey
    avianey about 9 years
    did you add the repository in the right section... I mean not in the plugin repositories...
  • rrrocky
    rrrocky about 9 years
    I added it in the dependency section in the individual module build.gradle file. Here
  • avianey
    avianey about 9 years
    just put it outside of the android closure... at the same level as the apply plugin
  • rrrocky
    rrrocky about 9 years
    Error:(4, 0) Gradle DSL method not found: 'compile()' Possible causes:The project 'Pigen' may be using a version of Gradle that does not contain the method. Gradle settingsThe build file may be missing a Gradle plugin. Apply Gradle plugin What do I do now? Which plugin should I use?
  • rrrocky
    rrrocky about 9 years
    Am I missing something here?
  • Mark
    Mark about 9 years
    fr.avianey.com.viewpagerindicator:library:2.4.1@aar - you're missing the @aar
  • friederbluemle
    friederbluemle over 8 years
    This did not work for me, as the pom file seems to have a dependency on com.google.android:android. Variant Debug has a dependency on version 4.1.1.4 of the legacy com.google.android Maven artifact, which corresponds to API level 15.
  • friederbluemle
    friederbluemle over 8 years
    Explicitly excluding transitive dependencies fixed the build: compile('fr.avianey.com.viewpagerindicator:library:2.4.1') { transitive = false; }
  • moDev
    moDev over 8 years
    This doesn't work in 4.4 and it throws Didn't find class com.viewpagerindicator.CirclePageIndicator
  • avianey
    avianey over 8 years
    that's not related to the android version, whether yuor sdk version or your project setup
  • Muhammad
    Muhammad over 8 years
    Saved the day thanks :) I'll post your answer somewhere else stackoverflow.com/questions/25702884/….
  • avianey
    avianey over 8 years
    update top 2.4.1.1 which switch from deprecated FloatMath to Math so you can use proguard with latest SDK
  • MiguelHincapieC
    MiguelHincapieC about 8 years
    you should use this answer at 2016
  • RoCkDevstack
    RoCkDevstack about 8 years
    @Juan Andres - Is it ok if I take the gradle only?
  • Govinda Paliwal
    Govinda Paliwal over 7 years
    not working : Error:Packaging for dependency com.viewpagerindicator:library:2.4.1 is 'apklib' and is not supported. Only 'aar' libraries are supported.
  • user2408952
    user2408952 over 7 years
    Idd this is the correct way to do it. Since it goes directly to the source project on GitHub, skipping 3th party sites.