Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add ViewPagerIndicator to Android Studio

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 gives me the following error:

Error:duplicate files during packaging of APK

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?

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')
}
like image 998
carstenbaumhoegger Avatar asked Sep 06 '14 17:09

carstenbaumhoegger


3 Answers

UPDATE

Based on the answer given by Jürgen 'Kashban' Wahlmann, it is now possible to add ViewPagerIndicator via 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()
    }
}

App's build.gradle:

compile 'com.viewpagerindicator:library:2.4.1@aar'

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:

In root build.grade:

allprojects {
        repositories {
            ...
            maven { url "https://jitpack.io" }
        }
    }

In project build.grade:

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

------------

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.

Follow these steps:

#1 Download source code from GitHub.

#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 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 Add Android-ViewPagerIndicator project as a dependency to your build.gradle module:

dependencies {
    compile project(':library')
}

# 5 Sync project with gradle files.

like image 107
Víctor Albertos Avatar answered Nov 09 '22 06:11

Víctor Albertos


It can be imported by Gradle like this:

Top Level Build.gradle:

buildscript {
    repositories {
        maven { url "http://dl.bintray.com/populov/maven" }
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:0.12.+'
    }
}

allprojects {
    repositories {
        maven { url "http://dl.bintray.com/populov/maven" }
        mavenCentral()
    }
}

In your App's build.gradle add this to your dependencies section:

compile 'com.viewpagerindicator:library:2.4.1@aar'

(Add @aar to avoid "packaging for apklib is not supported error")

Works fine for me.

like image 32
Jürgen 'Kashban' Wahlmann Avatar answered Nov 09 '22 07:11

Jürgen 'Kashban' Wahlmann


As of today (March 2016), Jitpack's maven repos work for me: https://jitpack.io/#JakeWharton/ViewPagerIndicator/2.4.1/aar

In root build.gradle:

allprojects {
        repositories {
            ...
            maven { url "https://jitpack.io" }
        }
    }

In project build.gradle:

dependencies {
            compile 'com.github.JakeWharton:ViewPagerIndicator:2.4.1'
    }
like image 44
Enrico Susatyo Avatar answered Nov 09 '22 07:11

Enrico Susatyo