在所有库中导入应用程序compat依赖项 [英] Import app compat dependency in all libraries
问题描述
我在我的应用程序中有两个模块,我想修改它们两个以使用AppCompat Widgets,我必须使用它们对它们进行扩展。问题是我不想为它们中的每一个添加appcompat依赖项,所以我怎么可能将Dependency添加到模块和我的应用程序。如果我添加
compile'com.android.support:appcompat-v7:23.1.1'
code>
到每个模块,会影响应用程序的大小吗?
compile'com.android.support:appcompat-v7:23.1.1'
在每个模块中并不意味着将其添加两次或更多次。
Gradle处理它只为您添加一次库。
使用多模块项目,您可以将支持库依赖集中在gradle中。
一个很好的方法是分离gradle构建文件,定义如下所示:
root
--gradleScript
---- dependencies.gradle
--module1
---- build。 gradle
--module2
---- build.gradle
--build.gradle
在 gradleScript / dependecies.gradle
中:
ext {
//版本
supportLibrary = '23 .2.0'
/ /支持库依赖关系
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},
]
}
在顶层文件 build.gradle
中:
//顶层构建文件,您可以在其中添加对所有子项目/模块通用的配置选项。
buildscript {
repositories {
jcenter()
}
依赖关系{
classpath'com.android.tools.build:gradle:1.5.0'
加载依赖关系
应用于:'gradleScript / dependencies.gradle'
$ b $ module1 / build.gradle
: //模块构建文件
依赖关系{
// ......
编译supportDependencies.appCompat
编译supportDependencies.design
}
I have 2 modules in my application, I want to modify both of them to use AppCompat Widgets for which I have to extend them with same. The problem is that I do not want to add appcompat dependency to each of them, So how could I possibly add Dependency to both modules and my app. If I do add
compile 'com.android.support:appcompat-v7:23.1.1'
to every module, would it affect the application size?
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
}
这篇关于在所有库中导入应用程序compat依赖项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!