How can I support API 16 but still have Leanback? - android

I made my game work on Android TV, it required Leanback library, which wants minSdkVersion to be 17. I must support API 16 too. What can I do?
When building, I get an error this suggestion:
Suggestion: use tools:overrideLibrary="android.support.v17.leanback" to force usage
What exactly does it do? Does it actually make my app still support API 16? What am I losing?

You can find the detailed information here.
Here is what it says:
tools:overrideLibrary marker
A special marker that can only be used with uses-sdk declaration to
override importing a library which minimum SDK version is more recent
than that application's minimum SDK version. Without such a marker,
the manifest merger will fail. The marker will allow users to select
which libraries can be imported ignoring the minimum SDK version.
And you need to do the following: In the main android manifest :
<uses-sdk android:targetSdkVersion="14" android:minSdkVersion="2"
tools:overrideLibrary="android.support.v17.leanback"/>
Hope this helps.

Related

Building MAUI Android Failing

I created a brand new MAUI app (I had to create a new app as the previous app I'd created with a preview version didn't work when I upgraded Visual Studio preview). This app is using prism.maui which shouldn't make any difference and I'm also using a class library built with the preview version.
My app runs fine with Windows so I have no concern that I have issues with the app. I have also cleared out the obj folder multiple times with no joy.
When I build Android I get the following error message:
Error AMM0000
uses-sdk:minSdkVersion 19 cannot be smaller than version 21 declared in library D:\Code\AzureDevops\BootCom.Money.Xamarin\App\Money.App\obj\Debug\net6.0-android\lp\164\jl\AndroidManifest.xml as the library might be using APIs not available in 19
Suggestion: use a compatible library with a minSdk of at most 19,
or increase this project's minSdk version to at least 21,
or use tools:overrideLibrary="androidx.security" to force usage (may lead to runtime failures)
Money.App D:\Code\AzureDevops\BootCom.Money.Xamarin\App\Money.App\obj\Debug\net6.0-android\AndroidManifest.xml 35
I know how to fix this - but even when I do I get a further issue:
AMM0000
Attribute application#appComponentFactory value=(androidx.core.app.CoreComponentFactory) from AndroidManifest.xml:24:18-86
is also present at AndroidManifest.xml:22:18-91 value=(android.support.v4.app.CoreComponentFactory).
Suggestion: add 'tools:replace="android:appComponentFactory"' to element at AndroidManifest.xml:11:3-33:17 to override.
Money.App D:\Code\AzureDevops\BootCom.Money.Xamarin\App\Money.App\obj\Debug\net6.0-android\AndroidManifest.xml 24
I really don't know where to go from here. I've recreated this app now 3 times and if this is how it needs to work for MAUI I need to go back to using Xamarin.
Please help!
I had the same error after I added a package name via the properties of the project.
As a consequence of adding the package name via the options of the project, the AndroidManifest.xml package attribute was updated, wich is what is expected, but there was also a tag that was being added, wich was unwanted.
The tag was the following:
<uses-sdk />
After removing this tag everything worked again.
Go to androidManifest.xml file
add: uses-sdk android:minSdkVersion="21" if not exist
otherwise update uses-sdk section to uses-sdk android:minSdkVersion="21"
That solves my problem

How can I add foregroundServiceType to a library manifest while maintaining backwards compatibility?

My library project has a location service, and per Android Q requirements it sets the android:foregroundServiceType="location" attribute in the manifest. When an app module uses my library and compiles against API level 28, it fails with the following error:
AndroidManifest.xml:57: AAPT: error: attribute android:foregroundServiceType not found.
How can my library maintain compatibility with older versions, while making sure the functionality works on Android Q?
I had same error and after migrating to Androidx and updating compileSdkVersion from 28 to 29 my issue was resolved. So please do these changes and you can get your solution
My goal is to avoid breaking anyone's build when the library version is updated, and at the same time avoid forcing the developer to compile against API 29. It seems I have two choices:
Provide a separate library so that developers compiling against API 28 and lower don't get impacted;
warn developers targeting the new version to replace the service definition in the manifest using tools:node="replace".
The problem with the first approach is that I will need to maintain two libraries for some time. The problem with the second is that developers must remember to revert the change once they update the SDK version.
In my case, I will go with the second approach. By passing an explicit foreground service type to the startForeground method when targeting Android Q, I can cause a crash if the type is not set in the manifest. The developer can therefore catch this when targeting Android Q and revert the manifest change to fix it.

