Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Android version code incorrect when publishing release build apk #11139

Closed
taublast opened this issue Nov 7, 2022 · 4 comments · Fixed by dotnet/android#7795
Closed

Android version code incorrect when publishing release build apk #11139

taublast opened this issue Nov 7, 2022 · 4 comments · Fixed by dotnet/android#7795
Labels
area-publishing Issues with the app packaging/publishing process (ipk/apk/msix/trimming) area-single-project Splash Screen, Multi-Targeting, MauiFont, MauiImage, MauiAsset, Resizetizer platform/android 🤖 t/bug Something isn't working

Comments

@taublast
Copy link
Contributor

taublast commented Nov 7, 2022

Description

There is no appearent way to set Version Code to other than 1 inside .cproj. whatever version number you put in code.
When you hit Publish release version you get an apk with Version Code 1.

Context:

Related to #3690.

Environment:

Microsoft Visual Studio Community 2022
Version 17.3.6
VisualStudio.17.Release/17.3.6+32929.385
Xamarin.Android SDK 13.0.0.0 (d17-3/030cd63)
Xamarin.Android Reference Assemblies and MSBuild support.
Mono: dffa5ab
Java.Interop: xamarin/java.interop/d17-3@7716ae53
SQLite: xamarin/sqlite@df4deab
Xamarin.Android Tools: xamarin/xamarin-android-tools/main@14076a6

Project:

        <TargetFrameworks>net6.0-android;net6.0-ios;net6.0-maccatalyst</TargetFrameworks>

	<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Release|net6.0-android|AnyCPU'">
		<AndroidPackageFormat>apk</AndroidPackageFormat>
		<AndroidCreatePackagePerAbi>True</AndroidCreatePackagePerAbi>
	</PropertyGroup>

Steps to Reproduce

Select local Android device as target, build configuration Release, hit Publish. but before:

  1. We try to specify versions inside .cproj:
    A:
		<!-- Versions -->
		<ApplicationDisplayVersion>1.0</ApplicationDisplayVersion>
		<AndroidVersionCode>007</AndroidVersionCode>
		<ApplicationVersion>7</ApplicationVersion>

after Publish in VS for windows this results in:
image

Version Code 1

B:

		<ApplicationDisplayVersion>0.007</ApplicationDisplayVersion>
		<AndroidVersionCode>007</AndroidVersionCode>
		<ApplicationVersion>7</ApplicationVersion>

after Publish in VS for windows this results in:

image

Version Code 1

As you can see there is no appearent way to set Version Code to other than 1 inside .cproj

  1. We do not modify manifest file to specify version code to workaround the issue above, otherwise we meet another bug: if one specifies version code inside manifest then the build process takes sdk build target from manifest too (why), doesn't find it (we never did put it there), then uses sdk 19 by default and gives us a nice "build failed".

Link to public reproduction project repository

https://github.com/taublast/MauiDroidVersionCodeBug/

Version with bug

6.0.486 (current)

Last version that worked well

Unknown/Other

Affected platforms

Android

Affected platform versions

et6.0-android

Did you find any workaround?

No.

Relevant log output

No response

@taublast taublast added the t/bug Something isn't working label Nov 7, 2022
@jsuarezruiz jsuarezruiz added area-publishing Issues with the app packaging/publishing process (ipk/apk/msix/trimming) platform/android 🤖 labels Nov 7, 2022
@AndreasReitberger
Copy link

I set the Version and VersionCode at the AndroidManifest.xml located in the Platforms folder.

<?xml version="1.0" encoding="utf-8"?>
<manifest
	xmlns:android="http://schemas.android.com/apk/res/android"
	android:versionCode="40"
        android:versionName="1.3.0"
	>
	<application
		android:allowBackup="true"
		android:label="AppName"
		android:icon="@mipmap/appicon"
		android:roundIcon="@mipmap/appicon_round"
		android:supportsRtl="true"
		android:networkSecurityConfig="@xml/network_security_config"
		>
		<!-- Xam.Plugins.Messaging -->
		<!--android:name="android.support.v4.content.FileProvider"-->
		<provider android:name="androidx.core.content.FileProvider" android:authorities="${applicationId}.provider" android:exported="false" android:grantUriPermissions="true">
			<meta-data android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/provider_paths" />
		</provider>
	</application>
	<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
	<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
	<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
	<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
	<uses-permission android:name="android.permission.INTERNET" />
	<uses-permission android:name="android.permission.CAMERA" />
	<uses-permission android:name="android.permission.FLASHLIGHT" />
