android - 将依赖版本从应用程序继承到库模块

标签 android android-library

我创建了一个在内部使用一些标准依赖项的库:

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.google.android.gms:play-services-drive:16.0.0'
}

我想知道是否有一种方法可以从应用程序继承依赖版本,比如:

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:$INHERITED_FROM_APP'
implementation 'com.google.android.gms:play-services-drive:$INHERITED_FROM_APP'
}

最佳答案

在你的项目级build.gradle,定义全局变量

buildscript {    
    ext.global_minSdkVersion = 16
    ext.global_targetSdkVersion = 28
    ext.global_buildToolsVersion = '28.0.1'
    ext.global_supportLibVersion = '28.0.0'
    ext.global_googleLibVersion = '16.0.0'
}

转到应用级别build.gradle,并使用全局变量

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:$global_supportLibVersion'
    implementation 'com.google.android.gms:play-services-drive:$global_googleLibVersion'
}

关于android - 将依赖版本从应用程序继承到库模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53041445/

相关文章:

Android InApp 计费包装器?

android - 如何修复 webview_flutter 中的白屏?

android - 当涉及到 Android 库项目时,Eclipse/ADT 有多聪明?

Android _ import android.support.v7.graphics 无法解决?

Android gradle 使用库构建,找不到符号

android - 为什么ImageView的png图像中包含背景颜色?

android - Firebase endAt() 不适用于日期字符串?

Android 应用程序登录设计模式

android - 创建 STANDALONE Android Studio (1.5) 库项目

Android Studio 找不到导入的库