在 Android Studio 和 Gradle 中使用 ViewPagerIndicator 库
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21130003/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Using ViewPagerIndicator library with Android Studio and Gradle
提问by loeschg
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.
我正在尝试使用 Jake Wharton 的ViewPagerIndicator 库,但我无法在 Android Studio 中使用我的 Gradle 项目。
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...?
但该项目似乎无法识别库中的任何组件。我想知道是否存在不同 support-v4 版本的依赖问题或 Nineoldandroids 中的某些东西...?
回答by avianey
I just pushed a version inside maven central so you only need to add that dependency :
我刚刚在 maven central 中推送了一个版本,因此您只需要添加该依赖项:
compile 'fr.avianey.com.viewpagerindicator:library:2.4.1.1@aar'
And declare maven central like this :
并像这样声明 maven central:
repositories {
mavenCentral()
}
Hope it helps...
希望能帮助到你...
回答by Zac Sweers
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:
Jake Wharton 还没有在 maven 中作为 aar 发布它。虽然有一个组通过他们的服务器提供了一个可用的 aar,你可以在你的 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.
这将获取他们的 maven 存储库,其中包含他们放在一起的打包 aar。完成后,您可以简单地将此行添加到您的依赖项中,一旦您将项目与 gradle 文件同步,一切都应该可以正常工作。
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.
确保 Maven Repo 列在mavenCentral()
条目上方。否则,它会首先在 maven 的中央存储库中查找并找到错误的包。
Android Studio generates two build.gradle
files for projects, make sure you put this in the right one!
Android Studiobuild.gradle
为项目生成两个文件,请确保将其放在正确的一个中!
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
https://github.com/pandanomic/SUREwalk_android/blob/master/surewalk/build.gradle
回答by mugiwarapy
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:
我在 Android Studio 0.8.2 中使用 gradle 0.10.+ 并且接受的答案对我不起作用。为了让 ABS 在我的项目中工作,我必须做一些细微的更改:
In the top level build.gradle
file of your project add the maven repository in the allprojects
config like this:
在项目的顶级build.gradle
文件中,allprojects
像这样在配置中添加 Maven 存储库:
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
:
并在模块的build.gradle
文件中添加不带以下内容的依赖项@aar
:
dependencies {
// ...
compile 'com.viewpagerindicator:library:2.4.1'
// ...
}
回答by Juan Andrés Diana
Jitpack.iois greatfor this situation.
Jitpack.io是伟大的这种情况。
First, add the following repository:
首先,添加以下存储库:
repositories {
// ...
maven { url "https://jitpack.io" }
}
Then, just add the dependency pointing to the GitHub repo:
然后,只需添加指向 GitHub 存储库的依赖项:
dependencies {
compile 'com.github.JakeWharton:ViewPagerIndicator:2.4.1@aar'
}
回答by Md Yusuf Alam
Add this to your dependencies in your app module's build.gradle file like so:
将此添加到您的应用程序模块的 build.gradle 文件中的依赖项中,如下所示:
dependencies {
compile 'com.github.JakeWharton:ViewPagerIndicator:2.4.1'
...
}
回答by Parsania Hardik
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:...):
在 build.gradle(Project:...) 中:
allprojects {
repositories {
...
maven { url "https://jitpack.io" }
}
}
In build.gradle(Module:app):
在 build.gradle(Module:app) 中:
dependencies {
compile 'com.github.JakeWharton:ViewPagerIndicator:2.4.1'
}
回答by vrunoa
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.
我无法使用任何答案导入项目。我使用的是 Android Studio 0.8.6 和 gradle 1.12。
The only solution I came up with was downloading the .aar library from:
我想出的唯一解决方案是从以下位置下载 .aar 库:
http://dl.bintray.com/populov/maven/com/viewpagerindicator/library/2.4.1/
http://dl.bintray.com/populov/maven/com/viewpagerindicator/library/2.4.1/
and then import the library in gradle like this:
然后像这样在gradle中导入库:
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!
希望这可以帮助!
回答by Jens
I am using Studio 0.8.6 and Gradle 1.12
我正在使用 Studio 0.8.6 和 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.
我的项目中的一个不同之处可能是我还使用了兼容性库,这让 gradle 抱怨support-v4
两次拥有该库。
So I had to exclude the already included support-v4
like this:
所以我不得不support-v4
像这样排除已经包含的:
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.
然后它也抱怨有AndroidManifest.xml
两次文件。
So I also added exclude 'AndroidManifest.xml'
in the android
section like this:
所以我也在这样exclude 'AndroidManifest.xml'
的android
部分中添加了:
android {
packagingOptions {
exclude 'AndroidManifest.xml'
}
Then it worked.
然后它起作用了。
回答by Jitesh Upadhyay
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.
请确保所有库和您的应用程序中的 support:support-v4 相同,有时它会导致问题,因此请在库和您的应用程序项目中使用相同的 support:support-v4。
回答by devguy
The post marked as answer didn't work for me...Gradle complained about "Connection refused".
标记为答案的帖子对我不起作用......Gradle 抱怨“连接被拒绝”。
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:
考虑到它看起来很稳定,我只是从https://bintray.com/populov/maven/com.viewpagerindicator:library下载 aar 文件,复制到我的 libs 文件夹中,并像这样引用它:
dependencies {
...
compile 'com.viewpagerindicator:library:2.4.1@aar'
}