Error: "Version code not found in manifest." - android

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()

Related

AndroidManifest.xml "Unresolved package" Error

I am developing a Media Player app. I was implementing MediaButtonReceiver (which is used to control Media inputs given from Headphone, bluetooth like external devices).
But while declaring receiver in the manifest file I encountered a number of errors.
Errors:
Unresolved package session
Unresolved class MediaButtonReceiver
Class referenced in the manifest, com.example.android.MediaPlaybackService, was not found in the project or the libraries
Unresolved package android
Unresolved class MediaPlaybackService
build.gradle:app
plugins {
id 'com.android.application'
id 'kotlin-android'
}
android {
compileSdkVersion 30
buildToolsVersion "30.0.3"
defaultConfig {
applicationId "com.example.helloworld"
minSdkVersion 16
targetSdkVersion 30
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
}
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation 'androidx.core:core-ktx:1.3.2'
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'com.google.android.material:material:1.3.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
}
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.helloworld">
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/Theme.HelloWorld">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver android:name="android.support.v4.media.session.MediaButtonReceiver">
<intent-filter>
<action android:name="android.intent.action.MEDIA_BUTTON" />
</intent-filter>
</receiver>
<service android:name="com.example.android.MediaPlaybackService" >
<intent-filter>
<action android:name="android.intent.action.MEDIA_BUTTON" />
</intent-filter>
</service>
</application>
</manifest>
"Unresolved package/reference" means that the supporting library doesn't exist. According to the bewildering Android dev doc, you must download it by adding the following code to Gradle Scripts > build.gradle (Module: xxx.app) inside dependencies{}, resync and the error will disappear from androidx.media.session.MediaButtonReceiver
implementation("androidx.media:media:1.6.0")
and add this code for the error to disappear from android.support.v4.media.session.MediaButtonReceiver
implementation("com.android.support:support-media-compat:28.0.0")
Check latest version of androidx and v4
Maybe try to declare it in AndroidManifest.xml like the documentation said (for AndroidX) :
<receiver android:name="androidx.media.session.MediaButtonReceiver" >
<intent-filter>
<action android:name="android.intent.action.MEDIA_BUTTON" />
</intent-filter>
</receiver>

ActionBar is not being displayed anymore after migration from Eclipse to Android Studio

