Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make $(AndroidLinkResources) able to be the default for MAUI projects #7194

Closed
jonathanpeppers opened this issue Jul 21, 2022 · 3 comments · Fixed by #7306
Closed

Make $(AndroidLinkResources) able to be the default for MAUI projects #7194

jonathanpeppers opened this issue Jul 21, 2022 · 3 comments · Fixed by #7306
Assignees
Labels
Area: App+Library Build Issues when building Library projects or Application projects. enhancement Proposed change to current functionality.

Comments

@jonathanpeppers
Copy link
Member

Android application type

Android for .NET (net6.0-android, etc.)

Affected platform version

.NET 7

Description

Context: dotnet/maui#7038

We found some Telerik and/or other vendor libraries would fail due to this code in SkiaSharp:

https://github.com/mono/SkiaSharp/blob/4a687a87b86f127ccc23116ee410dcb5df8fca63/source/SkiaSharp.Views/SkiaSharp.Views.Android/SKCanvasView.cs#L48-L61

So if we don't finish #6427 for .NET 7, we could consider:

  1. Fix SKCanvasView so it doesn't use a Styleable int[].
  2. Give an error message at build time if the AndroidLinkResources linker step encounters a int[]
  3. Try turning on AndroidLinkResources=true by default for MAUI projects

Steps to Reproduce

  1. Use SKCanvasView in a project
  2. Build with -c Release -p:AndroidLinkResources=true

Did you find any workaround?

Don't use $(AndroidLinkResources)

Relevant log output

No response

@jonathanpeppers jonathanpeppers added the Area: App+Library Build Issues when building Library projects or Application projects. label Jul 21, 2022
@jonathanpeppers jonathanpeppers added this to the .NET 7 milestone Jul 21, 2022
@tipa
Copy link

tipa commented Aug 10, 2022

I was hitting the same problem today (not using a 3rd party library) when subclassing a View and using ObtainStyledAttributes.
Attached a simple repo project: AndroidApp2.zip

Would appreciate if a fix could be found

@jonathanpeppers
Copy link
Member Author

@tipa can you share the error message you got? Probably a crash at runtime?

@tipa
Copy link

tipa commented Aug 10, 2022

With the demo project attached I first get this exception (only when enabling all exceptions in the VS Exception Settings Window):
System.BadImageFormatException: 'Could not resolve field token 0x0400000b'

When I then click "Continue" in the debugger I get this exception:
System.NotSupportedException: 'Could not activate JNI Handle 0x7fe1003920 (key_handle 0x73cc609) of Java type 'crc641149b9fe658fbe8e/MyView' as managed type 'AndroidApp2.MyView'.'

They are crashes at runtime, yes

@jpobst jpobst added the enhancement Proposed change to current functionality. label Sep 6, 2022
jonpryor pushed a commit that referenced this issue Sep 13, 2022
)

Fixes: #7194

Context: dotnet/maui#7038

The initial version of `$(AndroidLinkResources)` (9e6ce03) was too
broad in its removal of Resource classes and fields.  Certain fields
such as `Styleable` arrays were not called using the IL `stsfld`
opcode.  As a result they could not be easily replaced with constant
usage.

However, the linker removed *all* the fields from the `Resource` 
nested types.  This would result in the following error at runtime:

	System.BadImageFormatException: 'Could not resolve field token 0x0400000b'

This was because the `int[]` fields were removed as part of the
linking process. 

Fix this by leaving the `int[]` fields in the `Resource` nested types
instead of removing them.

We can still remove all the other `int` fields.

We now also need to fix up the `Resource` nested type constructors
to replace the `int` field access with the constant values like we do
for the rest of the app.   This was not required previously because
these constructors were removed, but now we have to keep them because
the static array initialization takes place in these constructors.
@ghost ghost locked as resolved and limited conversation to collaborators Oct 14, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Area: App+Library Build Issues when building Library projects or Application projects. enhancement Proposed change to current functionality.
Projects
Development

Successfully merging a pull request may close this issue.

4 participants