120

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...?

Mr-IDE
  • 7,051
  • 1
  • 53
  • 59
loeschg
  • 29,961
  • 26
  • 97
  • 150

19 Answers19

204

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()
}
starball
  • 20,030
  • 7
  • 43
  • 238
avianey
  • 5,545
  • 3
  • 37
  • 60
  • 4
    Thank you. I did not want to add some random maven repository to my build script. This much better. – Greg Ennis Mar 13 '15 at 21:21
  • 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? – rrrocky Jun 07 '15 at 21:25
  • did you add the repository in the right section... I mean not in the plugin repositories... – avianey Jun 08 '15 at 12:10
  • I added it in the `dependency` section in the individual module `build.gradle` file. [Here](http://pastie.org/10229441) – rrrocky Jun 08 '15 at 13:06
  • just put it outside of the android closure... at the same level as the apply plugin – avianey Jun 08 '15 at 13:26
  • 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 Jun 08 '15 at 18:00
  • Am I missing something here? – rrrocky Jun 09 '15 at 05:44
  • 2
    fr.avianey.com.viewpagerindicator:library:2.4.1@aar - you're missing the @aar – Mark Jun 27 '15 at 01:46
  • 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 Oct 30 '15 at 09:44
  • Explicitly excluding transitive dependencies fixed the build: `compile('fr.avianey.com.viewpagerindicator:library:2.4.1') { transitive = false; }` – friederbluemle Oct 30 '15 at 09:48
  • This doesn't work in 4.4 and it throws `Didn't find class com.viewpagerindicator.CirclePageIndicator` – moDev Dec 30 '15 at 11:41
  • that's not related to the android version, whether yuor sdk version or your project setup – avianey Dec 30 '15 at 12:52
  • update top 2.4.1.1 which switch from deprecated FloatMath to Math so you can use proguard with latest SDK – avianey Feb 15 '16 at 13:39
146

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

FoamyGuy
  • 46,603
  • 18
  • 125
  • 156
Zac Sweers
  • 3,101
  • 2
  • 18
  • 20
  • 5
    Thanks! Just wanted to remark that bintray repo must be above mavenCentral(). You can read this: http://blog.haunted-soft.com/2013/10/viewpagerindicator-aar-packaged.html – Ferran Maylinch Mar 19 '14 at 20:29
  • 5
    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 Mar 25 '14 at 05:53
  • 30
    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 "http://dl.bintray.com/populov/maven" } mavenCentral() } } in the top level build.gradle for it to work – Luke Sleeman Mar 25 '14 at 06:40
  • @Johan I included a link at the bottom of my post to an example – Zac Sweers May 13 '14 at 14:04
  • 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 "http://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) – Johan May 13 '14 at 14:17
  • Wait, were you meaning that doesn't work or that it's just not a comprehensive example? – Zac Sweers May 13 '14 at 14:21
  • The example does not work with android studio 5.8 gradle 0.9.+, but it is comprehensive. – Johan May 13 '14 at 14:34
  • What gradle and Android Studio versions do you use? – Johan May 13 '14 at 14:46
  • 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: https://github.com/pandanomic/utexas-utilities/blob/master/build.gradle – Zac Sweers May 13 '14 at 14:50
  • 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: http://textuploader.com/r346 – Johan May 14 '14 at 06:24
  • @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. – Oleg Vaskevich May 15 '14 at 07:35
  • 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. – Johan May 15 '14 at 13:18
  • 67
    attention now the dependency is **compile 'com.viewpagerindicator:library:2.4.1'** [reference:]http://mvnrepository.com/artifact/com.viewpagerindicator/library/2.4.1 – Ricardo Pessoa May 27 '14 at 10:41
  • 3
    @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 Aug 18 '14 at 23:35
  • 4
    @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. – Zac Sweers Aug 18 '14 at 23:38
  • 1
    As of today you should remove the "@aar", gradle cannot find it but it works with "compile 'com.viewpagerindicator:library:2.4.1'" – Lv.BeLeCk Nov 18 '14 at 15:04
  • 1
    @Lv.BeLeCk this is not correct. As you can see in the below link, the aar is still there. http://dl.bintray.com/populov/maven/com/viewpagerindicator/library/2.4.1/#library-2.4.1.aar – Zac Sweers Nov 19 '14 at 03:55
  • 1
    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. – voghDev Jan 16 '15 at 15:19
  • 1
    you should use [this answer](http://stackoverflow.com/a/35761063/1332549) at 2016 – MiguelHincapieC Apr 14 '16 at 16:35
55

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'
   // ...
}
mugiwarapy
  • 561
  • 4
  • 4
  • 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 - http://stackoverflow.com/questions/20989317/multiple-dex-files-define-landroid-support-v4-accessibilityservice-accessibility – trippedout Dec 16 '14 at 19:45
50

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'
}
Juan Andrés Diana
  • 2,215
  • 3
  • 25
  • 36
28

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

dependencies {
   compile 'com.github.JakeWharton:ViewPagerIndicator:2.4.1'
   ...
}
Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Md Yusuf Alam
  • 421
  • 4
  • 5
  • 1
    Idd this is the correct way to do it. Since it goes directly to the source project on GitHub, skipping 3th party sites. – user2408952 Mar 07 '17 at 11:30
9

I did the trick by following this. No need to import library or nothing. Just two steps and bingo, it works perfectly.

In build.gradle(Project:...):

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

In build.gradle(Module:app):

dependencies {
            compile 'com.github.JakeWharton:ViewPagerIndicator:2.4.1'
    }
Parsania Hardik
  • 4,593
  • 1
  • 33
  • 33
5

I could not manage to import the project with any of the answers. I'm using Android Studio 0.8.6 and gradle 1.12.

The only solution I came up with was downloading the .aar library from:

http://dl.bintray.com/populov/maven/com/viewpagerindicator/library/2.4.1/

and then import the library in gradle like this:

 repositories {
      flatDir {
        dirs 'libs'}
   }

 dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:20.0.0'
    compile(name:'library-2.4.1', ext:'aar') 
  }

Hope this helps!

Mohammad Ersan
  • 12,304
  • 8
  • 54
  • 77
vrunoa
  • 766
  • 8
  • 15
  • 2
    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. – Sam May 29 '15 at 11:23
4

I am using Studio 0.8.6 and Gradle 1.12

A difference in my project might have been that I am also using the compatbility libraries which made gradle complain about having the support-v4 lib twice.

So I had to exclude the already included support-v4 like this:

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:support-v4:19.0.1'
    compile 'com.android.support:appcompat-v7:19.0.1'    
    compile ('com.viewpagerindicator:library:2.4.1') {
        exclude module: 'support-v4'
    }
}

Then it also complained about having the AndroidManifest.xml file twice.

So I also added exclude 'AndroidManifest.xml' in the android section like this:

android {
    packagingOptions {
        exclude 'AndroidManifest.xml'
    }

Then it worked.

Jens
  • 6,243
  • 1
  • 49
  • 79
  • not working : Error:Packaging for dependency com.viewpagerindicator:library:2.4.1 is 'apklib' and is not supported. Only 'aar' libraries are supported. – Govinda P Dec 28 '16 at 15:30
3

please make sure that support:support-v4 is same in all the libs and yours application, sometime it causes problem so use same support:support-v4 across libs and your app project.

Jitesh Upadhyay
  • 5,244
  • 2
  • 25
  • 43
  • Yeah, this is a possibility. There's a pull request open to update the v4 support library (https://github.com/JakeWharton/Android-ViewPagerIndicator/pull/271). Doesn't look like this project is being actively maintained... :( – loeschg Jan 15 '14 at 15:23
  • 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 – Eugen Martynov Jan 16 '14 at 07:28
3

The post marked as answer didn't work for me...Gradle complained about "Connection refused".

Considering that it looks like it's stable after all this time, I just download the aar file from https://bintray.com/populov/maven/com.viewpagerindicator:library, copied into my libs folder, and referenced it like so:

dependencies {
...
compile 'com.viewpagerindicator:library:2.4.1@aar'
}
devguy
  • 2,336
  • 5
  • 27
  • 31
  • 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 :/ – Zac Sweers May 13 '14 at 14:07
  • 1
    This is no longer correct advice, as the @aar suffix is no longer needed. – John Hamelink Jun 14 '14 at 16:37
  • 4
    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.aar`. – Sam May 29 '15 at 11:07
2

This is what worked for me:

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

i.e, do not use the repo URL.

then use:

dependencie {
    ....
    compile 'com.mcxiaoke.viewpagerindicator:library:2.4.1@aar'
    ....
}
nyxee
  • 2,773
  • 26
  • 22
2
Add it in your build.gradle at the end of repositories:
Ste 1
 repositories {
        // ...
        maven { url "https://jitpack.io" }
    }
Step 2. Add the dependency in the form

    dependencies {
            compile 'com.github.JakeWharton:ViewPagerIndicator:2.4.1@aar'
    }
Sam
  • 6,215
  • 9
  • 71
  • 90
2

Also try to put maven repository before others.

 buildscript {
    repositories {
        maven { url "http://dl.bintray.com/populov/maven" }
        mavenCentral()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:1.3.0'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

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

And build with dependencies:

  apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.1"

    defaultConfig {
        applicationId ""
        minSdkVersion 10
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:23.0.1'
    compile 'com.viewpagerindicator:library:2.4.1'
}
ODAXY
  • 335
  • 4
  • 12
2

For the sake of variety here is an answer that doesn't use maven:

  1. Download zip/tgz from ViewPagerIndicator

  2. In the project window, select project navigation.

  3. Go to project > New > Module.

  4. Import Gradle Project

  5. Browse to and select the unzipped library folder. Name the module whatever you want to. I named it viewPagerIndicator

  6. Keep clicking next until you reach the last window where Finish is clickable. If you get the Android Support Library is not installed message, don't worry. Just go ahead and click Finish.

  7. Wait for gradle build and project compilation to finish. Once completed, add this to dependencies { .. } in build.gradle (Module:app):

     compile project(':viewPagerIndicator')
    

The library is now available for your use.

Flame of udun
  • 2,136
  • 7
  • 35
  • 79
1

It has an issue of newer gradle. Just change dependency like below.

implementation 'com.inkapplications.viewpageindicator:library:2.4.3'
Rajan Kashiyani
  • 891
  • 7
  • 11
0

Please check this first

Android Studio - UNEXPECTED TOP-LEVEL EXCEPTION:

if these checks are ok do mentioned below.

No need to include support-v4 as dependency of your module because ViewPagerIndicator library already having support-v4 as its dependency. So you can try to remove that and do sync with gradle using tiny lovely gradle button available in toolbar -

enter image description here

Update your question if you are getting any error in syncing.

UPDATED :

I am not sure but It might be a problem I did not find any ViewPagerIndicator Library based on gradle. JackWarton has moved actionbarsherlock in gradle but ViewPagerIndicator still using maven.

Community
  • 1
  • 1
Piyush Agarwal
  • 25,608
  • 8
  • 98
  • 111
  • 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 Jan 15 '14 at 15:17
  • @loeschg i did not find that jackwarton has moved viewpagerindicator in gradle. It might be a problem. – Piyush Agarwal Jan 15 '14 at 15:35
0

You can just include the ViewPagerIndicator library directly within your application as described here

It enables you to import the ViewPagerIndicator library as an “Existing Project” to your current project.

Community
  • 1
  • 1
Babatunde Adeyemi
  • 14,360
  • 4
  • 34
  • 26
0

For me also any of the above solution didn't worked. But this worked for me.

  1. Just include the required librabry from here Viewpagerindicator Library

  2. Include this in your app module's build.gradle (you won't have repository there just include it above dependencies.

repositories {
    flatDir{
        dirs 'libs'
    }
}
  1. add this into your dependencies.

compile (name:'library-2.4.1',ext:'aar')
gotqn
  • 42,737
  • 46
  • 157
  • 243
Uday Ramjiyani
  • 1,407
  • 9
  • 22
0

To sum up: you can search "ViewPagerIndicator" in http://mvnrepository.com/, you will find out the original com.viewpagerindicator doesn't have the red marker "Android Packages", so you cannot use it with Gradle. You can find another one with the red marker, make sure it has the same version as the original one. (i.e. some one create an android package based on the original one)

cn123h
  • 2,302
  • 1
  • 21
  • 16