</manifest>

@jsuarezruiz jsuarezruiz added the area-single-project Splash Screen, Multi-Targeting, MauiFont, MauiImage, MauiAsset, Resizetizer label Nov 7, 2022
@jsuarezruiz jsuarezruiz added this to the Backlog milestone Nov 7, 2022
@ghost
Copy link

ghost commented Nov 7, 2022

We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process.

@eddieyanez
Copy link

I also have this issue and I'm not using Maui, but Xamarin Forms. The Android app when built in release mode will completely ignore android:versionCode="1" android:versionName="0.0.1" inside AndroidManifest.xml and set them to 1 and 1.0.0 respectively. Another point that might be worth mentioning is that this happens when building locally, and on Azure DevOps.

@dellis1972
Copy link
Contributor

This is a comment from the docs at https://github.com/xamarin/xamarin-android/blob/main/Documentation/guides/building-apps/build-properties.md#androidversioncode

This property is ignored if `$(AndroidCreatePackagePerAbi)` and `$(AndroidVersionCodePattern)` are used.

That said, having the value be derived from ApplicationVersion when using AndroidCreatePackagePerAbi should probably be something we could look at.

In the meantime I have found that by setting the android:versionCode="4" in the Platforms/Android/AndroidManifest.xml does work, at least on .net 7.0.

dellis1972 added a commit to dellis1972/xamarin-android that referenced this issue Feb 14, 2023
…ilds

Fixes dotnet/maui#11139

Users trying to use `maui` and the new `ApplicationVersion` in
conjunction with `AndroidCreatePackagePerAbi` find that the version
is NOT used in the final set of apks.

This is because when we use `AndroidCreatePackagePerAbi` we are totally
ignoring the `ApplicationVersion` number. Instead we pick up the one
from the `AndroidManifest.xml` `android:versionCode`. For maui users This
is not obvious and is counter intuitive.

So lets use the `ApplicationVersion` when using `AndroidCreatePackagePerAbi`.
All the old code will remain in place, if the `ApplicationVersion` is
not set we will still fall back to `android:versionCode` and if that is
not set default to `1`.
dellis1972 added a commit to dellis1972/xamarin-android that referenced this issue Feb 17, 2023
…ilds

Fixes dotnet/maui#11139

Users trying to use `maui` and the new `ApplicationVersion` in
conjunction with `AndroidCreatePackagePerAbi` find that the version
is NOT used in the final set of apks.

This is because when we use `AndroidCreatePackagePerAbi` we are totally
ignoring the `ApplicationVersion` number. Instead we pick up the one
from the `AndroidManifest.xml` `android:versionCode`. For maui users This
is not obvious and is counter intuitive.

So lets use the `ApplicationVersion` when using `AndroidCreatePackagePerAbi`.
All the old code will remain in place, if the `ApplicationVersion` is
not set we will still fall back to `android:versionCode` and if that is
not set default to `1`.
dellis1972 added a commit to dellis1972/xamarin-android that referenced this issue Mar 14, 2023
…ilds

Fixes dotnet/maui#11139

Users trying to use `maui` and the new `ApplicationVersion` in
conjunction with `AndroidCreatePackagePerAbi` find that the version
is NOT used in the final set of apks.

This is because when we use `AndroidCreatePackagePerAbi` we are totally
ignoring the `ApplicationVersion` number. Instead we pick up the one
from the `AndroidManifest.xml` `android:versionCode`. For maui users This
is not obvious and is counter intuitive.

So lets use the `ApplicationVersion` when using `AndroidCreatePackagePerAbi`.
All the old code will remain in place, if the `ApplicationVersion` is
not set we will still fall back to `android:versionCode` and if that is
not set default to `1`.
dellis1972 added a commit to dellis1972/xamarin-android that referenced this issue Mar 15, 2023
…ilds

Fixes dotnet/maui#11139

Users trying to use `maui` and the new `ApplicationVersion` in
conjunction with `AndroidCreatePackagePerAbi` find that the version
is NOT used in the final set of apks.

This is because when we use `AndroidCreatePackagePerAbi` we are totally
ignoring the `ApplicationVersion` number. Instead we pick up the one
from the `AndroidManifest.xml` `android:versionCode`. For maui users This
is not obvious and is counter intuitive.

So lets use the `ApplicationVersion` when using `AndroidCreatePackagePerAbi`.
All the old code will remain in place, if the `ApplicationVersion` is
not set we will still fall back to `android:versionCode` and if that is
not set default to `1`.
dellis1972 added a commit to dellis1972/xamarin-android that referenced this issue Mar 17, 2023
…ilds

