I have solution for my problem. Sadly, I see no full tutorial for my problem. And by many mistakes, I can try it by hand.I have try a way : here is my short tutorial. Hope help someone here.
Short Description : I will add a SlidingMenu library to my project. This library is special because :
it's an Eclipse-type project (means : has a slide difference compare to android project create by Android Studio or Intellij IDEA), so you must have a step config by hand. If this's a normal library create by Android Studio, you can remove mapping by hand step in below Gradle file.
It uses v4 support library. Often, your app uses this library too. So, if you compile both same two libries in same project. You will meet error. So, there is a way : using Android Repository to synchronized. You will not meet exception that two same libraries in one project.
You create a libs folder inside your app. After that, copy whole project library to this folder. For example, I'm using SlidingMenu. After that, you create gradle.build with following content. ( I have added some comments, for easier to follow)
// SlidingMenu is an Eclipse project. so its structure is different. and must config by hand. // script to decide which gradle version will use for maven buildscript { repositories { mavenCentral() } dependencies { classpath 'com.android.tools.build:gradle:0.6.+' } } // because this is a android library. we change : apply plugin: 'android' to apply plugin: 'android-library' // Base Project includes "Support Library v4 jar to its project // 1. If Not Compile it : this library project cannot compile because missing libraries // 2. Cannot delete jar file in libs folder. Because its code depend on this libs. Delete jar file turn out that cannot see class file // 3. My Solution : Use Gradle Repository. By use Gradle Repository, this library will be synchronized between two projects. // So, just one instance could be used for both project. dependencies { compile 'com.android.support:support-v4:19.0.0' } android { compileSdkVersion 18 buildToolsVersion "18.1.1" // Mapping phrase : use if this library is Eclipse-base project // modify link because this project is from Eclipse Project // not from normal gradle Project. So project structure is different. Cannot make default // Config by hand, get Gradle knows which part for each type of directory sourceSets { main { manifest.srcFile 'AndroidManifest.xml' java.srcDirs = ['src'] resources.srcDirs = ['src'] aidl.srcDirs = ['src'] renderscript.srcDirs = ['src'] res.srcDirs = ['res'] assets.srcDirs = ['assets'] } // Move the tests to tests/java, tests/res, etc... instrumentTest.setRoot('tests') debug.setRoot('build-types/debug') release.setRoot('build-types/release') } }
Here is main gradle file :
buildscript { repositories { mavenCentral() } dependencies { classpath 'com.android.tools.build:gradle:0.6.+' } } // this is main project : so we use apply plugin : 'android' apply plugin: 'android' repositories { mavenCentral() } android { compileSdkVersion 18 buildToolsVersion "18.1.1" defaultConfig { minSdkVersion 9 targetSdkVersion 18 } } dependencies { compile 'com.android.support:appcompat-v7:19.0.0' compile 'com.android.support:support-v4:18.0.0' // compile project SlidingMenu compile project(':Hop Am Chuan:libs:SlidingMenu') // add this line just for demonstration. you can use or remove it. // compile files('libs/google-gson-2.2.4/gson-2.2.4.jar') }
Hope this help :)