I recently tried to edit my 4 year old android application in the recently appeared Android Studio 2.3.1.
After importing the code I can launch it on my mobile phone. However the action bar seems to have disappeared. What has gone wrong?
How can I tell android to display the action bar?
I have implemented the action bar activity like this:
public class MainActivity extends ActionBarActivity
My build.gradle looks like this:
apply plugin: 'com.android.application'
android {
compileSdkVersion 17
buildToolsVersion "25.0.0"
defaultConfig {
applicationId "de.my.app"
minSdkVersion 8
targetSdkVersion 17
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
dependencies {
compile 'com.android.support:appcompat-v7:18.0.0'
}
I also tried to replace the compile command with something newer one:
compile 'com.android.support:appcompat-v7:25.3.1'
but already the syncing in android studio fails like this, throwing the following error:
Error:Execution failed for task ':app:processDebugManifest'.
> Manifest merger failed : uses-sdk:minSdkVersion 8 cannot be smaller than version 9 declared in library [com.android.support:appcompat-v7:25.3.1] /home/user/.android/build-cache/815cafa5312f1d889eb1134b2184a62b3f88d8a3/output/AndroidManifest.xml
Suggestion: use tools:overrideLibrary="android.support.v7.appcompat" to force usage
I haven't done much android coding in the last 4 years so I assume the ActionBar stuff has changed profoundly but shouldn't there be a way to compile the old code as it is using android studio?
Edit:
This is the manifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="de.myApp.myAppDemo"
android:versionCode="1"
android:versionName="1.0" >
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<application
android:allowBackup="true"
android:icon="#drawable/icon_app"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="de.myApp.myAppDemo.Splash"
android:label="#string/app_name"
android:screenOrientation="landscape" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="de.myApp.myAppDemo.MainActivity"
android:label="#string/app_name"
android:screenOrientation="landscape"
android:theme="#style/Theme.AppCompat.Light">
<intent-filter>
<action android:name="de.myApp.myAppDemo.MAINACTIVITY" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name="de.myApp.myAppDemo.PropertiesAssign"
android:label="#string/app_name"
android:screenOrientation="landscape" >
<intent-filter>
<action android:name="de.myApp.myAppDemo.PROPERTIESASSIGN" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name="de.myApp.myAppDemo.PropertiesView"
android:label="#string/app_name"
android:screenOrientation="landscape" >
<intent-filter>
<action android:name="de.myApp.myAppDemo.PROPERTIESVIEW" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
</manifest>
Meanwhile I got at least the ActionBar to be displayed. However I had to increase the MinSDK and targetSdkVersion / compileSdkVersion bigly: From 8,17 to 15,23. Moreover I had to look in the SDK-Manager to see which exact version of Android Support Library was installed on my system (23.2.0) and adapt the corresponding line in build.gradle.
apply plugin: 'com.android.application'
android {
compileSdkVersion 23 //->modified
buildToolsVersion "25.0.0"
defaultConfig {
applicationId "de.Geo.geodraw"
minSdkVersion 15 //->modified
targetSdkVersion 23 //->modified
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
dependencies {
compile "com.android.support:appcompat-v7:23.2.0" //->modified
}
Not sure whether it was relevant or necessary but following this page I also added
allprojects {
repositories {
jcenter()
maven { //->modified
url "https://maven.google.com" //->modified
} //->modified
}
}
in another build.gradle file.
If there is another solution without drastically changing minSdk and targetSdk I will accept that answer.

Android: Element Activity is now allowed here

In the code below Android Studio shows me
"Element activity is now allowed here"
when I hover over activity tag, and the app doesn't launch the activity which is the default one, I tried clean project, rebuild project then restarted Android Studio, I tried invalidate cashes / restart, and the problem still exist, how to fix this?
<activit
android:name=".MainActivity"
android:configChanges="orientation|screenSize"
android:label="#string/app_name"
android:launchMode="singleTask" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activit>
build.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.1"
defaultConfig {
applicationId "com.blabla.testapp1"
minSdkVersion 15
targetSdkVersion 23
versionCode 1
versionName "1.0.0"
}
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:23.1.0'
}
In your manifest i see you wrote activit instead of activity. Make it okey
<activity
android:name=".MainActivity"
android:configChanges="orientation|screenSize"
android:label="#string/app_name"
android:launchMode="singleTask" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

gradle placeholder can not solve the ${com.nssb.zssb}

gradle placeholder support problem :
my placeholder looks like ${com.nssb.zssb}
how can gradle deal with this situation, I tried the following command:
manifestPlaceholders = [com.nssb.zssb:"djdssb"]
but it didnt worked. any suggestion? many thanks~~~~~
my mainifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="differentbuild.com.mike.differentbuild" >
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="${com.nssb.zssb}"
android:theme="#style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="${com.nssb.zssb}" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".SecondActivity"
android:label="${com.nssb.zssb}" >
</activity>
</application>
</manifest>
my build gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion "22.0.1"
defaultConfig {
applicationId "differentbuild.com.mike.differentbuild"
minSdkVersion 19
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
productFlavors {
production {
applicationId "differentbuild.com.mike.differentbuild"
manifestPlaceholders = [com.nssb.zssb:"SecondActivity"]
versionName "1.0-pro"
}
pros {
applicationId "differentbuild.com.mike.differentbuild"
manifestPlaceholders = [com.nssb.zssb:"SecondActivity111"]
versionName "1.0.1-pro"
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:22.0.0'
}

Failure [INSTALL_FAILED_OLDER_SDK] error

I have an AVD emulator set at API 18 and my manifest is as follows:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="pushpindesigns.com.lines"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="12" android:targetSdkVersion="20"/>
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme">
<activity
android:name=".mainActivity"
android:label="#string/app_name"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".Level_1"
android:label="#string/title_activity_level_1" >
</activity>
</application>
Updated build.gradle file that includes the compilesdkversion = 18
apply plugin: 'com.android.application'
android {
compileSdkVersion 18
buildToolsVersion "20.0.0"
defaultConfig {
applicationId "pushpindesigns.com.lines"
minSdkVersion 8
targetSdkVersion 'L'
versionCode 1
versionName "1.0"
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:19.+'
}
Code above is updated and still doesn't work.................Let me know what you think
Replace android-L with something else -- 20 or 19 would be likely choices. The "L" Developer Preview will not work on anything but "L"-equipped devices and emulators.
Also, the targetSdkVersion in your build.gradle overrides that which is in your manifest. Replace the targetSdkVersion in your build.gradle to 20.

Categories

Resources