簡體   English   中英

從應用程序到庫模塊繼承依賴項版本

[英]Inherit dependencies version from app to library module

我創建了一個在內部使用一些標准依賴項的庫:

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'
}

一個非常方便的解決方案,可以使用您的依賴項來定義dependencies.gradle文件: dependencies.gradle文件:

ext.versions = [
 'supportLib' : 28.0.0,
]

ext.deps = [
  'appcompat': "com.android.support:appcompat-v7:${versions.supportLib}",
]

build.gradle文件的應用程序級別:

buildscript {
  apply from: rootProject.file('dependencies.gradle')
  ....
}

build.gradle文件應用程序模塊級別:

implementation deps.appcompat

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM