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

Android.Content.Res.Resources+NotFoundException when using an external library #3342

Closed
jschmid opened this issue Jul 10, 2019 · 13 comments
Closed
Assignees
Labels
need-info Issues that need more information from the author.

Comments

@jschmid
Copy link

jschmid commented Jul 10, 2019

When running our project with Xamarin.Android 9.3.0.23, the app crashes with a Android.Content.Res.Resources+NotFoundException as soon as we try to use a resource that is bundled by an external library.

At first, I though this was caused by the library itself that was not correctly bundled, but then realized that it failed with any external library. This happens for example with Acr.UserDialogs or Plugin.Fingerprint.

Steps to Reproduce

Unfortunately, I do not have a working (crashing) example. I tried to make a repro project, but it works as expected.

Expected Behavior

Xamarin.Forms app can use resources from external libraries.

Actual Behavior

Android.Content.Res.Resources+NotFoundException: Resource ID #0x7f03005a
  at Java.Interop.JniEnvironment+InstanceMethods.CallNonvirtualObjectMethod (Java.Interop.JniObjectReference instance, Java.Interop.JniObjectReference type, Java.Interop.JniMethodInfo method, Java.Interop.JniArgumentValue* args) [0x00089] in <3beddfcb1eb547cd8ce47c3097f6eaeb>:0
  at Java.Interop.JniPeerMembers+JniInstanceMethods.InvokeVirtualObjectMethod (System.String encodedMember, Java.Interop.IJavaPeerable self, Java.Interop.JniArgumentValue* parameters) [0x0005d] in <3beddfcb1eb547cd8ce47c3097f6eaeb>:0
  at Android.Views.LayoutInflater.Inflate (System.Int32 resource, Android.Views.ViewGroup root, System.Boolean attachToRoot) [0x0005a] in <ff9f3f3d4e134974a889db1b532c9b6e>:0
  at MvvmCross.Platforms.Android.Binding.Views.MvxLayoutInflater.Inflate (System.Int32 resource, Android.Views.ViewGroup root, System.Boolean attachToRoot) [0x0003e] in C:\projects\mvvmcross\MvvmCross\Platforms\Android\Binding\Views\MvxLayoutInflater.cs:141
  at Android.Views.LayoutInflater.n_Inflate_ILandroid_view_ViewGroup_Z (System.IntPtr jnienv, System.IntPtr native__this, System.Int32 resource, System.IntPtr native_root, System.Boolean attachToRoot) [0x00011] in <ff9f3f3d4e134974a889db1b532c9b6e>:0
  at at (wrapper dynamic-method) Android.Runtime.DynamicMethodNameCounter.27(intptr,intptr,int,intptr,bool)
  at android.content.res.Resources$NotFoundException: Resource ID #0x7f03005a
  at at android.content.res.ResourcesImpl.getValue(ResourcesImpl.java:216)
  at at android.content.res.Resources.loadXmlResourceParser(Resources.java:2155)
  at at android.content.res.Resources.getLayout(Resources.java:1155)
  at at android.view.LayoutInflater.inflate(LayoutInflater.java:421)
  at at mvvmcross.platforms.android.binding.views.MvxLayoutInflater.n_inflate(Native Method)
  at at mvvmcross.platforms.android.binding.views.MvxLayoutInflater.inflate(MvxLayoutInflater.java:50)
  at at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
  at at android.support.v7.app.AlertDialog_IDialogInterfaceOnClickListenerImplementor.n_onClick(Native Method)
  at at android.support.v7.app.AlertDialog_IDialogInterfaceOnClickListenerImplementor.onClick(AlertDialog_IDialogInterfaceOnClickListenerImplementor.java:30)
  at at android.support.v7.app.AlertController$ButtonHandler.handleMessage(AlertController.java:167)
  at at android.os.Handler.dispatchMessage(Handler.java:106)
  at at android.os.Looper.loop(Looper.java:193)
  at at android.app.ActivityThread.main(ActivityThread.java:6718)
  at at java.lang.reflect.Method.invoke(Native Method)
  at at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
  at at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)

Version Information

