Maui for Android OCR project Using latest maui and android versions

Haviv Elbsz 2,071 Reputation points
2024-07-02T10:46:36.0166667+00:00

Hello All.

I created new maui project based on an Ocr for Android

example. And it start build ok but after a while it throw

this error. Please any help to fix this. Thank you.

Build Error

===========

Severity Code Description Project File Line Suppression State

Error (active) Precompiling failed for C:\GitHub\MyOcr\MyOcr\obj\Release\net8.0-android\android-arm64\linked\IronOcr.dll with exit code -1073741819.

Mono Ahead of Time compiler - compiling assembly C:\GitHub\MyOcr\MyOcr\obj\Release\net8.0-android\android-arm64\linked\IronOcr.dll

AOTID B4C955CF-7491-E197-2787-A371D120EF7B

Using profile data file 'C:\Users\haviv.nuget\packages\microsoft.maui.controls.build.tasks\8.0.40\buildTransitive\netstandard2.0\maui.aotprofile'

Using profile data file 'C:\Users\haviv.nuget\packages\microsoft.maui.controls.build.tasks\8.0.40\buildTransitive\netstandard2.0\maui-blazor.aotprofile'

Could not load signature of Azure.<e8b4f7ea-6ebf-426d-a24f-4362bcc9815f>AzureCoreExtensions:ToObject due to: Could not load file or assembly

'System.Memory.Data, Version=1.0.2.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' or one of its dependencies.

MyOcr (net8.0-android) C:\Program Files\dotnet\packs\Microsoft.Android.Sdk.Windows\34.0.113\targets\Microsoft.Android.Sdk.Aot.targets 109

              ================ MyOcr PROJECT =================

MainPage.xaml.cs

================

using IronOcr;

namespace MyOcr

{

public partial class MainPage : ContentPage

{

    // Initialize IronTesseract once in a class

    private IronTesseract ocrTesseract = new IronTesseract();

    public MainPage()

    {

        InitializeComponent();

        // Apply License key

        IronOcr.License.LicenseKey = "IRONOCR.MYLICENSE.KEY.1EF01";

    }

    private async void ReadFileOnImport(object sender, EventArgs e)

    {

        try

        {

            var options = new PickOptions

            {

                PickerTitle = "Please select a file"

            };

            var result = await FilePicker.PickAsync(options);

            if (result != null)

            {

                using var stream = await result.OpenReadAsync();

                // Instantiate OcrInput

                using var ocrInput = new OcrInput();

                // Load image stream

                ocrInput.LoadImage(stream);

                // Perform OCR

                var ocrResult = ocrTesseract.Read(ocrInput);

                OutputText.Text = ocrResult.Text;

            }

        }

        catch (Exception ex)

        {

            // Handle exceptions

            System.Diagnostics.Debug.WriteLine(ex);

        }

    }

}

}

MainPage.xaml

=============

<?xml version="1.0" encoding="utf-8" ?>

<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"

         xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"

         x:Class="MyOcr.MainPage">

<Grid>

    <Grid.RowDefinitions>

        <RowDefinition Height="Auto"/>

        <RowDefinition Height="*"/>

    </Grid.RowDefinitions>

    <Button

    Text="Import File"

    Clicked="ReadFileOnImport"

    Grid.Row="0"

    HorizontalOptions="Center"

    Margin="20, 20, 20, 10"/>

    <ScrollView

    Grid.Row="1"

    BackgroundColor="LightGray"

    Padding="10"

    Margin="10, 10, 10, 30">

        <Label x:Name="OutputText"/>

    </ScrollView>

</Grid>

</ContentPage>

MyOcr.csproj

============

