简体   繁体   English

错误:“清单中未找到版本代码。”

[英]Error: "Version code not found in manifest."

I am trying to build the signed app bundle, so publishing.我正在尝试构建签名的应用程序包,以便发布。 All I did was update the OS versions and some graphics.我所做的只是更新操作系统版本和一些图形。 The app runs on the ADKs just fine.该应用程序在 ADK 上运行得很好。 When building the signed apk, I get this error message:在构建签名的 apk 时,我收到以下错误消息:

"Version code not found in manifest." “在清单中找不到版本代码。”

This is the error log:这是错误日志:

"Caused by: com.android.ide.common.workers.WorkerExecutorException: “引起:com.android.ide.common.workers.WorkerExecutorException:
1 exception was raised by workers: com.android.tools.build.bundletool.exceptions.manifest.ManifestVersionException$VersionCodeMissingException: Version code not found in manifest."工作人员引发了 1 个异常:com.android.tools.build.bundletool.exceptions.manifest.ManifestVersionException$VersionCodeMissingException:在清单中找不到版本代码。”

Thanks for anyone that can help me sort this small issue out.感谢任何可以帮助我解决这个小问题的人。 I searched on here and could not find a good fix.我在这里搜索,找不到好的解决方法。

<?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>


The Gradle file:摇篮文件:

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'
}

I am hoping someone here can tell me what is missing.我希望这里有人可以告诉我缺少什么。 I expect to simply insert some code on the manifest file to sort this out, however, all other examples of other coders manifests do not have any version showing anywhere.我希望在清单文件中简单地插入一些代码来解决这个问题,但是,其他编码器清单的所有其他示例都没有任何版本显示在任何地方。

Add the versionCode to your gradle.versionCode添加到您的 gradle。 Something like below...像下面这样...

   defaultConfig {
        applicationId "com.sevillasoundservices.warningshot"
        minSdkVersion 24
        targetSdkVersion 28
        versionName '1.0.2'
        versionCode 3
    }

The versionCode is an incremental integer that is used to determine which version is higher than the other. versionCode是一个增量整数,用于确定哪个版本高于另一个版本。 I think this is only enforced on signed APKs, that's why you haven't seen the error earlier.我认为这仅对签名的 APK 强制执行,这就是为什么您之前没有看到该错误的原因。

More info can be found in Android Developer Guides更多信息可以在Android 开发者指南中找到

You need to add versionCode code as follows.您需要添加 versionCode 代码,如下所示。

android {
    compileSdkVersion 32
    defaultConfig {

        minSdkVersion 28
        targetSdkVersion 32
        versionCode 4
        versionName '0.0.4.'
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

For me, Error was in my build.gradle that I was trying to generate VersionCode dynamically .对我来说,错误在我试图动态生成 VersionCode 的 build.gradle 中。 For that I need to add a method that generated versionCode.为此,我需要添加一个生成 versionCode 的方法。 It had no issue till I tried to generate a release.在我尝试生成发布之前,它没有问题。 But got the error when I tried creating signed bundle.但是当我尝试创建签名包时出现错误。

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.'
        
    }

The reason was my method name getVersionCode() conflicted with the default getter for field versionCode and was hiding it.原因是我的方法名称 getVersionCode() 与字段 versionCode 的默认 getter 冲突并隐藏了它。

If you want dynamic generation like the above your method name has to be something other than getVersionCode(), may be generatetVersionCode()如果您想要像上面那样动态生成,您的方法名称必须不是 getVersionCode(),可能是 generatetVersionCode()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM