dotnet / maui

.NET MAUI is the .NET Multi-platform App UI, a framework for building native device applications spanning mobile, tablet, and desktop.
https://dot.net/maui
MIT License
22.28k stars 1.76k forks source link

[Bug] IntentFilter WebAuthenticator - Resources+NotFoundException appIcon #2902

Closed auriou closed 2 years ago

auriou commented 3 years ago

Description

I use Microsoft Visual Studio Enterprise 2022 Preview (64 bits) Version 17.0.0 Preview 4.1 6.0.100-rc.1.21463.6 - C:\Program Files\dotnet\sdk\6.0.100-rc.1.21463.6

Here is the error :

Android.Content.Res.Resources+NotFoundException Message=Drawable com.myproject:mipmap/appicon with resource ID #0x7f0c0000

image

auriou commented 3 years ago

here is an example which reproduces the error : https://github.com/auriou/MauiWebAuthenticator

auriou commented 3 years ago

this error seems to be already produced on Xamarin : https://github.com/xamarin/Xamarin.Forms/issues/13843 https://github.com/xamarin/Xamarin.Forms/issues/14317

dhabierre commented 3 years ago

Hi,

I've the same issue. I'm playing with the .NET MAUI app sample.

First, in the OnCounterClicked method, I've wrote:

private async void OnCounterClicked(object sender, EventArgs e)
{
    var selected = await FilePicker.PickAsync(new PickOptions { PickerTitle = "Select the ZIP file" });
    if (selected != null)
    {
      // TODO
    }
}

Then I've added in Platforms\Android\AndroidManifest.xml:

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

Error:

System.NullReferenceException: 'The current Activity can not be detected. Ensure that you have called Init in your Activity or Application class.'

This seems to fix it (Platforms\Android\MainActivity.cs):

[Activity(...)]
public class MainActivity : MauiAppCompatActivity
{
    protected override void OnCreate(Bundle savedInstanceState)
    {
        base.OnCreate(savedInstanceState);

        Platform.Init(this, savedInstanceState);
    }
}

Next execution:

Android.Content.Res.Resources+NotFoundException: 'Drawable com.companyname.Vaultage:mipmap/appicon_round with resource ID #0x7f0c0001'

Finally I've tried this:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
  <uses-sdk android:minSdkVersion="21" android:targetSdkVersion="31" />

  <!--Android.Content.Res.Resources+NotFoundException: Message=Drawable com.companyname.Vaultage:mipmap/appicon_round with resource ID #0x7f0c0001-->
  <!--<application android:allowBackup="true" android:icon="@mipmap/appicon" android:roundIcon="@mipmap/appicon_round" android:supportsRtl="true"></application>-->
  <application android:allowBackup="true" android:supportsRtl="true"></application>

  <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
  <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
</manifest>

Hope it helps.

dhabierre commented 3 years ago

here is an example which reproduces the error : https://github.com/auriou/MauiWebAuthenticator

Ho great! I'd like to play with WebAuthenticator too :) But the project does not build on my computer:

Error   XA0003  VersionCode 1.0 is invalid. It must be an integer value.

To fix it I have to build the csproj:

<ApplicationVersion>1.0</ApplicationVersion>

=>

<ApplicationVersion>1</ApplicationVersion>

The rebuild. It will update android:versionCode:

<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.companyname.MauiWebAuthenticator" android:versionCode="1.0" android:versionName="1.0.0">

=>

<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.companyname.MauiWebAuthenticator" android:versionCode="1" android:versionName="1.0.0">
auriou commented 3 years ago

Finally I've tried this:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
  <uses-sdk android:minSdkVersion="21" android:targetSdkVersion="31" />

  <!--Android.Content.Res.Resources+NotFoundException: Message=Drawable com.companyname.Vaultage:mipmap/appicon_round with resource ID #0x7f0c0001-->
  <!--<application android:allowBackup="true" android:icon="@mipmap/appicon" android:roundIcon="@mipmap/appicon_round" android:supportsRtl="true"></application>-->
  <application android:allowBackup="true" android:supportsRtl="true"></application>

  <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
  <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
</manifest>

Hope it helps.

This is perfect it works by removing the attributes "android: icon" and "android: roundIcon"

Thank you

shimingsg commented 2 years ago

Glad to see you get project working and close this issue.

thomiel commented 2 years ago

Does everyone who wants web authentication really need to run into this issue? I think you prematurely closed this. Either the maui project template or the Maui.Essentials Samples need to be fixed.