<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>

	<TargetFrameworks>net8.0-android</TargetFrameworks>

            <!-- <TargetFrameworks>net8.0-ios;net8.0-maccatalyst</TargetFrameworks> -->

	<!-- <TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('windows'))">$(TargetFrameworks);net8.0-windows10.0.19041.0</TargetFrameworks> --> 

	<!-- Uncomment to also build the tizen app. You will need to install tizen by following this: https://github.com/Samsung/Tizen.NET -->

	<!-- <TargetFrameworks>$(TargetFrameworks);net8.0-tizen</TargetFrameworks> -->

	<!-- Note for MacCatalyst:

	The default runtime is maccatalyst-x64, except in Release config, in which case the default is maccatalyst-x64;maccatalyst-arm64.

	When specifying both architectures, use the plural <RuntimeIdentifiers> instead of the singular <RuntimeIdentifier>.

	The Mac App Store will NOT accept apps with ONLY maccatalyst-arm64 indicated;

	either BOTH runtimes must be indicated or ONLY macatalyst-x64. -->

	<!-- For example: <RuntimeIdentifiers>maccatalyst-x64;maccatalyst-arm64</RuntimeIdentifiers> -->

	<OutputType>Exe</OutputType>

	<RootNamespace>MyOcr</RootNamespace>

	<UseMaui>true</UseMaui>

	<SingleProject>true</SingleProject>

	<ImplicitUsings>enable</ImplicitUsings>

	<Nullable>enable</Nullable>

	<!-- Display name -->

	<ApplicationTitle>MyOcr</ApplicationTitle>

	<!-- App Identifier -->

	<ApplicationId>com.companyname.myocr</ApplicationId>

	<!-- Versions -->

	<ApplicationDisplayVersion>1.0</ApplicationDisplayVersion>

	<ApplicationVersion>1</ApplicationVersion>

	<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'ios'">11.0</SupportedOSPlatformVersion>

	<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'maccatalyst'">13.1</SupportedOSPlatformVersion>

	<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'android'">21.0</SupportedOSPlatformVersion>

	<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'">10.0.17763.0</SupportedOSPlatformVersion>

	<TargetPlatformMinVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'">10.0.17763.0</TargetPlatformMinVersion>

	<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'tizen'">6.5</SupportedOSPlatformVersion>

</PropertyGroup>

<ItemGroup>

	<!-- App Icon -->

	<MauiIcon Include="Resources\AppIcon\appicon.svg" ForegroundFile="Resources\AppIcon\appiconfg.svg" Color="#512BD4" />

	<!-- Splash Screen -->

	<MauiSplashScreen Include="Resources\Splash\splash.svg" Color="#512BD4" BaseSize="128,128" />

	<!-- Images -->

	<MauiImage Include="Resources\Images\*" />

	<MauiImage Update="Resources\Images\dotnet_bot.png" Resize="True" BaseSize="300,185" />

	<!-- Custom Fonts -->

	<MauiFont Include="Resources\Fonts\*" />

	<!-- Raw Assets (also remove the "Resources\Raw" prefix) -->

	<MauiAsset Include="Resources\Raw\**" LogicalName="%(RecursiveDir)%(Filename)%(Extension)" />

</ItemGroup>

<ItemGroup>

	<PackageReference Include="IronOcr.Android" Version="2024.6.3" />

	<PackageReference Include="Microsoft.Maui.Controls" Version="$(MauiVersion)" />

	<PackageReference Include="Microsoft.Maui.Controls.Compatibility" Version="$(MauiVersion)" />

	<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="8.0.0" />

</ItemGroup>

<ItemGroup>

	<PackageReference Include="IronOcr.Android" Version="2024.6.3" />

	<!-- <PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="7.0.0" /> -->

</ItemGroup>

</Project>

.NET MAUI
.NET MAUI
A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
3,607 questions
0 comments No comments
{count} votes

Accepted answer
  1. Yonglun Liu (Shanghai Wicresoft Co,.Ltd.) 44,171 Reputation points Microsoft Vendor
    2024-07-03T06:04:17.2433333+00:00

    Hello,

    Issues due to third-party controls are not currently supported on Microsoft Q&A. Therefore, it is more recommended that you send this back to the plugin's official repository or forum for support.

    Best Regards,

    Alec Liu.


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.