将 ViewPagerIndicator 添加到 Android Studio [英] Add ViewPagerIndicator to Android Studio
问题描述
我正在尝试让 Jake Wharton 的 ViewPagerIndicator 与 Android Studio 一起工作,但不幸的是它不起作用.
我从此处下载了 .aar 文件,并将其包含在我的 libs 文件夹中.
我是这样引用的:
i'm trying to get Jake Wharton's ViewPagerIndicator working with Android Studio but unfortunately it won't work.
I downloaded the .aar file from here and included it in my libs folder.
I referenced it like this:
compile files('src/main/libs/viewpagerindicator_2.4.1.aar')
Android Studio 给我以下错误:
Android Studio gives me the following error:
Error:duplicate files during packaging of APK
我对 gradle 不是很熟悉,当它给我这个错误时不知道该怎么办.
你能帮我解决这个问题吗?
I'm not very familiar with gradle and don't know what to do when it gives me this error.
Can you please help me with this one?
这是我完整的 build.gradle:
Here's my complete build.gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 19
buildToolsVersion "20.0.0"
defaultConfig {
applicationId "de.xxx"
minSdkVersion 15
targetSdkVersion 19
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
dependencies {
compile 'com.android.support:support-v4:20.0.0'
compile 'com.github.amlcurran.showcaseview:library:5.0.0'
compile files('src/main/libs/PdfViewer.jar')
compile files('src/main/libs/viewpagerindicator_2.4.1.aar')
}
推荐答案
UPDATE
根据 Jürgen 'Kashban' Wahlmann 给出的答案,现在可以通过 gradle 添加 ViewPagerIndicator:
Based on the answer given by Jürgen 'Kashban' Wahlmann, it is now possible to add ViewPagerIndicator via gradle:
顶级 Build.gradle:
Top Level Build.gradle:
buildscript {
repositories {
maven { url "http://dl.bintray.com/populov/maven" }
mavenCentral()
}
}
allprojects {
repositories {
maven { url "http://dl.bintray.com/populov/maven" }
mavenCentral()
}
}
应用的 build.gradle:
App's build.gradle:
compile 'com.viewpagerindicator:library:2.4.1@aar'
此外,根据 Enrico Susatyo 给出的答案,现在似乎可以从 Jitpack maven 存储库下载该库.请按以下步骤操作:
Also, based on the answer given by Enrico Susatyo now it seems possible to download the library from Jitpack maven repositories. Do it as follows:
在根 build.grade 中:
In root build.grade:
allprojects {
repositories {
...
maven { url "https://jitpack.io" }
}
}
在项目 build.grade 中:
In project build.grade:
dependencies {
compile 'com.github.JakeWharton:ViewPagerIndicator:2.4.1'
}
------------
要在Android Studio中使用Android-ViewPagerIndicator,是不能从gradle下载的.相反,您必须将该库作为现有项目"导入到您当前的项目中.
To use Android-ViewPagerIndicator in Android Studio, you can’t download it from gradle. Instead, you must import the library as an "Existing Project" to your current one.
请按照以下步骤操作:
#1 从 GitHub 下载源代码.
#1 Download source code from GitHub.
#2 在您的 Android Studio 项目中:文件 -> 项目结构 -> 添加(+ 符号) -> 导入现有项目.只导入名为library"的文件夹,而不是整个项目(保留 Android Studio 建议的导入选项).
#2 In your Android Studio Project: File -> Project Structure -> add (+ symbol) -> Import Existing Project. Import just the folder called "library", not the entire project (leave the import options as Android Studio suggests).
#3 如果 build.gradle 中指定的compileSdkVersion"与 Android-ViewPagerIndicator 项目中指定的不匹配,请更改第二个.这同样适用于任何其他属性,例如minSdkVersion"甚至当前的支持库.
# 3 If the "compileSdkVersion" specified in your build.gradle doesn’t match with the one specified in the Android-ViewPagerIndicator project, change the second one. The same apply with any other property, such as "minSdkVersion" or even the current support library.
#4 将 Android-ViewPagerIndicator 项目添加为 build.gradle 模块的依赖项:
# 4 Add Android-ViewPagerIndicator project as a dependency to your build.gradle module:
dependencies {
compile project(':library')
}
#5 同步项目与 gradle 文件.
# 5 Sync project with gradle files.
这篇关于将 ViewPagerIndicator 添加到 Android Studio的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!