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

Android Unit Test on Device F# crash: Resources NotFoundException #4456

Closed
nosami opened this Issue Apr 5, 2018 · 3 comments

Comments

Projects
None yet
2 participants
@nosami
Member

nosami commented Apr 5, 2018

Originally reported here

Steps to Reproduce

  1. Create an Android Unit Test project with F#
  2. Build and run on device

Expected Behavior

The Unit tests will run on the device

Actual Behavior

--- End of managed Android.Content.Res.Resources+NotFoundException stack trace ---
android.content.res.Resources$NotFoundException: Resource ID #0x7f020003
at android.content.res.Resources.getValue(Resources.java:2485)
at android.content.res.Resources.loadXmlResourceParser(Resources.java:4217)
at android.content.res.Resources.getLayout(Resources.java:2301)
at android.view.LayoutInflater.inflate(LayoutInflater.java:413)
at android.view.LayoutInflater.inflate(LayoutInflater.java:366)
at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:450)
at android.app.Activity.setContentView(Activity.java:2399)
at md54f7330f059cfdce8608ce9cc3a0da7e3.MainActivity.n_onCreate(Native Method)
at md54f7330f059cfdce8608ce9cc3a0da7e3.MainActivity.onCreate(MainActivity.java:29)
at android.app.Activity.performCreate(Activity.java:6608)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1134)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3086)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3243)
at android.app.ActivityThread.access$1000(ActivityThread.java:218)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1718)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:6917)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1404)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1199)

Version Information

=== Visual Studio Professional 2017 for Mac ===

Version 7.4.2 (build 12)
Installation UUID: 69cc42aa-2bc3-49e3-929b-43eb3dfdb0eb
Runtime:
Mono 5.8.1.0 (2017-10/6bf3922f3fd) (64-bit)
GTK+ 2.24.23 (Raleigh theme)

Package version: 508010000

=== NuGet ===

Version: 4.3.1.4445

=== .NET Core ===

Runtime: /usr/local/share/dotnet/dotnet
Runtime Versions:
2.0.5
2.0.0
1.1.2
1.1.1
1.1.0
1.0.5
1.0.4
SDK: /usr/local/share/dotnet/sdk/2.1.4/Sdks
SDK Versions:
2.1.4
2.0.0
1.0.4
1.0.1
1.0.0-preview2-1-003177
MSBuild SDKs: /Library/Frameworks/Mono.framework/Versions/5.8.1/lib/mono/msbuild/15.0/bin/Sdks

=== Xamarin.Profiler ===

Version: 1.6.1
Location: /Applications/Xamarin Profiler.app/Contents/MacOS/Xamarin Profiler

=== Apple Developer Tools ===

Xcode 9.2 (13772)
Build 9C40b

=== Xamarin.Mac ===

Version: 4.2.1.28 (Visual Studio Professional)

=== Xamarin.Android ===

Version: 8.2.0.16 (Visual Studio Professional)
Android SDK: /Users/sam.williams/Library/Developer/Xamarin/android-sdk-macosx
Supported Android versions:
2.3 (API level 10)
5.0 (API level 21)
6.0 (API level 23)
7.0 (API level 24)
7.1 (API level 25)
8.0 (API level 26)
8.1 (API level 27)

SDK Tools Version: 25.2.5
SDK Platform Tools Version: 25.0.5
SDK Build Tools Version: 25.0.3

Java SDK: /usr
java version "1.8.0_151"
Java(TM) SE Runtime Environment (build 1.8.0_151-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.151-b12, mixed mode)

Android Designer EPL code available here:
https://github.com/xamarin/AndroidDesigner.EPL

=== Xamarin.iOS ===

Version: 11.9.1.24 (Visual Studio Professional)
Hash: f62de472
Branch: xcode9.3
Build date: 2018-03-29 19:30:53-0400

=== Xamarin Inspector ===

Version: 1.4.0
Hash: b3f92f9
Branch: master
Build date: Fri, 19 Jan 2018 22:00:34 GMT
Client compatibility: 1

=== Build Information ===

Release ID: 704020012
Git revision: 0d8e3f0
Build date: 2018-03-30 10:45:17-04
Xamarin addins: 958839ea56ab1e331caf7c92b6ad50fb9e6ee9d2
Build lane: monodevelop-lion-d15-6

=== Operating System ===

Mac OS X 10.13.3
Darwin 17.4.0 Darwin Kernel Version 17.4.0
Sun Dec 17 09:19:54 PST 2017
root:xnu-4570.41.2~1/RELEASE_X86_64 x86_64

=== Enabled user installed addins ===

MvvmCross Template pack 2.0.1
Paket 0.3
xUnit.NET 2 testing framework support 0.7.5
Redth's Addins 1.0.9
Straight8's SpecFlow Integration 1.11.1.0
SpecFlow Support 1.10.0.0
Internet of Things (IoT) development (Preview) 7.1

Log File

Intentionally left blank, as the bug is reliably reproducible for me, and I don't think device logs will help in the fix.

If they are required, I can update.

VS bug #595215

@nosami nosami self-assigned this Apr 5, 2018

nosami added a commit to xamarin/Xamarin.Android.FSharp.ResourceProvider that referenced this issue Apr 6, 2018

Revert the usage of the TP SDK. We need real C# types...
...to be embedded into the F# assembly - not mirrored types

Re xamarin/xamarin-android#1513
and mono/monodevelop#4456

Bump to 1.0.0.22

We also need code such as the following adding to the NUnit template and
possibly others.

```fs
namespace fsandroidnunit
// the name of the type here needs to match the name inside the ResourceDesigner attribute
type Resources = fsandroidnunit.Resource
[<assembly: Android.Runtime.ResourceDesigner("fsandroidnunit.Resources", IsApplication=true)>]
()
```
@nosami

This comment has been minimized.

Member

nosami commented Apr 6, 2018

Good news is that I have this working now without copying any assemblies around - the C# types are embedded into the F# assembly.

image

I broke the type provider inadvertently when I switched to using the Type Provider SDK. I didn't realise that it was creating a 'metadata only' view of the assembly - it contained all the field values but not the runtime code. This was fine for single assembly applications but not applications that referenced other Android libraries. The type provider fix will be in v 1.0.0.22

I also noticed another issue that must have always been there - the assembly level attribute contained inside the C# code was never applied to the resulting F# assembly. It's going to be necessary to add this into the template somewhere.

namespace fsandroidnunit
// the name of the type here needs to match the name inside the ResourceDesigner attribute
type Resources = fsandroidnunit.Resource
[<assembly: Android.Runtime.ResourceDesigner("fsandroidnunit.Resources", IsApplication=true)>]
()

@nosami nosami added this to the 15.7 milestone Apr 8, 2018

@nosami nosami closed this Apr 9, 2018

@xamarin-release-manager

This comment has been minimized.

Contributor

xamarin-release-manager commented Apr 10, 2018

Fixed in version 7.6.0.448 (master)

Pull Request #3063 merged by: Jason Imison
Author: xamarin
Commit: c226faf8e20cb7cf42f2a2829d4a9232d0331d36 (xamarin/md-addins)
Included in Commit: 6911820 (mono/monodevelop)

@xamarin-release-manager

This comment has been minimized.

Contributor

xamarin-release-manager commented Apr 10, 2018

Fixed in version 7.5.0.1117 (d15-7)

Author: nosami
Commit: 547617d5ee51d1679339e9995ffa3cc2bb3c285e (xamarin/md-addins)
Included in Commit: 6b0b6ea (mono/monodevelop)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment