I am trying to make a basic Xamarin.forms (pcl) application (in Visual studio 2017) and i want to Target Lolipop (5.0.0, api level 21).
So i made a basic Xamarin solution and i adjusted the Android properties all to Android 5.0 lollipop
Compile using Android version "Android 5.0 (Lollipop)"
Minimum Android to target "Android 5.0 (API Level 21 - Lollipop)"
Target Android Version "Android 5.0 (API Level 21 - Lollipop)"
Unfortunately in my warning list i get the following
Severity Code Description Project File Line Suppression State
Warning The $(TargetFrameworkVersion) for Xamarin.Forms.Platform.dll (v7.0) is greater than the $(TargetFrameworkVersion) for your project (v5.0). You need to increase the $(TargetFrameworkVersion) for your project. Prolang.Android C:\Projects\Prolang\Prolang\Prolang.Android\Prolang.Android.csproj
If i google for this error most people say to indeed update your android project to use the latest Targetframework version. But in my case i really want to only be able to call Api calls that are available to level 21 aka Android 5.0 Lollipop. As in i want the compile time safety net that i only use Api Calls from Api level 21.
To me it seems like i have to downgrade my xamarin.Forms dll to a version that is made specifically for android lollipop since the one i use right now targets a higher version.
So should i downgrade my xamarin.forms dll to achieve this and get rid of the error? And if i downgrade to what version do i need to downgrade so i target Android 5.0 Lollipop? This information is all pretty unclear to me.
Xamarin.Forms is designed using the Android's support libraries so it will run on a wide range of APIs without any additional actions from the developer.
If you are using native APIs via Xamarin.Android (assumably via Forms' Dependency Service) then yes you would have to be aware of the API level of the method calls.
That said, since Xamarin.Forms uses the com.android.support.* libraries and you would have to have to a Forms versions that uses com.android.support:design:21.x.x and the associated Android build tools for API 21.
Now you can review the package dependancies and you will see that your choices are Forms' is 1.4
`1.4.0.6336-pre1` to `1.4.4.6449`
Note: v1.5.x moved to version 22 of the Android support libraries
IMHO using Forms's 1.4 would a bad mistake due to its age and the mountain of improvements and bugs fixes since 2015, you are so much better off:
Using the latest Forms version
Set the Framework version to latest (7.1)
Set the Target Android version to Android 5.0 (API Level 21)
Set the Minimum Android version to whatever you need...
Forgo the compile time API checks
Check runtime API issues via API-21 devices and emulators
Related
I am new to Android development. I am told to create an android app that should support android Version 5 (Lollipop) and android Version 9 (Pie). How should I approach this? Should i create 2 different apps supporting Version 5 and Version 9?
Is there any way to make a single app that runs on both version 5 and version 9?
If I use AndroidX, then will it make sure that the app look and function same on both version 5 and 9?
P.S.: I am told to build the app using Xamarin Android Native (not Xamarin Forms).
Thanks.
First you need to understand the following Settings:
Target Framework :Specifies which framework to use in building your application. This API level is used at compile time by Xamarin.Android.
Minimum Android Version:Specifies the oldest Android version that you want your app to support. This API level is used at run time by Android.
Target Android Version:Specifies the version of Android that your app is intended to run on. This API level is used at run time by Android.
Normally, all three Xamarin.Android API levels are set to the same value. On the Application page, set Compile using Android version (Target Framework) to the latest stable API version (or, at a minimum, to the Android version that has all of the features you need)strong text
On the Android Manifest page, set the Minimum Android version to Use Compile using SDK version and set the Target Android version to the same value as the Target Framework version.
If you want to maintain backward compatibility with an earlier version of Android, set Minimum Android version to target to the oldest version of Android that you want your app to support.
Then in you case,you could set the Target Framework version to Android 9.0,and Minimum Android Version to Android 5,Target Android Version to Android 9.0.
I'm becoming crazy. I want to compile Xamarin.Forms for Android 8.0 with Visual Studio 2019
I setup all correct, I think, but I always get:
Error The $(TargetFrameworkVersion) for App_test32.Android (v8.0) is less than the minimum required $(TargetFrameworkVersion) for Xamarin.Forms (8.1). You need to increase the $(TargetFrameworkVersion) for App_test32.Android. App_test32.Android
You cannot target 8.0 and that's for a reason. Starting from August 1, 2019 Google doesn't accept new apps that doesn't have targetSdkVersion set below Android 9.0 (for new apps).
You can read more about this here (Meet Google Play's target API level requirement) and more specifically here (Target API level requirements for the Play Console).
If you open the second link, you will see that the targetSdkVersion will be bumped even to Android 10, starting from August 3, 2020 (for new apps)
This is what you are seeing - Xamarin has restricted this, so that you don't set it lower that what it must be. Otherwise, you will be able to build it, but you won't be able to upload it. You can see the minimum version set here
However, you can still set it to 8.0, but you will need to downgrade the Xamarin.Forms & Xamarin.Android to a version that is way back - probably even before 4.0. This way you will be able to build the project, but the end result will be the same - you won't be able to upload the app to the PlayStore.
Useful link to get familiar with the difference between Target Framework, Minimum Android Version & Target Android Version from the official docs
Here is the most important comparison:
Minimum Android Version <= Target Android Version <= Target Framework
To sum up, I will quote again the guys from Microsoft (see in the link above):
We recommend that you explicitly set the Target Android version to the latest version of Android that you use to test your app. Ideally, it should be set to the latest Android SDK version – this allows you to use new APIs prior to working through the behavior changes. For most developers, we do not recommend setting the Target Android version to Use Compile using SDK version.
I have developed an application for Android in Kotlin. I was assuming that Android studio is taking care of the compatibility of the used libraries and the code once I setup the minimum targetted Android version.
I am getting responses that the app is crashing with noSuchMethodError, which is linked to a listview's .getView() methode.
I am running the app on Android 8, but these errors are reported on Android 6 and 7 randomly.
I was reading different articles about this failure and I am having the feeling that i might need to setup the libraries setting differently in Studio.
In your build.gradle you can specify a minSdk and a targetSdk, while the targetSdk specifies as the name says the target audience and is in general the newest version e.G. 29, your minSdk takes care of your minimum supported version.
So if you have minSDK 19, Android Studio will show Warnings in your code whenever a method or class is not compatible with devices running sdk 19.
Anyway this might not solve your "noSuchMethodError".
I was following setup guide for android in react-native documentation
and have it up and running correctly using suggested SDK v23
However there are much newer SDK versions available, I would like to set v23 as a minimum SDK version, but use latest one as my main one.
Being new to android I'm not sure on how to achieve this, what steps should I take? I can see option to edit sdk versions in some xml files and can download latest one using Android Studio.
As a side note, what are my limitations of using SDK v23? Will it not work on newer devices, do I loose out on performance etc... ?
According to some sources React Native does support up to API level 25, but there seems to be some disagreement on the issue. So according to official sources, React Native only supports Android API level 16 to level 23.
I haven't used React Native myself, but assuming versioning works the same as native development, an application with a compileSdkVersion lower than the version it is running against will run fine. The only limitations on the application would be that it would be unable to access the new features and APIs introduced by those higher SDK versions.
For example, Android 8.0 (API level 26) introduced a new Picture-in-Picture API, but the method used to enter picture-in-picture mode would not be available in code compiled against API level 23. Some new features may effect performance (usually positively), but an application compiled against API level 23 won't perform any worse on on a device running on API 26 than one running on API 23.
In my custom view I'm using the method drawTextOnPath(...) which is not supported for hardware acceleration until 4.1.
So I wanted to add an if statement which checks the current Android version on runtime and turns the hardware acceleration on if this version is greater or equals to 4.1.
My problem is that I compile my project with Android 4.0 SDK (which is my minimum version), so I don't have the Build.VERSION_CODES for Android 4.1.
Should I compile my project with 4.1 although my minimum version is 4.0 ?
I wrote that up once: Android targeting system
Important parts:
When compiling a Java application with a Java 7 compiler, you can’t
use it with a Java 6 interpreter. The interpreter will tell you, that
it can’t interpret the produced byte-code, even thought you’re not
using any Java 7 language features. If you want to compile with the
latest compiler but make your byte-code runnable on older JVM
instances, you’ll need to tell the compiler to do so (using the
-target-flag).
In Android, you can declare what platform-versions you support in your
manifest-file, using the <uses-sdk>-element and it’s
android:minSdkVersion and android:targetSdkVersion-attributes. The
difference between those “targeting mechanics” is, that Android does
not care against which platform version the application was compiled.
If you declare your application to be compatible with API Level 4,
Android will happily install it, even if you compiled it against
Android 4.1 (API Level 16).
So in short:
If you want your application to work with the newest Android platform, build against it.
Use minSdkVersion to declare the lowest API Level which is supported by your application.
As your targetSdkVersion, use the API Level against which you compiled the application.
Use [Android] Lint to check for (possibly) unsupported API calls.
Use conditional execution and the #TargetApi-annotation to use newer APIs when available.
When you're building your application with the newest SDK, you'll have all the Build.VERSION_CODES available.
Yes, you have to compile against 4.1 if you use 4.1's features, even if you do so conditionally, otherwise compiler will not be able to build your app because it will consider all 4.1 features as invalid (non-existing).