Using ViewPagerIndicator library with Android Studio and Gradle
Asked Answered
C

19

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

Collettecolletti answered 15/1, 2014 at 5:50 Comment(0)
M
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()
}
Magnum answered 8/11, 2014 at 12:19 Comment(13)
Thank you. I did not want to add some random maven repository to my build script. This much better.Bronder
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?Polygynous
did you add the repository in the right section... I mean not in the plugin repositories...Magnum
I added it in the dependency section in the individual module build.gradle file. HerePolygynous
just put it outside of the android closure... at the same level as the apply pluginMagnum
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?Polygynous
Am I missing something here?Polygynous
fr.avianey.com.viewpagerindicator:library:2.4.1@aar - you're missing the @aarDelano
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.Palomino
Explicitly excluding transitive dependencies fixed the build: compile('fr.avianey.com.viewpagerindicator:library:2.4.1') { transitive = false; }Palomino
This doesn't work in 4.4 and it throws Didn't find class com.viewpagerindicator.CirclePageIndicatorOconner
that's not related to the android version, whether yuor sdk version or your project setupMagnum
update top 2.4.1.1 which switch from deprecated FloatMath to Math so you can use proguard with latest SDKMagnum
P
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

Polonaise answered 2/3, 2014 at 11:35 Comment(19)
Thanks! Just wanted to remark that bintray repo must be above mavenCentral(). You can read this: blog.haunted-soft.com/2013/10/…Finzer
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.Planksheer
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 workPlanksheer
@Johan I included a link at the bottom of my post to an examplePolonaise
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)Aweigh
Wait, were you meaning that doesn't work or that it's just not a comprehensive example?Polonaise
The example does not work with android studio 5.8 gradle 0.9.+, but it is comprehensive.Aweigh
What gradle and Android Studio versions do you use?Aweigh
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.gradlePolonaise
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/r346Aweigh
@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.Bowline
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.Aweigh
attention now the dependency is compile 'com.viewpagerindicator:library:2.4.1' [reference:]mvnrepository.com/artifact/com.viewpagerindicator/library/2.4.1Disini
@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.Polonaise
@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.Polonaise
As of today you should remove the "@aar", gradle cannot find it but it works with "compile 'com.viewpagerindicator:library:2.4.1'"Ludie
@Ludie 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/…Polonaise
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.Murrah
you should use this answer at 2016Shrinkage
H
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'
   // ...
}
Haupt answered 29/7, 2014 at 19:18 Comment(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 - #20989817Shellfish
C
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'
}
Clef answered 10/8, 2015 at 17:24 Comment(2)
Saved the day thanks :) I'll post your answer somewhere else #25703384.Nur
@Juan Andres - Is it ok if I take the gradle only?Prosaic
G
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'
   ...
}
Gonfalon answered 10/5, 2016 at 1:41 Comment(1)
Idd this is the correct way to do it. Since it goes directly to the source project on GitHub, skipping 3th party sites.Alyssa
I
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'
    }
Isogamete answered 23/4, 2016 at 6:57 Comment(0)
D
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!

Deport answered 1/9, 2014 at 21:26 Comment(1)
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.Checkmate
H
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.

Hau answered 11/9, 2014 at 20:43 Comment(1)
not working : Error:Packaging for dependency com.viewpagerindicator:library:2.4.1 is 'apklib' and is not supported. Only 'aar' libraries are supported.Unseat
S
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.

Streamline answered 15/1, 2014 at 5:55 Comment(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... :(Collettecolletti
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 onlyCowled
T
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'
}
Thief answered 3/5, 2014 at 10:45 Comment(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 :/Polonaise
This is no longer correct advice, as the @aar suffix is no longer needed.Orourke
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.Checkmate
L
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'
    ....
}
Leverrier answered 15/9, 2015 at 6:0 Comment(0)
C
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'
    }
Checkmate answered 23/9, 2015 at 13:48 Comment(0)
R
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'
}
Reprobation answered 15/10, 2015 at 14:6 Comment(0)
S
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.

Stiffnecked answered 11/4, 2016 at 17:36 Comment(0)
S
1

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

implementation 'com.inkapplications.viewpageindicator:library:2.4.3'
Sestertium answered 2/11, 2018 at 9:52 Comment(0)
B
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.

Bowen answered 15/1, 2014 at 7:17 Comment(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.Collettecolletti
@Collettecolletti i did not find that jackwarton has moved viewpagerindicator in gradle. It might be a problem.Bowen
D
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.

Debauchee answered 30/9, 2014 at 22:47 Comment(0)
C
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')
Canal answered 20/9, 2015 at 7:34 Comment(0)
A
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)

Alfredoalfresco answered 16/10, 2015 at 6:5 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.