salman salman - 2 months ago 14
Android Question

View pager indicator in android studio

I want to use view pager indicator library in android studio. As it is available for the maven and not for the gradle project yet so I am adding library folder in android studio and including it in app build.gradle file. Problem arises, when I compiled the project so it wont compile as both the app and library gradle files are using android-support-v4.jar files. I need to know how can I use the library in android studio.

settings.gradle

include ':app'
include ':library'
include ':sample'


app/build.gradle

apply plugin: 'android'
android {
compileSdkVersion 19
buildToolsVersion "19.0.3"
defaultConfig {
minSdkVersion 8
targetSdkVersion 19
versionCode 1
versionName "1.0"
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}

dependencies {
compile project(':library')
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:19.+'
}


library.gradle

buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.9.+'
}
}

apply plugin: 'android-library'

android {
sourceSets {
main {
java.srcDirs = ['src']
manifest.srcFile 'AndroidManifest.xml'
res.srcDirs = ['res']
}
}

compileSdkVersion 19
buildToolsVersion '19.0.3'
}

dependencies {
compile files('libs/android-support-v4.jar')
// compile 'com.android.support:support-v4:19.+'
// compile fileTree(dir: 'libs', include: ['*.jar'])
}

Answer

Don't include the support library by adding a direct dependency to its jar file as you have in your library's build.gradle file. If you include it everywhere via the Maven-coordinate-style include, like your commented out line, the build system won't have trouble with duplicates:

dependencies {
    compile 'com.android.support:support-v4:19.+'
}