Building MAUI Android Failing - android

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

Related

Flutter "Add 2 App" Android integration with adjustments to generated .android

I'm working on an Android app with 3+ years of Kotlin development and want to gradually migrate it to Flutter feature-by-feature. I use option B of the "add 2 app" integration where I depend on the module's source code. Features written Flutter are integrated into the native Android app with FlutterActivity or FlutterFragment. This worked great for the first feature however now I have an issue with migrating the second feature. The second feature requires the packages camera and firebase_ml_vision. Now the problem is that camera requires a min SDK of 21 but the generated Android code in .android sets the min SDK to 16. Additionally firebase_ml_vision requires initialization of Firebase which also needs to be added to .android. I'm thinking about adding .android to VCS and add the required changes however this is generated code. It gets removed when flutter clean is called and generated on flutter pub get. I would have to constantly adjust the generated code when Flutter changes/removes it :( .android only hosts the "skeleton" Android app which is started when the Flutter project is run from IDE (or command line). It is not the host app (the old, native app) where Firebase is already configured. However the .android app is used for quick development cycles. If I cannot use this anymore because of said limitations, I would always have to start the native Android app (host) and lose many benefits of Flutter like hot reload :( Has anyone come across the same problem?
Update:
In this article they clearly state that .android should not be modified or added to VCS. They even mention the camera module as an example. However this does not work and can be reproduced with a few simple steps:
Create a new module: flutter create --template=module --project-name example
cd example
Add camera plugin to pubspec.yaml
flutter pub get
Now running flutter build apk results in the following error:
/Users/sven/Development/example/.android/app/src/main/AndroidManifest.xml Error:
uses-sdk:minSdkVersion 16 cannot be smaller than version 21 declared in library [:camera] /Users/sven/.pub-cache/hosted/pub.dartlang.org/camera-0.5.8+11/android/build/intermediates/library_manifest/release/AndroidManifest.xml as the library might be using APIs not available in 16
Suggestion: use a compatible library with a minSdk of at most 16,
or increase this project's minSdk version to at least 21,
or use tools:overrideLibrary="io.flutter.plugins.camera" to force usage (may lead to runtime failures)
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:processReleaseManifest'.
> Manifest merger failed : uses-sdk:minSdkVersion 16 cannot be smaller than version 21 declared in library [:camera] /Users/sven/.pub-cache/hosted/pub.dartlang.org/camera-0.5.8+11/android/build/intermediates/library_manifest/release/AndroidManifest.xml as the library might be using APIs not available in 16
Suggestion: use a compatible library with a minSdk of at most 16,
or increase this project's minSdk version to at least 21,
or use tools:overrideLibrary="io.flutter.plugins.camera" to force usage (may lead to runtime failures)
I noticed you are facing 2 issues/ questions:
Minimum android sdk compatibility mismatch: Probably requires some work by the flutter team for a proper fix (I expected the flutter_module/build.gradle to be more useful, but it wasn't (not the one in build/ or .android), but as a workaround, some :app module AndroidManifest.xml changes using uses-sdk will work:
<manifest ...>
<uses-sdk android:targetSdkVersion="29" android:minSdkVersion="21"
tools:overrideLibrary="com.example.flutter_module, com.example.flutter_module.host"/>
...
</manifest>
(I set the default package name for the flutter module but you should replace both instances of com.example.flutter_module with your package name. (check your build.gradles). What I do here is raise the minSDK for the 2 flutter modules that were added. The error message you got recommended lowering the minSDK for camera to 16, but this is not a good idea (the camera plugin developers set it to 21 probably because the APIs they use have minSDK 21, e.g. camera2).
How to setup firebase/ dependencies config in build.gradle? (i.e. firebase_ml_vision and firebase 'platform specific configuration'): Change your main app's app/build.gradle and AndroidManifest.xml as per the instructions. This is what the doc says:
Perform those Android Gradle file edits on your outer, existing Android app rather than in your Flutter module.
Let me know if you need anymore help :)
on android/app/build.gradle changing minSdkVersion to 21

How can I support API 16 but still have Leanback?

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.

Overriding Library twice in android studio project manifest

Min sdkversion of my project is 8.I am using two libraries whose min version is 9 and 10.When I run my project it showed two errors that uses-sdk:minSdkVersion 8 cannot be smaller than version 10 declared in library Suggestion: use tools:overrideLibrary="com.brightcove.seamless" to force usage for one.When I did this it asked the same for other library.But since we can use tools:overrideLibrary once I dont know how to overcome this...please help...
Pre-Required:
Add Your library inside gradle with compile scope
In Side AndroidMenifest.xml file
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="xx.tech.cs.xx" >
And then above application start tag need to add
<uses-sdk tools:overrideLibrary="com.brightcove.seamless"/>
No need to change the minSDK version of your applications so it will go through with this I hope you can work this code in your program.
I have same issue for the other minSDK=14 version library and my application minSDK is 10 So I use this way.

Using ActionBarSherlock in Mono Android

I am trying to implement the ActionBar in a Mono Android application. Could someone provide me steps to including the ActionBar project in my solution? I have seen the sample projected provided at this url
https://github.com/xamarin/monodroid-samples/tree/master/ActionBarSherlock
Do I have to simply add a reference of the ActionBarSherlock project in that sample? When I attempt to add a reference to that project I get many errors such as "Error retrieving parent for item: No resource found that matches the given name 'android:TextAppearance.Holo.Widget.ActionBar.Menu'." in file abs_styles.xml
Has anyone else successfully added ActionBarSherlock to a Mono Android Project? Could you please provide me steps to get a simple example working?
Ok, this is how I got it working...
Open up the sample project and build just the 'ActionBarSherlock' project on Release mode. Make sure that the minimum target android version is 4.0.3 (required)
Take the dll and reference it in your project. I have found that you can get it to compile fine if your project has a minimum android version of 2.2 - I found that if you used profile version 2.1 it doesn't work, but that just might of been my app. Maybe your minimum version is too low? I also set my 'target' android to be the latest... I don't know if this helps too.
The reason I say to reference the dll instead of the project is that you will get the correct intellisense. Otherwise as you can see in the example project it does not (Makes working on it a pain!).
Make sure you have a reference to the v4 support lib in your project (Mono.Android.Support.v4)
The final step is that need to change your default theme to use a Sherlock theme. (see xml below for example)
Use the ActionbarSherlock.* namespaces when adding Actionbars etc...
Example manifest after adding ActionbarSherlock:
<manifest ...>
<uses-sdk android:minSdkVersion="8" android:targetSdkVersion="16" />
<application android:label="IDNT" android:theme="#style/Theme.Sherlock.Light.DarkActionBar" android:icon="#drawable/Icon">
</application>
</manifest>
BEWARE: There is a small issue with all this... If your project has a minimum version of under 3.0 (ie 2.2 as per my example) and you compile with linking (ie SDK assemblies only) you will get an error 'Mono.Cecil.ResolutionException: Failed to resolve Android.Database.IDatabaseErrorHandler'. I am currently sending support messages about this to Xamarin and will edit this post once I work out a fix.
EDIT: To fix the issue I have mentioned above make sure that the project options -> Application -> Minimum Android to target option is at LEAST 4.0.3. Your minSdkVersion can still be 7/8 or whatever so it will still run in older android versions. It also means you have to be careful you dont code in stuff that is for higher versions.

Not able to use new resource identifiers in Android with targetSdkVersion defined in manifest

I'm developing an Android application that I'd like to be compatible with 1.5 (SDK version 4). I'm testing the application on 2.2 (SDK version 8). To do this, I'm including in the manifest file the line
<uses-sdk android:minSdkVersion="4" android:targetSdkVersion="8" />
I thought this would allow me to use the newest manifest elements and APIs, but I'm getting a compile error whenever I try to use them. For example, I try to define the element installLocation to allow the app to be installed on the SD card, but Eclipse gives me the error
No resource identifier found for attribute 'installLocation' in package 'android'
Is there something else I have to do to get this to work? If I can't get this to work, what benefit is defining targetSdkVersion?
Make sure that you are using building against the android 2.2 jars. Right click on your Eclipse project, choose, properties, go down to Android and make sure the correct sdk is selected.
Change the build target by editing the project properties in Eclipse, and choose a target with at least API Level 8: ("I'm testing the application on 2.2 (SDK version 8)").

Categories

Resources