作者热门文章
- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我正在尝试分离库的版本,将它们全部放在一个位置,以节省时间和复杂性。
我在某个博客的评论中看到一个人说他是这样做的。他发布了下一个屏幕。
我不能用这种方式来构建gradle,但我认为这是一个很好的方式。
我的项目build.gradle文件:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
maven {
url "https://maven.google.com"
}
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.3'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
maven {
url "https://maven.google.com"
}
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
// Definition of versions of libraries
ext {
toolVersions = [
android :[
versionCode : 1,
versionName : "0.0.1",
minSdk : 16,
targetSdk : 26,
compileSdk : 26,
buildTools : "26.0.2",
support : "26.1.0"
],
espressoCore : "2.2.2",
junit : "4.12"
]
libVersions = [
glide : "4.2.0",
flubber : "1.0.1"
]
}
我的应用程序 build.gradle 文件:
apply plugin: 'com.android.application'
android {
compileSdkVersion toolVersions.android.compileSdk
buildToolsVersion toolVersions.android.buildTools
defaultConfig {
applicationId "com.maol.brastlewark"
minSdkVersion toolVersions.android.minSdk
targetSdkVersion toolVersions.android.targetSdk
versionCode toolVersions.android.versionCode
versionName toolVersions.android.versionName
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:' + toolVersion.espressoCore, {
exclude group: 'com.android.support', module: 'support-annotations'
})
// SUPPORT LIBRARIES
compile 'com.android.support:appcompat-v7:' toolVersion.support
compile "com.android.support:support-core-utils:$rootProject.toolVersion.support"
testCompile "junit:junit:$rootProject.toolVersion.junit"
// IMAGE LOADER LIBRARY
compile "com.github.bumptech.glide:glide:$rootProject.libVersions.glide"
annotationProcessor "com.github.bumptech.glide:compiler:$rootProject.libVersions.glide"
// VIEW ANIMATIONS
compile "com.appolica:flubber:$rootProject.libVersions.flubber"
}
我不知道如何在 build.gradle (app) 中使用它。房间里有人可以给我一些建议吗?
谢谢
最佳答案
您可以创建一个文件(例如gradleScript/dependencies.gradle
):
ext {
//Version
supportLibrary = '26.1.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}",
]
}
在顶层文件 build.gradle
添加:
// Load dependencies
apply from: 'gradleScript/dependencies.gradle'
在 module1/build.gradle
中:
// Module build file
dependencies {
//......
compile supportDependencies.appCompat
compile supportDependencies.design
}
关于android - 我如何在 "build.gradle"应用程序中分离库版本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46930920/
我是一名优秀的程序员,十分优秀!