From Visual Studio for Mac === Visual Studio Community 2019 for Mac ===

Version 8.1.5 (build 9)
Installation UUID: c647d718-5745-4cd4-a94d-56ba562963eb
GTK+ 2.24.23 (Raleigh theme)
Xamarin.Mac 5.6.0.25 (d16-0 / 50f75273)

Package version: 518010028

=== Mono Framework MDK ===

Runtime:
Mono 5.18.1.28 (2018-08/223ea7ef92e) (64-bit)
Package version: 518010028

=== NuGet ===

Version: 5.0.2.5988

=== .NET Core ===

Runtime: /usr/local/share/dotnet/dotnet
Runtime Versions:
2.2.5
2.1.8
2.1.2
2.0.5
2.0.0
SDK: /usr/local/share/dotnet/sdk/2.2.300/Sdks
SDK Versions:
2.2.300
2.2.107
2.1.504
2.1.302
2.1.4
2.0.0
MSBuild SDKs: /Library/Frameworks/Mono.framework/Versions/5.18.1/lib/mono/msbuild/Current/bin/Sdks

=== Xamarin.Profiler ===

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

=== Updater ===

Version: 11

=== Xamarin.Android ===

Version: 9.3.0.23 (Visual Studio Community)
Commit: HEAD/d0b48056f
Android SDK: /Users/jonas/Library/Android/sdk
Supported Android versions:
4.4 (API level 19)
5.0 (API level 21)
5.1 (API level 22)
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: 26.1.1
SDK Platform Tools Version: 29.0.1
SDK Build Tools Version: 29.0.0 rc1

Build Information:
Mono: mono/mono@3a07bd426d3
Java.Interop: xamarin/java.interop/d16-1@5ddc3e3
LibZipSharp: grendello/LibZipSharp/d16-1@44de300
LibZip: nih-at/libzip@b95cf3f
ProGuard: xamarin/proguard@905836d
SQLite: xamarin/sqlite@8212a2d
Xamarin.Android Tools: xamarin/xamarin-android-tools/d16-1@acabd26

=== Microsoft Mobile OpenJDK ===

Java SDK: /Users/jonas/Library/Developer/Xamarin/jdk/microsoft_dist_openjdk_1.8.0.25
1.8.0-25
Android Designer EPL code available here:
https://github.com/xamarin/AndroidDesigner.EPL

=== Android Device Manager ===

Version: 1.2.0.44
Hash: aac645b
Branch: remotes/origin/d16-1
Build date: 2019-05-29 19:55:24 UTC

=== Xamarin Designer ===

Version: 16.1.0.467
Hash: f1657e133
Branch: remotes/origin/d16-1-new-document-model
Build date: 2019-06-18 21:57:42 UTC

=== Apple Developer Tools ===

Xcode 10.2 (14490.120)
Build 10E125

=== Xamarin.Mac ===

Xamarin.Mac not installed. Can't find /Library/Frameworks/Xamarin.Mac.framework/Versions/Current/Version.

=== Xamarin.iOS ===

Version: 12.10.0.157 (Visual Studio Community)
Hash: 6bd94753
Branch: d16-1
Build date: 2019-06-12 17:28:47-0400

=== Xamarin Inspector ===

Version: 1.4.3
Hash: db27525
Branch: 1.4-release
Build date: Mon, 09 Jul 2018 21:20:18 GMT
Client compatibility: 1

=== Build Information ===

Release ID: 801050009
Git revision: bd0ab28ba941b19b39322247db020dcd0fb305d0
Build date: 2019-07-03 17:15:21+00
Build branch: release-8.1
Xamarin extensions: 8cc25b5cb090e6c23b62a7901000c299977eb08d

=== Operating System ===

Mac OS X 10.14.5
Darwin 18.6.0 Darwin Kernel Version 18.6.0
Thu Apr 25 23:16:27 PDT 2019
root:xnu-4903.261.4~2/RELEASE_X86_64 x86_64

We are otherwise using Xamarin.Forms 4.0 and MvvmCross 6.2.3.

When using Xamarin.Android 9.1.8 it works fine. It started crashing with Xamarin.Android 9.2, and also 9.3 now. (I could not try with 9.4 preview because it does not compile, see #3343)

I am testing with Android 9, so it does not seem related to #3314.

Workarounds ?

I tried to disable AAPT2 like explained in the release notes. It does not help.

For now we can compile with Xamarin 9.1 and it works, but it does not look good for the future.

@jschmid
Copy link
Author

jschmid commented Jul 10, 2019

Alright, if I do a weird trick:

  • Compile using version 9.3.0.23
  • Quit Visual Studio
  • Install 9.4.0.34
  • Open the projet and run

Then is will run and work as expected. However, I do not see any bug related to that in the 16-2 milestone.

@dellis1972
Copy link
Contributor

@jschmid thanks for the bug report. This might be related to #3329. We will take a look at the repo project (even though it seems to work) and see if we can figure this out.

@jschmid
Copy link
Author

jschmid commented Jul 11, 2019

Thanks @dellis1972. It seems that #3329 is not included in 9.4.0.34, so I don't think it's related. (But I don't know :) )

@dellis1972
Copy link
Contributor

@jschmid regarding #3329 it might be that is fixes your issue, but its not released yet :) I'll see if I can repo on 9.4.0.34 and see where we can go from there.

@jonathanpeppers
Copy link
Member

@jschmid looking at your stack trace:

  at at mvvmcross.platforms.android.binding.views.MvxLayoutInflater.inflate(MvxLayoutInflater.java:50)

Can you reproduce the problem with your repro project if you change it to use MvvmCross instead of Xamarin.Forms?

@jschmid
Copy link
Author

jschmid commented Jul 17, 2019

@jonathanpeppers I added a new branch with MvvmCross.

The sample works with Xamarin.Android 9.1, 9.3, 9.4.0.34.

@jonathanpeppers jonathanpeppers added the need-info Issues that need more information from the author. label Jul 17, 2019
@jonathanpeppers
Copy link
Member

@jschmid circling back on this, does the problem still occur with the latest preview? Xamarin.Android 10.x.

Would you be able to share the APK file that is crashing? You can email me at what is listed on my Github account if you don't want that public.

@jschmid
Copy link
Author

jschmid commented Sep 3, 2019

Thanks @jonathanpeppers. It still crashes with 9.4.1.0. I could not make it work with 10.0.0.4. It crashes on Activity.OnCreate() before reaching my code.

I've sent you APKs by emails.

@jonathanpeppers
Copy link
Member

jonathanpeppers commented Sep 3, 2019

Will be discussing further over email, the APK I'm seeing a different error:

System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> Xamarin.Forms.Xaml.XamlParseException: Position 220:14. Type converters:InvertedBooleanСonverter not found

But I can find the type in the assembly in the APK it's looking for. So I wonder if it could be related to AndroidPreloadAssemblies=False.

@jonathanpeppers
Copy link
Member

@jschmid and I did some troubleshooting over email, and we found the issue was their solution had a Xamarin.Android app project referencing another app project. The only case this has ever been supported is with Android Wear, which is a special case to embed the Wear app's APK into Resources/raw.

What was happening was the wrong Resource.designer.cs was being used.

I filed #3638 to see what we can do to better prevent developers doing this.

@jschmid let me know otherwise, but I think you solved your issue by moving your solution around. Closing, thanks!

@jschmid
Copy link
Author

jschmid commented Sep 16, 2019

Thanks @jonathanpeppers for the investigation.

We will find a way to make it work now.

@SagarPanwala
Copy link

@jschmid Did you find any solution for this ? Can you please share it with me if you got it ?

@jschmid
Copy link
Author

jschmid commented Oct 21, 2019

@SagarPanwala as @jonathanpeppers said:

we found the issue was their solution had a Xamarin.Android app project referencing another app project.

luckily for us it was easy to "unwrap" the projects and remove this wrong reference. We now have upgraded to Xamarin.Android 10 and it works fine.

@ghost ghost locked as resolved and limited conversation to collaborators Jun 6, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
need-info Issues that need more information from the author.
Projects
None yet
Development

No branches or pull requests

4 participants