Using ViewPagerIndicator library with Android Stud

2019-01-03 04:55发布

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条回答
混吃等死
2楼-- · 2019-01-03 05:09

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'
    ....
}
查看更多
老娘就宠你
3楼-- · 2019-01-03 05:11

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)

查看更多
爷、活的狠高调
4楼-- · 2019-01-03 05:12

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'
}
查看更多
倾城 Initia
5楼-- · 2019-01-03 05:12

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'
}
查看更多
相关推荐>>
6楼-- · 2019-01-03 05:13

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.

查看更多
三岁会撩人
7楼-- · 2019-01-03 05:13

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

查看更多
登录 后发表回答