Fixes dotnet/maui#11139

Users trying to use `maui` and the new `ApplicationVersion` in
conjunction with `AndroidCreatePackagePerAbi` find that the version
is NOT used in the final set of apks.

This is because when we use `AndroidCreatePackagePerAbi` we are totally
ignoring the `ApplicationVersion` number. Instead we pick up the one
from the `AndroidManifest.xml` `android:versionCode`. For maui users This
is not obvious and is counter intuitive.

So lets use the `ApplicationVersion` when using `AndroidCreatePackagePerAbi`.
All the old code will remain in place, if the `ApplicationVersion` is
not set we will still fall back to `android:versionCode` and if that is
not set default to `1`.
dellis1972 added a commit to dellis1972/xamarin-android that referenced this issue Mar 20, 2023
…ilds

Fixes dotnet/maui#11139

Users trying to use `maui` and the new `ApplicationVersion` in
conjunction with `AndroidCreatePackagePerAbi` find that the version
is NOT used in the final set of apks.

This is because when we use `AndroidCreatePackagePerAbi` we are totally
ignoring the `ApplicationVersion` number. Instead we pick up the one
from the `AndroidManifest.xml` `android:versionCode`. For maui users This
is not obvious and is counter intuitive.

So lets use the `ApplicationVersion` when using `AndroidCreatePackagePerAbi`.
All the old code will remain in place, if the `ApplicationVersion` is
not set we will still fall back to `android:versionCode` and if that is
not set default to `1`.
dellis1972 added a commit to dellis1972/xamarin-android that referenced this issue Mar 22, 2023
…ilds

Fixes dotnet/maui#11139

Users trying to use `maui` and the new `ApplicationVersion` in
conjunction with `AndroidCreatePackagePerAbi` find that the version
is NOT used in the final set of apks.

This is because when we use `AndroidCreatePackagePerAbi` we are totally
ignoring the `ApplicationVersion` number. Instead we pick up the one
from the `AndroidManifest.xml` `android:versionCode`. For maui users This
is not obvious and is counter intuitive.

So lets use the `ApplicationVersion` when using `AndroidCreatePackagePerAbi`.
All the old code will remain in place, if the `ApplicationVersion` is
not set we will still fall back to `android:versionCode` and if that is
not set default to `1`.
dellis1972 added a commit to dellis1972/xamarin-android that referenced this issue Mar 23, 2023
…ilds

Fixes dotnet/maui#11139

Users trying to use `maui` and the new `ApplicationVersion` in
conjunction with `AndroidCreatePackagePerAbi` find that the version
is NOT used in the final set of apks.

This is because when we use `AndroidCreatePackagePerAbi` we are totally
ignoring the `ApplicationVersion` number. Instead we pick up the one
from the `AndroidManifest.xml` `android:versionCode`. For maui users This
is not obvious and is counter intuitive.

So lets use the `ApplicationVersion` when using `AndroidCreatePackagePerAbi`.
All the old code will remain in place, if the `ApplicationVersion` is
not set we will still fall back to `android:versionCode` and if that is
not set default to `1`.
dellis1972 added a commit to dotnet/android that referenced this issue Mar 27, 2023
…ilds (#7795)

* [Xamarin.Android.Build.Tasks] Fix Android Version Code for Release builds

Fixes dotnet/maui#11139

Users trying to use `maui` and the new `ApplicationVersion` in
conjunction with `AndroidCreatePackagePerAbi` find that the version
is NOT used in the final set of apks.

This is because when we use `AndroidCreatePackagePerAbi` we are totally
ignoring the `ApplicationVersion` number. Instead we pick up the one
from the `AndroidManifest.xml` `android:versionCode`. For maui users This
is not obvious and is counter intuitive.

So lets use the `ApplicationVersion` when using `AndroidCreatePackagePerAbi`.
All the old code will remain in place, if the `ApplicationVersion` is
not set we will still fall back to `android:versionCode` and if that is
not set default to `1`.
@ghost ghost locked as resolved and limited conversation to collaborators Apr 26, 2023
@samhouts samhouts modified the milestones: Backlog, .NET 8 May 24, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-publishing Issues with the app packaging/publishing process (ipk/apk/msix/trimming) area-single-project Splash Screen, Multi-Targeting, MauiFont, MauiImage, MauiAsset, Resizetizer platform/android 🤖 t/bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants