Skip to content

Update to Build Xamarin.Android.NUnitLite.dll for API-28 introduces possible breakage for existing XA Unit Test Apps #2189

Closed

Description

@pjcollins

The recent changes to Xamarin.Android.NUnitLite.dll in #2182 could cause new issues for users consuming this assembly if the Target Framework Version of the application referencing this assembly is not high enough.

Steps to Reproduce

  1. Using a recent d15-9 build, attempt to build and deploy an XA unit test application targeting v5.1 or some earlier version in Debug or Release.
  2. I ran into issues when using the d15-9 version of Xamarin.Android.Locale-Tests. Seeing as this project does not explicitly set a TargetFrameworkVersion or AndroidUseLatestPlatformSdk, it will by default compile against MonoAndroid 2.3.
    https://github.com/xamarin/xamarin-android/blob/d15-9/tests/locales/Xamarin.Android.Locale-Tests/Xamarin.Android.Locale-Tests.csproj

Expected Behavior

I am assuming that this breakage is going to be considered acceptable as it has a simple workaround, however we may be able to improve the type of error that could be encountered when an assembly has a higher compile version than the project referencing it. I believe we had talked about wanting to to promote the following warning type to an error[0]. Is that still on the roadmap? This change would help prevent some of the more difficult to diagnose error cases like those described in the 'Actual Behavior' section below.

[0] warning XA0105: The $(TargetFrameworkVersion) for 'Foo' (v9.0) is greater than the $(TargetFrameworkVersion) for your project (v5.0). You need to increase the $(TargetFrameworkVersion) for your project.

Actual Behavior

Now that Xamarin.Android.NUnitLite.dll is compiled with MonoAndroid v9.0, any projects which reference it and target a lower version are susceptible to breakage. Specific examples from the Xamarin.Android.Locale-Tests case mentioned in the 'Steps to Reproduce' section are shown below:

Release (w/ Link SDK)

Build error is produced during linking: http://xqa.blob.core.windows.net/gist/report-390a9ba93fde4b98b0f13dd2fb58c066.txt:

/Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Common.targets(2109,5): error MSB4018: The "LinkAssemblies" task failed unexpectedly. [/Users/xamarinqa/myagent/_work/r1/a/monodroid/external/xamarin-android/tests/locales/Xamarin.Android.Locale-Tests/Xamarin.Android.Locale-Tests.csproj]
/Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Common.targets(2109,5): error MSB4018: Mono.Linker.MarkException: Error processing method: 'System.Void Xamarin.Android.NUnitLite.TestSuiteInstrumentation::OnStart()' in assembly: 'Xamarin.Android.NUnitLite.dll' ---> Mono.Cecil.ResolutionException: Failed to resolve System.Void Android.OS.BaseBundle::PutString(System.String,System.String) [/Users/xamarinqa/myagent/_work/r1/a/monodroid/external/xamarin-android/tests/locales/Xamarin.Android.Locale-Tests/Xamarin.Android.Locale-Tests.csproj]
/Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Common.targets(2109,5): error MSB4018:   at Mono.Linker.Steps.MarkStep.HandleUnresolvedMethod (Mono.Cecil.MethodReference reference) [0x00013] in <89c61745fe494f0489d2df2499b02950>:0  [/Users/xamarinqa/myagent/_work/r1/a/monodroid/external/xamarin-android/tests/locales/Xamarin.Android.Locale-Tests/Xamarin.Android.Locale-Tests.csproj]
/Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Common.targets(2109,5): error MSB4018:   at Mono.Linker.Steps.MarkStep.MarkMethod (Mono.Cecil.MethodReference reference) [0x0004a] in <89c61745fe494f0489d2df2499b02950>:0  [/Users/xamarinqa/myagent/_work/r1/a/monodroid/external/xamarin-android/tests/locales/Xamarin.Android.Locale-Tests/Xamarin.Android.Locale-Tests.csproj]

Debug

