versionCode is always overwritten to -1 - android

I created a new project in android studio and one of the first things I did was to move the versionCode an versionName attributes from build.gradle to the manifest file for convenience. Then i get this weird warning saying:
This versionCode value (1) is not used; it is always written by the
value specified in the Gradle build script (-1)
It started appearing in my older projects too, so it's clearly not a project specific problem. Something may happened when I updated to 0.8.14 and updated the build tools, but I have no ide what. Any ideas on how to fix this?

According to official doc, gradle overrides some values in AndroidManifest.
The default value in DSL object for the versionCode is -1.
Then when gradle builds your apk, overrides the value in Manifest and assign the versionCode=-1

You already explained the source of this problem: you can't move the versioning information to the manifest in gradle-based projects. You should use build.grade for the version code and name.

Well, probably the Gradle build system expects you to keep the versionCode and versionName there and if it is missing, it does not know what to do. It is recommended to keep those values in the build.gradle file instead of in AndroidManifest anyway

Related

Does VersionCode matter for an Android AAR library?

Specifically for aar generated libraries, does the versionCode set either in the manifest or build file matter? Is it used anywhere for anything?
For an apk the docs say versionCode is used by the Play store API. I couldn't find any reference to versionCode relating to aars though.
For aar consumer it doesn't matter - they only need the maven artifact version.
For aar producer it matters - you may want to use it to add specific upgrade code to run only once (from version X to version Y).
I think AGP no longer requires specifying version name or code to non-app modules.

Android Studio Installation failed since the device already has a newer version

We have written a new version of an Android app to upgrade an old one, but would like to extract login username from old apps SharedPreferences on first run after upgrade before overwriting the whole thing with the new data model. build.gradle of the new codebase specifies a newer versionName and versionCode, yet when we try to run from Android Studio onto a device that had the old app installed we get a dialog box with the following error message:
Installation failed since the device already has a newer version of this application.
In order to proceed, you have to uninstall the existing application.
WARNING. Uninstalling will removed the application data!
Do you want to uninstall the existing application?
[OK] [Cancel]
Obviously if we accept it uninstalls the old app along with all the user data and we cannot achieve what we intended.
Cannot find anything on the internet regarding this problem
OLD APP build.gradle:
versionCode 1
versionName '1.4.1'
NEW APP build.gradle:
versionCode 2
versionName '2.0.0'
I believe this error is happening because your old APP has a higher versionCode than your new app.
So, you must update versionCode from your new app to a higher (or at least equal) value if compared to your oldAPP.
In the new app:
build.grade
android {
...
defaultConfig {
...
versionCode 2
versionName "1.1"
}
...
}
If your oldVersion was built in Eclipse, versionCode was probably defined in AndroidManifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="string"
android:versionCode="integer"
android:versionName="string"
. . .
</manifest>
For testing you can change the version code to the one currently installed in the device.
#alex, Update "versionCode" ,"version name" in build.gradle. after complete clean proj and rebuild. Many time old all data not remove.
Ahh it looks like some gradle script from the old developers was overwriting the versionCode at build time with a much higher number... but now using a really high number I get INSTALL_FAILED_UPDATE_INCOMPATIBLE instead! :(
As it was mentioned in one of the comments above, it is purely because of the versionCode in the build.gradle
I too had the same issue. My old app had a version code of 7009 and the new one had 7010. However, the old app's version code was changed during build-time (7009 was just the base-apk code) so as soon as I changed versionCode to 17010 which was much greater than 7009, I could install the new app over the previous one without uninstalling.
To confirm, maybe just try Logging the versionCode in console from the old app and make sure that the new version code is greater than that.
In my case, I had multiple users on my device. The app got installed for all users. So I had to delete it for all of them.

You need to use a different version code for your APK because you already have one with version code 1

i know this has been ask here
The correct answer is to change the version does not solve my problem
id did added this two lines in my manifest
android:versionCode="2"
android:versionName="2.01"
but then when i clean and build using android studio the generate the apk again then upload the same error happend ..
Note: I did check that it is the correct file that i try to upload in the developer console
In the build.gradle file check if you have versionCode like
defaultConfig {
minSdkVersion 10
targetSdkVersion 22
versionCode 1
versionName "1.0"
}
because if you have mentioned versionCode in build.gradle file then it will overwrite the values in manifest file. Please make sure if you have mentioned version code here then you have updated here also.
Change it in the build.gradle file of your app module in Android Studio.
Remove those from your manifest. Go to File>Project Structure> And either flavors or build types (don't remember and don't have my pc on me). Set the version name and version code from there.

Android manifest not updating app version from Gradle build

Based on this Google document I'm expecting Gradle to update my manifest.xml file with a version number, notably this quoted section:
The defaultConfig element configures core settings and entries in the manifest file (AndroidManifest.xml) dynamically from the build system. The values in defaultConfig override those in the manifest file.
However when I change the version code or version name of my Gradle file, the values arent' changed in my manifest.
Is this normal behavior?
Which values, between the manifest and the gradle build, are stting version codes and names?
How can I make the connection between the manifest versions and the gradle build more visible?
Even I am facing the similar issue. It is the default behaviour of gradle system I guess. You need to update both AndroidManifest.xml and build.gradle seperately if there is any changes in sdk versions, version code, version name,etc. I am looking forward that these kinda issues must be fixed in upcoming releases.
I have versionCode(1.0.3) and versionName(8) in my build.gradle only and it had worked correctly for me in past.
Now I updated the versionCode to 1.0.4 and versionName to 1 but it kept on giving me error on Google play. I even tried adding the new versionCode and versionName to AndroidManifest.xml but it did not help. Only thing that worked was updating the versionName to a higher number (9). Something seems broken in the Google Play upload apk and verify mechanism. Hopefully my answer would save someone else's 1 hour for solving this silly bug.

Android Manifest INSTALL_FAILED_VERSION_DOWNGRADE string resource Gradle

I have replaced the app version and name variables in my manifest file with resource references. The issue that is occurring now though is that regardless of what number I set in my resources file the app still gives this error.
Failure [INSTALL_FAILED_VERSION_DOWNGRADE]
This is the change ive made to the manifest
android:versionCode="#integer/version_code"
android:versionName="#string/version_name" >
Does anyone know why this is occurring and how I might be able to correct it?
If you're using gradle for building your APKs. Your build.gradle file is replacing the versionCode and versionName values in the androidManifest file. So doesn't matter where you've defined your code and version name. When you change those values directly in your manifest, they'll always be overridden by gradle.
consumer {
versionCode 123
versionName "1.0.0"
applicationId "com.example.android"
testInstrumentationRunner "android.test.InstrumentationTestRunner"
}
Removing your current installation of your apk and reinstalling will also solve this problem.

Categories

Resources