[英]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.