Using ViewPagerIndicator library with Android Studio and Gradle

AndroidGradleAndroid StudioViewpagerindicator

Android Problem Overview


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

Android Solutions


Solution 1 - Android

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 - Android

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 - Android

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 - Android

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 - Android

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

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

Solution 6 - Android

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

Solution 7 - Android

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!

Solution 8 - Android

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.

Solution 9 - Android

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.

Solution 10 - Android

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

Solution 11 - Android

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'
    ....
}

Solution 12 - Android

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

Solution 13 - Android

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

Solution 14 - Android

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.

Solution 15 - Android

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

implementation 'com.inkapplications.viewpageindicator:library:2.4.3'

Solution 16 - Android

Please check this first

https://stackoverflow.com/questions/21102598/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.

Solution 17 - Android

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.

Solution 18 - Android

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

Solution 19 - Android

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)

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionloeschgView Question on Stackoverflow
Solution 1 - AndroidavianeyView Answer on Stackoverflow
Solution 2 - AndroidZac SweersView Answer on Stackoverflow
Solution 3 - AndroidmugiwarapyView Answer on Stackoverflow
Solution 4 - AndroidJuan Andrés DianaView Answer on Stackoverflow
Solution 5 - AndroidMd Yusuf AlamView Answer on Stackoverflow
Solution 6 - AndroidParsania HardikView Answer on Stackoverflow
Solution 7 - AndroidvrunoaView Answer on Stackoverflow
Solution 8 - AndroidJensView Answer on Stackoverflow
Solution 9 - AndroidJitesh UpadhyayView Answer on Stackoverflow
Solution 10 - AndroiddevguyView Answer on Stackoverflow
Solution 11 - AndroidnyxeeView Answer on Stackoverflow
Solution 12 - AndroidSamView Answer on Stackoverflow
Solution 13 - AndroidODAXYView Answer on Stackoverflow
Solution 14 - AndroidFlame of udunView Answer on Stackoverflow
Solution 15 - AndroidRajan KashiyaniView Answer on Stackoverflow
Solution 16 - AndroidPiyush AgarwalView Answer on Stackoverflow
Solution 17 - AndroidBabatunde AdeyemiView Answer on Stackoverflow
Solution 18 - AndroidUday RamjiyaniView Answer on Stackoverflow
Solution 19 - Androidcn123hView Answer on Stackoverflow