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

19 Answers 19

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()
}
13
  • 4
    Thank you. I did not want to add some random maven repository to my build script. This much better.
    – Greg Ennis
    Mar 13, 2015 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 7, 2015 at 21:25
  • did you add the repository in the right section... I mean not in the plugin repositories...
    – avianey
    Jun 8, 2015 at 12:10
  • I added it in the dependency section in the individual module build.gradle file. Here
    – rrrocky
    Jun 8, 2015 at 13:06
  • 2
    fr.avianey.com.viewpagerindicator:library:2.4.1@aar - you're missing the @aar
    – Mark
    Jun 27, 2015 at 1:46
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

19
  • 5
    Thanks! Just wanted to remark that bintray repo must be above mavenCentral(). You can read this: blog.haunted-soft.com/2013/10/… Mar 19, 2014 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. Mar 25, 2014 at 5: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 "dl.bintray.com/populov/maven" } mavenCentral() } } in the top level build.gradle for it to work Mar 25, 2014 at 6:40
  • 67
    attention now the dependency is compile 'com.viewpagerindicator:library:2.4.1' [reference:]mvnrepository.com/artifact/com.viewpagerindicator/library/2.4.1 May 27, 2014 at 10:41
  • 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, 2014 at 23:38
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'
   // ...
}
1
  • 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/…
    – trippedout
    Dec 16, 2014 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'
}
2
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'
   ...
}
1
  • 1
    Idd this is the correct way to do it. Since it goes directly to the source project on GitHub, skipping 3th party sites. Mar 7, 2017 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'
    }
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!

1
  • 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, 2015 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.

1
  • 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, 2016 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.

2
  • 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... :(
    – loeschg
    Jan 15, 2014 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 Jan 16, 2014 at 7: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'
}
3
  • 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, 2014 at 14:07
  • 1
    This is no longer correct advice, as the @aar suffix is no longer needed. Jun 14, 2014 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, 2015 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'
    ....
}
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'
    }
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'
}
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.

1

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

implementation 'com.inkapplications.viewpageindicator:library:2.4.3'
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.

2
  • 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, 2014 at 15:17
  • @loeschg i did not find that jackwarton has moved viewpagerindicator in gradle. It might be a problem. Jan 15, 2014 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.

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')

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)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.