Import app compat dependency in all libraries

浪尽此生 提交于 2019-12-01 02:19:54

Using

compile 'com.android.support:appcompat-v7:23.1.1'

in every module doesn't mean to add it twice or more times.

Gradle handles it for you adding the library only one time.

Working with multi-modules project, you can centralize the support libraries dependencies in gradle.

A very good way is to separate gradle build files, defining something like:

root
  --gradleScript
  ----dependencies.gradle
  --module1
  ----build.gradle
  --module2
  ----build.gradle
  --build.gradle

In gradleScript/dependecies.gradle:

ext {
    //Version
    supportLibrary = '23.2.0'

    //Support Libraries dependencies
    supportDependencies = [
            design           :         "com.android.support:design:${supportLibrary}",
            recyclerView     :         "com.android.support:recyclerview-v7:${supportLibrary}",
            cardView         :         "com.android.support:cardview-v7:${supportLibrary}",
            appCompat        :         "com.android.support:appcompat-v7:${supportLibrary}",
            supportAnnotation:         "com.android.support:support-annotations:${supportLibrary}",
    ]
}

In the top level file build.gradle:

// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:1.5.0'
    }
}

// Load dependencies
apply from: 'gradleScript/dependencies.gradle'

In the module1/build.gradle:

// Module build file

dependencies {
    //......
    compile supportDependencies.appCompat
    compile supportDependencies.design
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!