简体   繁体   中英

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. When building the signed apk, I get this error message:

"Version code not found in manifest."

This is the error log:

"Caused by: 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."

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. 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. I think this is only enforced on signed APKs, that's why you haven't seen the error earlier.

More info can be found in Android Developer Guides

You need to add versionCode code as follows.

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 . For that I need to add a method that generated 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.

If you want dynamic generation like the above your method name has to be something other than getVersionCode(), may be generatetVersionCode()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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