Android-ViewPagerIndicator is presented as an Android library project. A standalone JAR is not possible due to the theming capabilities offered by the indicator widgets. Therefore, to use this library with Android Studio and Gradle, there were some complications but I finally managed to get this external library working. So I wrote this small guide into how to get an external library such as ViewPagerIndicator, which has not been built with Gradle, to work in your project. I hope that will spare you a couple of hours of struggling with different errors such as:
- UNEXPECTED TOP-LEVEL EXCEPTION: occurs when the external library set the same dependencies for both your project and the libraries.
- Manifest Merging Failed: occurs when the minimum SDK version of the library is different from the one set in your project.
- No resource found that matches the given name ‘@style/Theme.AppCompat.Light.DarkActionBar’: occurs when android.support.v7.appcompat library is missing.
My environment
- Android Studio (Preview) 0.6.1 Build #AI-135.1224218, built on June 12, 2014
- JRE: 1.7.0_51-b31 amd64
- ViewPagerIndicator Version 2.4.1 — 2012-09-11
Step by step
- Create a new directory at the root of your project, name it “libraries” (case sensitive).
- Download and extract the library ViewPagerIndicator; it has 2 subdirectories: library and sample.
- Copy the library directory to the libraries directory of your project and rename it to avoid confusion. Here, I renamed it to viewpager_indicator.
- Create a file at the root of the viewpager_indicator directory and name it build.grable. Here is a basic Gradle build file:
apply plugin: 'android-library' android { sourceSets { main { manifest.srcFile 'AndroidManifest.xml' java.srcDirs = ['src'] resources.srcDirs = ['src'] aidl.srcDirs = ['src'] res.srcDirs = ['res'] assets.srcDirs = ['assets'] } } compileSdkVersion 19 buildToolsVersion '19.1.0' } dependencies { compile 'com.android.support:support-v4:+' compile 'com.android.support:appcompat-v7:+' }
These lines have to match the ones declared in your build.gradle of your application (located at: YourProject > app > src).
compileSdkVersion 19 buildToolsVersion '19.1.0'
Here I didn’t precise the versions of com.android.support:support-v4 and com.android.support:appcompat-v7 but you may need to do it to match the configuration of your project.
– com.android.support:support-v4 is used by both my application and ViewPagerIndicator library.
– com.android.support:appcompat-v7 is used by my application.
5. Modify the dependencies of the build.gradle of the application (located at: YourProject > app > src):
apply plugin: 'android' android { compileSdkVersion 19 buildToolsVersion '19.1.0' defaultConfig { minSdkVersion 7 targetSdkVersion 19 versionCode 1 versionName '1.0' } buildTypes { release { runProguard false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt' } } productFlavors { } } dependencies { compile project(':libraries:viewpager_indicator') }
The only library my application depends one is viewpager_indicator because the dependency com.android.support:support-v4 will be set for the library.
6. Modify the Gradle settings of your project to include the library. Here is my settings.gradle:
include ':libraries:viewpager_indicator', ':app'
7. Voila, BUILD SUCCESSFUL 🙂
In this sample, I only have 1 library which has the dependency com.android.support:support-v4 in common with my application. The solution is then setting this dependency for the library. But if you have more than 1 library, you have to set the common dependencies only for your application and remove them from the libraries.
Enjoy and may the Force be with you!
Hello!! thanks. I have a error: configuration with name “default” not found, I need help, please. Thanks
May you tell me more about the error you got?
Excelente amigo me sirvió de mucho tu post!
i got an erorr as no class created when copying viewpagerindicator library under libraries folder
Hi Iakshman,
I’m so sorry that I did not read your comment sooner. I was inactive for a long period.
I hope that you could solve the problem. I don’t use ViewPagerIndicator anymore. So I’m sorry that I can’t help you.
Again, sincere apologies.
Tina.