[英]Error: "Version code not found in manifest."
我正在尝试构建签名的应用程序包,以便发布。 我所做的只是更新操作系统版本和一些图形。 该应用程序在 ADK 上运行得很好。 在构建签名的 apk 时,我收到以下错误消息:
“在清单中找不到版本代码。”
这是错误日志:
“引起:com.android.ide.common.workers.WorkerExecutorException:
工作人员引发了 1 个异常:com.android.tools.build.bundletool.exceptions.manifest.ManifestVersionException$VersionCodeMissingException:在清单中找不到版本代码。”
感谢任何可以帮助我解决这个小问题的人。 我在这里搜索,找不到好的解决方法。
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.sevillasoundservices.warningshot">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:theme="@style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".ShotgunSensing"
android:label="@string/title_activity_shotgun"
android:theme="@style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".RifleSensing"
android:label="@string/title_activity_rifle"
android:theme="@style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".PistolSensing"
android:label="@string/title_activity_pistol"
android:theme="@style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
摇篮文件:
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
buildToolsVersion '28.0.3'
defaultConfig {
applicationId "com.sevillasoundservices.warningshot"
minSdkVersion 24
targetSdkVersion 28
versionName '1.0.2'
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard- android.txt'), 'proguard-rules.pro'
}
}
productFlavors {
}
compileOptions {
sourceCompatibility = '1.8'
targetCompatibility = '1.8'
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
testImplementation 'junit:junit:4.13-beta-3'
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support:design:28.0.0'
}
我希望这里有人可以告诉我缺少什么。 我希望在清单文件中简单地插入一些代码来解决这个问题,但是,其他编码器清单的所有其他示例都没有任何版本显示在任何地方。
将versionCode
添加到您的 gradle。 像下面这样...
defaultConfig {
applicationId "com.sevillasoundservices.warningshot"
minSdkVersion 24
targetSdkVersion 28
versionName '1.0.2'
versionCode 3
}
versionCode
是一个增量整数,用于确定哪个版本高于另一个版本。 我认为这仅对签名的 APK 强制执行,这就是为什么您之前没有看到该错误的原因。
更多信息可以在Android 开发者指南中找到
您需要添加 versionCode 代码,如下所示。
android {
compileSdkVersion 32
defaultConfig {
minSdkVersion 28
targetSdkVersion 32
versionCode 4
versionName '0.0.4.'
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
对我来说,错误在我试图动态生成 VersionCode 的 build.gradle 中。 为此,我需要添加一个生成 versionCode 的方法。 在我尝试生成发布之前,它没有问题。 但是当我尝试创建签名包时出现错误。
def getVersionCode() {
def date = new Date()
def formattedDate = date.format('yyyyMMdd')
return formattedDate
}
android {
compileSdkVersion 32
defaultConfig {
minSdkVersion 28
targetSdkVersion 32
versionCode getVersionCode()
versionName '0.0.4.'
}
原因是我的方法名称 getVersionCode() 与字段 versionCode 的默认 getter 冲突并隐藏了它。
如果您想要像上面那样动态生成,您的方法名称必须不是 getVersionCode(),可能是 generatetVersionCode()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.