Xamarin.Android check API Level

I have an Android App that has been developed, compiled and released using the default SDK option
Use Compile using SDK Version
I need to make additions to this application, however I do not know what SDK it targeted at compiled time when it was last tested and released.
The problem being later API levels have different requirements, such as Authorization changes where you need to seek permission from the user. I can see from the code this does not do this, so it must be earlier.
Is there a way to know from source or the previous compiled .apk which SDK was used? I do not have permission to update all of the code to add in all of these authorization changes, just have a few small changes to do.
Maybe you can add your changes inside an if like this:
if (Android.OS.Build.VERSION.SdkInt >= Android.OS.BuildVersionCodes.**TheVersionYouNeed**) {
// Your code
}
An .apk is just a zip file, so unzip it and look at the manifest xml file.
Near the top of the file you should find an element that can contain the min, target and max SDK.
<uses-sdk android:minSdkVersion="integer"
android:targetSdkVersion="integer"
android:maxSdkVersion="integer" />
You will be looking for the targetSdkVersion API level
re: https://developer.android.com/guide/topics/manifest/uses-sdk-element.html

How to support lowest possible API version?

I'm developing a Android library and I want to support as many API versions as possible. I have stumbled upon a problem with AsyncTask and found an answer here on SO. The proposed code to use is:
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.GINGERBREAD_MR1) {
task.execute(params);
} else {
task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, params);
}
My question is, how do I include the proposed code AND support lowest possible API level? What API version should I reference? What should I write in the uses-sdk tag inte manifest?
Since the field THREAD_POOL_EXECUTOR in AsyncTask is only available from API level 11. Can this code be compiled to a lower level?
Thanks!
Assume that you line below exists in you manifest
<uses-sdk android:minSdkVersion="8" android:targetSdkVersion="17"/>
This means that you are using features from API-17 but to ensure backwards compatibility your application may start on minimum API-8 (Froyo).
According to your example, using THREAD_POOL_EXECUTOR for API-17 or lower is OK. And running your code with Froyo device is OK too. Because THREAD_POOL_EXECUTOR field will not be used in this case.
In the manifest set android:minSdkVersion="minimumApiYouNeed", this is the lowest api you want to support, and the android:targetSdkVersion="maximumApi". This is the api that will be used to compile the code. This way you will be able to do things like what you wrote there, if you ever write something that is not supported by the minimum api, the editor will notify you, but it will work well if you do the checking it will work well
You will have to use API level 11 or higher unless you can find a library that works on an earlier API level that provides the THREAD_POOL_EXECUTOR implementation. Also, check to see if Google provides any backports or support libraries that would allow this to work before API 11.
This supports Android back to 2.1 (sdk version 7), but compiles the code against sdk version 17 (HoneyComb). You would have to add that tag to your manifest, of course.
<uses-sdk
android:minSdkVersion="7"
android:targetSdkVersion="17" />
Your project.properties should include this line:
# Project target.
target=Google Inc.:Google APIs:17

Suppress AndroidManifest.xml minSdkVersion related warning

As recomended here http://developer.android.com/guide/practices/screens_support.html for compatibility reasons my AndroidManifest.xml contains this:
<uses-sdk android:minSdkVersion="3" android:targetSdkVersion="4"/>
This generates warning in eclipse:
Attribute minSdkVersion (3) is lower
than the project target API level (4)
Are there any means to suppress this warning or get rid of it any other way? It is really annoying.
In short, there is no built-in way to do this that I know of.
Here's a discussion from last August.
And here is a Xavier Durochet's response.
It looks like you can manually remove it according to Mark Murphy's response in the first thread:
Or, you can modify SetupTask.java, eliminate this test (lines 297-308 in
the code indexed by Google Code Search), and build it into a custom
version of the Android Ant extension
There is a feature request that may deal with this, but who knows when it will be implemented.
The answer from 2011 is no longer accurate. It was fixed in ADT 17 according to this bug.
This warning is an usual one. I am using minSdkVersion to support Android 1.5 and I am building for Android 1.6 to support small screens. You can build your application with the latest Android 2.3 library, but still support a lower version.

Categories

Resources