Open gerardvanderkruijs opened 2 weeks ago
@ChrisPulman Do you perhaps have any clue about this? You fixed the same issue in #3714, so maybe your magic can solve this issue too π
Hi @gerardvanderkruijs I will try to take a look this weekend, unfortunately I am away until Friday evening so don't think I'll get much time until then.
Hi @ChrisPulman , no worries thatβs perfect! Thank you so much π
@gerardvanderkruijs Just wondering if there is a specific requirement to use V19.6.12
@gerardvanderkruijs I did some research and as we are using reflection within ReactiveUI using linkers with AOT Compilation will not work as desired, the _Microsoft.Android.Resource.Designer.dll gets stripped of its code by being trimmed. I will see if I can find a way to do the same thing without using reflection. It seems that the _Microsoft.Android.Resource.Designer library may also not AOT friendly so may need to see what can be done about that first.
If the legacy AndroidLinkMode
setting is used, both SdkOnly
and Full
will default to equivalent linker settings:
<PublishTrimmed>true</PublishTrimmed>
<TrimMode>link</TrimMode>
With AndroidLinkMode
=SdkOnly
only BCL and SDK assemblies marked with %(Trimmable)
will be linked at the member level. AndroidLinkMode
=Full
will set %(TrimMode)
=link
on all .NET assemblies similar to the example in the trimming documentation.
It is recommended to migrate to the new linker settings, as AndroidLinkMode
will eventually be deprecated.
For the time being in your project I would set the following:
<IsTrimmable>True</IsTrimmable>
<TrimMode>link</TrimMode>
<PublishTrimmed>false</PublishTrimmed> // will remove the resources if true
<RunAOTCompilation>false</RunAOTCompilation> // will remove the resources if true
Then set the following:
[DynamicDependency(DynamicallyAccessedMemberTypes.All, "ResourceConstant", "_Microsoft.Android.Resource.Designer")]
protected override void OnCreate(Bundle? savedInstanceState)
Further Documentation can be found here Linking with .NET Android
Trimming incompatibilities Some further pointers to why Trimming can fail
Hi @ChrisPulman ,
Thanks for the super clear explanation and for the (temp) solution! I've been playing around this morning and everything seems to be working alright again now π
The reason we're still using 19.6.12
is because 20.x.x
results in another error in our Android project.
Of course this is not the thread for it, but it throws the following exception:
System.MethodAccessException: Method `ReactiveUI.ControlFetcherMixin.GetWireUpMembers(object,ReactiveUI.ControlFetcherMixin/ResolveStrategy)' is inaccessible from method `ReactiveUI.AndroidX.ControlFetcherMixin.WireUpControls(AndroidX.Fragment.App.Fragment,Android.Views.View,ReactiveUI.ControlFetcherMixin/ResolveStrategy)'
at ReactiveUI.AndroidX.ControlFetcherMixin.WireUpControls(Fragment fragment, View inflatedView, ResolveStrategy resolveMembers) in /_/src/ReactiveUI.AndroidX/ControlFetcherMixin.cs:line 35
at ***.OnViewCreated(View view, Bundle savedInstanceState) in ***.cs:line 84
at AndroidX.Fragment.App.Fragment.n_OnViewCreated_Landroid_view_View_Landroid_os_Bundle_(IntPtr jnienv, IntPtr native__this, IntPtr native_view, IntPtr native_savedInstanceState) in C:\a\_work\2\s\generated\androidx.fragment.fragment\obj\Release\net7.0-android\generated\src\AndroidX.Fragment.App.Fragment.cs:line 2742
at Android.Runtime.JNINativeWrapper.Wrap_JniMarshal_PPLL_V(_JniMarshal_PPLL_V callback, IntPtr jnienv, IntPtr klazz, IntPtr p0, IntPtr p1) in /Users/runner/work/1/s/xamarin-android/src/Mono.Android/Android.Runtime/JNINativeWrapper.g.cs:line 198
Also, there is no 20.x.x
version of the ReactiveUI.AndroidX
package, the last version is 19.6.12
, I assume we still need this package to wire up our controls in our .NET Android project?
ReactiveUI.AndroidX was aimed at pre net6.0 targeted versions of Android, as far as I am aware you should be able to achieve the same with just the ReactiveUI base package. I will certainly check again though.
Ah okay! Good to know.
When I remove the ReactiveUI.AndroidX
package there's a lot of errors, which is not necessarily a big issue if I would be able to fix them.
For example, where did the class ReactiveRecyclerViewViewHolder
go? Or ReactiveRecyclerViewAdapter
, ReactiveAppCompatActivity
and so on.
Describe the bug π
When calling
ReactiveUI.ControlFetcherMixin.WireUpControls()
in a .NET 8 Android app (net8.0-android
) in non-debug configuration, even though the correct resource ID is specified, aMissingFieldException
is thrown.This issue was fixed with bug report #3714 , but only for
Debug
builds by the looks of it. When deployingRelease
builds the exception is still present. I narrowed it down to one specific .csproj property, that is this one:When I change this to
<AndroidLinkMode>None</AndroidLinkMode>
it all works perfectly.Stracktrace:
project .csproj file
Step to reproduce
8.0.302
)net8.0-android
project usingdotnet new android
command.ReactiveUI
version19.6.12
MainActivity.cs
and change it so thatMainActivity
inheritsReactiveUI.ReactiveActivity
android:id
) to theTextView
inactivity_main.xml
and add a member toMainActivity.cs
to wire it up.WireUpControls()
afterSetContentView()
inOnCreate()
.Release
configurationMissingFieldException
is thrown fromWireUpControls()
.AndroidLinkMode
toSdkOnly
in theDebug
config, this will result in same exception.Reproduction repository
https://github.com/gerardvanderkruijs/ReactiveUI-WireUpControls-Issue
Expected behavior
After launching the application In
Release
configuration, theTextView
should be wired up correctly, and the initial screen should be displayed.AndroidLinkMode
set toSdkOnly
should not throw aMissingFieldException
.Screenshots πΌοΈ
No response
IDE
Rider macOS
Operating system
Android
Version
13
Device
Emulator
ReactiveUI Version
19.6.12
Additional information βΉοΈ
Since this report is almost identical to #3714 I mainly used all the info and sample project provided by @tommy10344, so thank you for that :-)