Android gradle build and the support library

后端 未结 5 884
梦毁少年i
梦毁少年i 2020-12-14 06:27

I have a project that uses a few other library projects (SlidingMenu, ActionbarSherlock) and both of these use the android support library, when building I am getting the fo

5条回答
  •  执笔经年
    2020-12-14 06:51

    Based in the answer from Xav, if you have other modules that depends on android-support-v4.jar, create a library project which contains the android-support-v4.jar and reference this project instead the jar file.

    E.g.:

    Add a project with this structure:

    - android-support
      - libs
        - android-support-v4.jar
      - AndroidManifest.xml
      - build.gradle
    

    AndroidManifest.xml:

    
    
    
        
    
    
    
    
    

    build.gradle:

    buildscript {
        repositories {
            mavenCentral()
        }
        dependencies {
            classpath 'com.android.tools.build:gradle:0.4.2'
        }
    }
    apply plugin: 'android-library'
    
    dependencies {
        compile files ("libs/android-support-v4.jar")
    
    }
    
    android {
        compileSdkVersion 17
        buildToolsVersion "17"
    
        defaultConfig {
            minSdkVersion 7
            targetSdkVersion 7
        }
        sourceSets {
            main {
                manifest.srcFile 'AndroidManifest.xml'
            }
    
        }
    }
    

    remember to include this project in your projects settings.gradle:

    include  ':android-support'
    

    now, for each project that requires the support library, instead of

    compile files ("libs/android-support-v4.jar")
    

    use the following line:

    compile project (':android-support')
    

提交回复
热议问题