我正在尝试在我的android应用中实现风味。我有以下build.gradle文件:
plugins {
id "com.company.versioning" version "1.0.9"
}
apply plugin: 'com.android.application'
apply plugin: 'realm-android'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
def AndroidAnnotationsVersion = '4.1.0'
android {
compileSdkVersion 26
buildToolsVersion '28.0.3'
dataBinding {
enabled = true
}
compileOptions {
targetCompatibility 1.8
sourceCompatibility 1.8
}
defaultConfig {
applicationId "com.newcompany.myapp"
minSdkVersion 19
targetSdkVersion 26
}
packagingOptions {
exclude 'META-INF/notice.txt'
exclude 'META-INF/license.txt'
}
signingConfigs {
staging {
storeFile file("file.jks")
storePassword "*********"
keyAlias "***********"
keyPassword "***********"
}
release {
storeFile file("file.jks")
storePassword "*********"
keyAlias "***********"
keyPassword "***********"
}
}
flavorDimensions "version"
productFlavors {
full {
//unused
dimension "version"
applicationId = "com.newcompany.myapp.full"
}
light {
dimension "version"
applicationId = "com.newcompany.myapp.light"
}
extra{
dimension "version"
applicationId = "com.newcompany.myapp.extra"
}
}
buildTypes {
release {
signingConfig signingConfigs.release
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
debug {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
zipAlignEnabled true
}
staging {
signingConfig signingConfigs.staging
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
sourceSets {
main {
java.srcDirs = ['src/main/java']
res.srcDirs = ['src/main/res']
assets.srcDirs = ['src/main/assets', 'src/main/assets/']
}
}
kapt {
generateStubs = true
arguments {
arg("resourcePackageName", android.defaultConfig.applicationId)
arg("androidManifestFile", variant.outputs[0]?.processResources?.manifestFile)
}
}
}
dependencies {
kapt 'com.android.databinding:compiler:3.1.4'
kapt "org.androidannotations:androidannotations:$AndroidAnnotationsVersion"
compile fileTree(include: ['*.jar'], dir: 'libs')
compile "org.androidannotations:androidannotations-api:$AndroidAnnotationsVersion"
compile 'com.android.support:appcompat-v7:26.1.0'
compile 'com.android.support:support-v4:26.1.0'
compile 'com.android.support:design:26.1.0'
compile 'com.github.ksoichiro:android-observablescrollview:1.5.2'
//InApp Purchase
compile ('com.android.billingclient:billing:1.0'){
exclude module: 'IInAppBillingService'
}
//RxJava RxAndroid
compile 'io.reactivex:rxandroid:1.2.0'
compile 'io.reactivex:rxjava:1.1.8'
stagingCompile 'net.hockeyapp.android:HockeySDK:4.1.4'
releaseCompile 'net.hockeyapp.android:HockeySDK:4.1.4'
}
当我现在执行该应用程序时,它给我以下错误:
versionName cannot be set on a mergedFlavor directly.
versionNameOverride can instead be set for variant outputs using the following syntax:
android {
applicationVariants.all { variant ->
variant.outputs.each { output ->
output.versionNameOverride = "1.0.0"
}
}
}
我尝试添加建议的代码:
applicationVariants.all { variant ->
def flavor = variant.mergedFlavor
def name = flavor.getVersionName()
def versionName = name + '-' + variant.properties.get('flavorName')
if (variant.buildType.isDebuggable()) {
versionName += '-debug'
}
flavor.versionName = versionName
variant.outputs.each { output ->
output.versionNameOverride = flavor.versionName
}
}
此后,我得到相同的错误,除了最后一行不同,它说:
output.versionNameOverride = "null-full"
有人可以在这里帮助我吗?也许是微不足道的错误,但我无法解决
预先感谢
答案 0 :(得分:0)
通过删除build.gradle文件的plugins部分来解决问题:
plugins {
id "com.company.versioning" version "1.0.9"
}
由于该插件,我想它总是将版本设置为固定数字,而我无法以编程方式完成。
此后发生了另一个错误,我可以通过将AndroidAnnotationsVersion
升级为4.5.0
答案 1 :(得分:0)
就我而言,当我从android gradle插件3.1.4升级到版本3.2.1时,存在相同的问题。错误消息是相同的!
解决方案是将我正在使用的auto-version plugin升级到v3.0.1时的最新版本⇢
希望这会有所帮助,并节省与他人的时间