Test project crashes at runtime: http://xqa.blob.core.windows.net/gist/report-1c8489f0f2d947e28d9f3d23c33f4410.txt

09-17 15:55:11.019 E/AndroidRuntime(12615): FATAL EXCEPTION: main
09-17 15:55:11.019 E/AndroidRuntime(12615): Process: Xamarin.Android.Locale_Tests, PID: 12615
09-17 15:55:11.019 E/AndroidRuntime(12615): android.runtime.JavaProxyThrowable: System.TypeLoadException: Could not resolve type with token 010000d4 from typeref (expected class 'Android.OS.BaseBundle' in assembly 'Mono.Android, Version=0.0.0.0, Culture=neutral, PublicKeyToken=84e04ff9cfb79065')
09-17 15:55:11.019 E/AndroidRuntime(12615):   at Xamarin.Android.NUnitLite.AndroidRunner.GetSetupTestTarget (Android.Content.Intent intent) [0x00000] in /Users/builder/data/lanes/6102/d2851781/source/monodroid/external/xamarin-android/src/Xamarin.Android.NUnitLite/Gui/AndroidRunner.cs:345 
09-17 15:55:11.019 E/AndroidRuntime(12615):   at Xamarin.Android.NUnitLite.TestSuiteActivity.SetupTestTarget () [0x00008] in /Users/builder/data/lanes/6102/d2851781/source/monodroid/external/xamarin-android/src/Xamarin.Android.NUnitLite/Gui/Activities/TestSuiteActivity.cs:246 
09-17 15:55:11.019 E/AndroidRuntime(12615):   at Xamarin.Android.NUnitLite.TestSuiteActivity.UpdateData (Android.Runtime.JavaList`1[T] data, Android.Widget.ListView lv) [0x00006] in /Users/builder/data/lanes/6102/d2851781/source/monodroid/external/xamarin-android/src/Xamarin.Android.NUnitLite/Gui/Activities/TestSuiteActivity.cs:137 
09-17 15:55:11.019 E/AndroidRuntime(12615):   at Xamarin.Android.NUnitLite.TestSuiteActivity.OnCreate (Android.OS.Bundle bundle) [0x0003b] in /Users/builder/data/lanes/6102/d2851781/source/monodroid/external/xamarin-android/src/Xamarin.Android.NUnitLite/Gui/Activities/TestSuiteActivity.cs:49 
09-17 15:55:11.019 E/AndroidRuntime(12615):   at Xamarin.Android.LocaleTests.MainActivity.OnCreate (Android.OS.Bundle bundle) [0x0000d] in C:\Users\peter\source\monodroid\external\xamarin-android\tests\locales\Xamarin.Android.Locale-Tests\MainActivity.cs:19 

Version Information

XA 9.1.0.28

Activity

  1. added
    Area: App+Library Build
    on Sep 17, 2018
  2. jonpryor commented on Sep 17, 2018

    @jonpryor
    Contributor

    I was wondering what the ramifications would be, and couldn't remember.

    Thank you for your test suite!

    I think this is acceptable for d15-9 P3. It won't be acceptable for P4 or stable.


    "The fix" will be to revert the changes to BuildEverything.mk, but this just re-introduces the issue we were trying to fix.

    I see two plausible fixes:

    1. Call Context.GetExternalFilesDir() via JNI. This allows us to continue building Xamarin.Android.NUnitLite.dll against API-10 while using the API-19 method -- when running on API-19+ -- and should allow the issue to be fixed.
    2. "Otherwise construct" what Context.GetExteralFilesDir() returns (which will likely bite us later).
    3. Use a different directory, e.g. /data/local/tmp.

    (2) is brittle, (3) leaves cleanup issues -- the TestResults.xml files will still remain after the app has been uninstalled -- which leaves (1) as "most useful" solution.

    @grendello: Any other ideas?

  3. ghost locked as resolved and limited conversation to collaborators on Jun 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Area: App+Library Build

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions