问题
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...?
回答1:
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...
回答2:
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
回答3:
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'
// ...
}
回答4:
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'
}
回答5:
Add this to your dependencies in your app module's build.gradle file like so:
dependencies {
compile 'com.github.JakeWharton:ViewPagerIndicator:2.4.1'
...
}
回答6:
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'
}
回答7:
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!
回答8:
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.
回答9:
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.
回答10:
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'
}
回答11:
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'
....
}
回答12:
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'
}
回答13:
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'
}
回答14:
For the sake of variety here is an answer that doesn't use maven:
Download zip/tgz from ViewPagerIndicator
In the project window, select project navigation.
Go to project > New > Module.
Import Gradle Project
Browse to and select the unzipped library folder. Name the module whatever you want to. I named it
viewPagerIndicator
Keep clicking next until you reach the last window where
Finish
is clickable. If you get theAndroid Support Library is not installed
message, don't worry. Just go ahead and clickFinish
.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.
回答15:
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 -
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.
回答16:
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.
回答17:
For me also any of the above solution didn't worked. But this worked for me.
Just include the required librabry from here Viewpagerindicator Library
Include this in your app module's build.gradle (you won't have repository there just include it above dependencies.
repositories {
flatDir{
dirs 'libs'
}
}
- add this into your dependencies.
compile (name:'library-2.4.1',ext:'aar')
回答18:
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)
回答19:
It has an issue of newer gradle. Just change dependency like below.
implementation 'com.inkapplications.viewpageindicator:library:2.4.3'
来源:https://stackoverflow.com/questions/21130003/using-viewpagerindicator-library-with-android-studio-and-gradle