gpt4 book ai didi

android - versionName 不能直接在 mergedFlavor 上设置

转载 作者:行者123 更新时间:2023-11-29 02:24:46 26 4
gpt4 key购买 nike

我正在尝试在我的 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"

有人可以帮我吗?也许这是一个微不足道的错误,但我无法修复它

提前致谢

最佳答案

通过删除 build.gradle 文件的插件部分解决了问题:

plugins {
id "com.company.versioning" version "1.0.9"
}

因为那个插件,我猜它总是将版本设置为一个固定的数字,我无法以编程方式进行。

在那之后发生了另一个错误,我可以通过将 AndroidAnnotationsVersion 升级到 4.5.0

来修复

关于android - versionName 不能直接在 mergedFlavor 上设置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52924175/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com