Xamarin Forms / API Level 34 / Deployment Failed

CSharpest 0 Reputation points
2024-10-04T15:53:27.25+00:00

While migrating the mobile app to some new tech, we need to deploy an update to our current app which requires Android 14. I've updated the AndroidManifest.xml to 34:

<uses-sdk android:minSdkVersion="28" android:targetSdkVersion="34" />

The app builds fine but when I try to deploy and run in an emulator I get this error:

/Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Legacy.targets(348,5): warning XA1008: The TargetFrameworkVersion (Android API level 33) is lower than the targetSdkVersion (34). Please increase the $(TargetFrameworkVersion) or decrease the android:targetSdkVersion in the AndroidManifest.xml so that the API levels match. /Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Common.targets(2103,3): error XABLD7024: Xamarin.Tools.Zip.ZipIOException: The file 'obj/Debug/android/bin/com.Funny.apk' is not a ZIP archive. /Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Common.targets(2103,3): error XABLD7024:   at Xamarin.Tools.Zip.ZipArchive.Open (System.String path, System.IO.FileMode mode, System.String defaultExtractionDir, System.Boolean strictConsistencyChecks, Xamarin.Tools.Zip.IPlatformOptions options) [0x0014c] in /Users/runner/work/1/s/LibZipSharp/Xamarin.Tools.Zip/ZipArchive.cs:283  /Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Common.targets(2103,3): error XABLD7024:   at Xamarin.Android.Tasks.ZipArchiveEx..ctor (System.String archive, System.IO.FileMode filemode) [0x0001b] in <2042d6a236404eba9dfd12d3be81a9bd>:0  /Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Common.targets(2103,3): error XABLD7024:   at Xamarin.Android.Tasks.BuildApk.ExecuteWithAbi (System.String[] supportedAbis, System.String apkInputPath, System.String apkOutputPath, System.Boolean debug, System.Boolean compress, System.Collections.Generic.IDictionary`2[TKey,TValue] compressedAssembliesInfo, System.String assemblyStoreApkName) [0x0004d] in <2042d6a236404eba9dfd12d3be81a9bd>:0  /Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Common.targets(2103,3): error XABLD7024:   at Xamarin.Android.Tasks.BuildApk.RunTask () [0x00117] in <2042d6a236404eba9dfd12d3be81a9bd>:0  /Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Common.targets(2103,3): error XABLD7024:   at Microsoft.Android.Build.Tasks.AndroidTask.Execute () [0x00000] in /Users/runner/work/1/s/xamarin-android/external/xamarin-android-tools/src/Microsoft.Android.Build.BaseTasks/AndroidTask.cs:17      1 Warning(s)     1 Error(s)

Note that the app uses Xamarin.Forms version 4.0.0 and Xamarin.Essentials version 1.8.1. We're building on an iMac.

Any ideas?

Developer technologies | .NET | Xamarin
{count} votes

2 answers

Sort by: Most helpful
  1. Graham McKechnie 441 Reputation points
    2024-10-07T22:04:07.34+00:00

    @CSharpest

    I would guess it is because of Xamarin.Android.Legacy. Check what the AndroidManifest.xml reads in the obj/release folder and check what the value of <uses-sdk android:minSdkVersion="28" android:targetSdkVersion="34" />. I'd suspect it is getting overridden compared to your AndroidManifest.xml. You are probably also dragging in support.V4 libs. That stuff is really old. I've never used Xamarin.Forms or Xamarin.Essentials, so I can't comment on those, but they would need to be whatever the latest versions are.

    I can assure you it does work for Android 14, as I have a couple of apps on Google Play. You will get a couple of build warnings, but they can be safely ignored.

    1 person found this answer helpful.

  2. Graham McKechnie 441 Reputation points
    2024-10-08T23:10:52.17+00:00

    @CSharpest Yes, its old...been working for years. Sure is...

    All the Support libs stuff goes back to 2018. AndroidX libs replace all of that. I can't figure out how you got it to even Android 13, let alone 14. Reckon, it might be time for a rewrite, especially since you'll be on the clock regarding Android 15 within 12 months.

    Xamarin.Android 14 is good for another 12 months before you are forced to move to net9.0-android35 or net10.0-androidXX

    If you are up for a rewrite, I'd suggest getting to know Android's NavigationComponent for modern Android development using views. It introduces the idea of a Single Activity app. The MainActivity is just a holder for fragments that represent all the screens of an app. Each fragment is represented in a NavigationGraph, which handles the navigation in your app. At the same time, learn about ConstraintLayout, which is probably the only layout you will ever need.

    I've got a GitHub page that takes you through the original NavigationComponent codelab that Google provided. Then, there is a series of NavigationGraphX projects (x is just a number) that add further complexity to a typical app. There are also different .Net versions Net6,7,8 etc. While you are learning the NavigationComponent, I'd suggest staying with Xamarin.Android 14 until you are comfortable with the idea of a Single activity and multiple fragments, and then convert your project to net 8 or net 9, depending on where you are. The conversion to .net is relatively simple once you have the NavigationGraph project working well. https://github.com/gmck

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.