0

I've created a blank Mobile App (Xamarin.Forms) application.

enter image description here

By default the target Android framework for this empty application is set to version 8.1 (Oreo)

enter image description here

I want to change this version to version 8.0, which is installed and available on the workstation.

enter image description here

But when I select the version 8.0 and Visual Studio recompiles the project I get a bunch of errors.

enter image description here

Error NU1202 Package Xamarin.Android.Support.Design 27.0.2.1 is not compatible with monoandroid80 (MonoAndroid,Version=v8.0). Package Xamarin.Android.Support.Design 27.0.2.1 supports: monoandroid81 (MonoAndroid,Version=v8.1)

Okay, then. I opened NuGet Manager and tried to update (downgrade) versions of corresponding components.

enter image description here

But when I try to reinstall a component with a lower version over an existing higher version I get the same error messages. And I get these messages for every component I want to downgrade.

The question: how can I change the target framework version for Android Xamarin application and it will finally work?


UPDATE

I tried to remove MonoAndroid reference from the Android Xamarin project in the Solution and add the reference to the lower version manually.

enter image description here

But as I click OK on the dialog, the MonoAndroid reference version 8 (instead of version 7) has been added.

enter image description here

Novice Student
  • 147
  • 1
  • 9
  • You need to replace MonoAndroid with version 7.x, somehow. – TheWanderer Dec 03 '18 at 14:03
  • @TheWanderer thank you, but how can I do this replacement? I supposed (probably I am a naive person) that a full fledged IDE like VS will do it as I change target Android API version. But I was wrong. I searched on StackOverflow, but posts [like this](https://stackoverflow.com/questions/49246580/xamarin-how-to-update-mono-android-version-to-resolve-dependencies?rq=1) unfortunately do not help. – Novice Student Dec 03 '18 at 14:11
  • I wish I knew. I've never even used VS, much less Xamarin. – TheWanderer Dec 03 '18 at 14:13
  • @TheWanderer anyway thanks. I have updated my question with the pictures. I tried to remove the reference to the MonoAndroid and replace it with the reference to the lower version. But it did not work. Visual Studio adds another version than I selected manually. – Novice Student Dec 03 '18 at 14:24
  • To whoever silently downvotes my question, what is wrong with my question? – Novice Student Dec 03 '18 at 15:00
  • You are saying "target Android framework" but are showing that you are trying to change "compile Android framework", what exactly is your goal? – SushiHangover Dec 03 '18 at 20:42
  • @SushiHangover , "Target framework" is used twice, confusingly, once for the "Compile using ..." project property and again for the Android manifest . Note that the GUI for the project options in the screenshot above says "Compile using Android version: (Target Framework)" and also this property is called in the .csproj file. – jgoldberger - MSFT Dec 04 '18 at 01:22
  • @jgoldberger-MSFT ? Not confusing really, one is used to compile against and one is used for APP runtime. – SushiHangover Dec 04 '18 at 02:19
  • @SushiHangover I want to run this app on actual device with Android 8.0, not Android 8.1. And this is reason, why I want to compile the project using framework version 8.0, instead of 8.1, Is it wrong approach? – Novice Student Dec 04 '18 at 05:44
  • @NoviceStudent *Normally* that is not the way to go unless there is an API change issue that prevents you from *compiling* against the latest framework. So in your case compile against 8.1 and set the runtime target to 8.0 (but just to use the app on an 8.0 device is not a good reason to do it this way), personally I would be using 9.0/Pie as the compile target for any new coding.... You might need to perform runtime API level checks to use different APIs for the different Android OS versions, but most 8.0 to 8.1 changes include OS level changes and not API changes... – SushiHangover Dec 04 '18 at 05:55
  • @NoviceStudent One of the only times is makes sense to set the API level the same as the compile and runtime target version (and possibly the min. target level) is when you are working with fixed version devices, like a bar coding device, point of sale device, etc... as those OEM/custom devices will never run any newer version and you will never need to test on any other devices and the app will never be distributed on one of the Android Stores. Again personally, I would be using 9.0/Pie as the compile target and as the runtime target.... – SushiHangover Dec 04 '18 at 06:03
  • @SushiHangover I am evaluating xamarin for enterprise level apps, and there will be a variety of tasks, probably including fixed-version devices. I am just checking how easy is working with this tool and how much time does it take to implement and run a simple app (for the first time) on an actual device. I set the minimal version for version 5 and target version for 8. And compiled the project and installed the apk. But application starts and stops immediately. On emulator it works ok. Something is wrong with this tool I guess. – Novice Student Dec 04 '18 at 08:18
  • @SushiHangover Issue related to start and immediate stop was related to the packaging the apk file. I've resolved it btw. – Novice Student Dec 04 '18 at 10:01
  • @SushiHangover What is confusing is that in the .csproj file property is used for the "Compile with android version ..." GUI property in the Android project options. And it also says in parentheses "Compile using Android version: (Target Framework)", so yes, it can e confusing... it is not to me as I know what they do, but for a new user it can be. – jgoldberger - MSFT Dec 04 '18 at 19:42
  • @jgoldberger-MSFT Maybe , if the Android Min. and Max. Targets for the APK/app were there "in name" in some degree, I would agree. but they are not in the .csproj, but the mannie. (A `.csproj` is for "build/compile" properties after all). The Xamarin "Understanding Android API levels" does explain the three major ones quite well. – SushiHangover Dec 04 '18 at 22:22
  • Yes, I know. I will end this silly argument now. Yes, it is explained if one does read the docs, but unfortunately not everyone does, and for those who don't it can be confusing. In my years as a Xamarin support engineer, I have had many cases come in where people were confused by "Target framework" moniker being used in two places, i.e. in both the .csproj file and in the Android Manifest. So regardless of what you say, as an experienced and very knowledgeable Xamarin user, it is confusing for some newbies who forego reading up on the docs. – jgoldberger - MSFT Dec 05 '18 at 01:02

1 Answers1

1

If you really need to use 8.0 instead of 8.1, then you will need to remove all of the 27.x.x versions of the Xamarin.Android.Support packages and install the 26.1.0.1 versions instead as the 27.x.x series is not compatible with Android version < 8.1.

But why do you need to target/compile with Android 8.0? Generally you want to compile with and target the latest available version. You can then set the minimum android version you want to support in the Android Manifest "Minimum Android Version" property in the project properties. Or this entry in the raw XML for the manifest:

<uses-sdk android:minSdkVersion="21" /> 

where "21" is the API number for the minimum version you want to support. Just make sure you do not use any types/methods/etc that are only available in Android versions > the minimum version you set. If you do that, your app will run on all Android versions >= the minimum version set. So perhaps you only need to set the minimum version and not the "Compile with ..." and/or "Target" android version?

jgoldberger - MSFT
  • 5,978
  • 2
  • 20
  • 44
  • thank you for assistance, I want to use 8.0, beacuse my actual device has Android 8.0 installed. Not 8.1. And I would like to check how does this app run on this actual device. Moreover, compiling for Android 8.0 is an example, what if I want to compile the project for Android 7, or even Android 6? Regarding removal of unwanted packages, I tried NuGet manager and it does not allow to reinstall packages with older versions. I guess I have to edit csproj and all project xml files manually, right? – Novice Student Dec 04 '18 at 05:47
  • 1
    Again, you can still compile with 8.1 and run on all earlier android versions just by setting the minimum android version in the Android manifest, so I seriously recommend compiling with the latest Android version... it will make life much easier for you now and into the future. – jgoldberger - MSFT Dec 04 '18 at 19:33
  • "I guess I have to edit csproj and all project xml files manually, right?" Not necessarily. You can set the "Compile with ...", minimum, and Target Android versions in the Project properties (options in VS for Mac). And you can totally uninstall all of those Xamarin.Android.Support packages and specifically reinstall any older version by selecting it in the drop down list in the nuget package manager. I know, I just tested doing this with your exact scenario and it worked like a champ. – jgoldberger - MSFT Dec 04 '18 at 19:38