我正在开发一个 Android 应用程序,其中 95% 的功能都包含在我编写的库中。同一个库将用于 30 多个应用程序,我希望不必手动设置每个应用程序的版本。相反,我想设置应用程序的 versionName
基于库的解析版本(因为它没有在 build.grade
文件中明确指定)。
这是我目前的build.gradle
应用程序文件:
apply plugin: 'com.android.application'
android {
compileSdkVersion 27
defaultConfig {
applicationId "com.commentsold.demo"
minSdkVersion 18
targetSdkVersion 27
multiDexEnabled true
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
buildscript {
repositories {
maven { url 'https://maven.fabric.io/public' }
}
dependencies {
classpath 'io.fabric.tools:gradle:1.+'
}
}
apply plugin: 'io.fabric'
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:multidex:1.0.3'
testImplementation 'junit:junit:4.12'
implementation 'com.github.CommentSold:Android-CommentSoldKit:1+'
}
android {
defaultConfig {
versionCode 1
versionName ***SET_THIS_NAME_BASED_ON_Android-CommentSoldKit***
}
}
apply plugin: 'com.google.gms.google-services'
请注意,占位符 **SET_THIS_NAME_BASED_ON_Android-CommentSoldKit**。这就是我想用“1.0.0”之类的东西代替的地方。
最佳答案
您可以在项目的根目录中定义共享变量 build.gradle
通过这样的事情:
buildscript {
ext {
my_lib = "com.github.CommentSold:Android-CommentSoldKit:1.0.0"
}
}
然后在你的每个应用程序的 build.gradle 中,你可以做
def common = rootProject.ext
dependencies {
implementation common.my_lib
}
这是你想要的?
关于android - 是否可以设置 Android 应用的 versionName 以匹配依赖项的已解析版本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50708859/