-
Notifications
You must be signed in to change notification settings - Fork 564
[monodroid] ensure main app assembly is loaded #4058
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
Merged
jonpryor
merged 2 commits into
dotnet:master
from
jonathanpeppers:resourceidmanager-assembly-loading
Jan 7, 2020
Merged
[monodroid] ensure main app assembly is loaded #4058
jonpryor
merged 2 commits into
dotnet:master
from
jonathanpeppers:resourceidmanager-assembly-loading
Jan 7, 2020
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Contributor
|
Unit test? :-D This should add a |
Member
Author
I'll look into this after the holiday. I sent this as a start, because I was not sure about it. @grendello might know more then, too. |
Fixes: https://developercommunity.visualstudio.com/content/problem/788217/xamarin-android-resource-ids-mismatch-1.html In a project where: * The `MainLauncher` activity is in a class library * This activity uses a value from `Resource.designer.cs` You get a crash such as: UNHANDLED EXCEPTION: Android.Content.Res.Resources+NotFoundException: Resource ID #0x7f09001c at Java.Interop.JniEnvironment+InstanceMethods.CallNonvirtualVoidMethod (Java.Interop.JniObjectReference instance, Java.Interop.JniObjectReference type, Java.Interop.JniMethodInfo method, Java.Interop.JniArgumentValue* args) [0x0008e] in <e7e2d009b69d4e5f9a00e6ee600b8a8e>:0 at Java.Interop.JniPeerMembers+JniInstanceMethods.InvokeVirtualVoidMethod (System.String encodedMember, Java.Interop.IJavaPeerable self, Java.Interop.JniArgumentValue* parameters) [0x0005d] in <e7e2d009b69d4e5f9a00e6ee600b8a8e>:0 at Android.App.Activity.SetContentView (System.Int32 layoutResID) [0x00022] in <82e50ec67af648c3b9f43b3d70e21b96>:0 at ClassLibrary1.SharedActivity.OnCreate (Android.OS.Bundle savedInstanceState) [0x00011] in <aff3f2d8f15f4b618f6674d9c306f099>:0 at Android.App.Activity.n_OnCreate_Landroid_os_Bundle_ (System.IntPtr jnienv, System.IntPtr native__this, System.IntPtr native_savedInstanceState) [0x00011] in <82e50ec67af648c3b9f43b3d70e21b96>:0 at (wrapper dynamic-method) Android.Runtime.DynamicMethodNameCounter.4(intptr,intptr,intptr) --- End of managed Android.Content.Res.Resources+NotFoundException stack trace --- android.content.res.Resources$NotFoundException: Resource ID #0x7f09001c at android.content.res.ResourcesImpl.getValue(ResourcesImpl.java:237) at android.content.res.Resources.loadXmlResourceParser(Resources.java:2281) at android.content.res.Resources.getLayout(Resources.java:1175) at android.view.LayoutInflater.inflate(LayoutInflater.java:532) at android.view.LayoutInflater.inflate(LayoutInflater.java:481) at android.support.v7.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:469) at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140) at crc64fd99288c2cd04dcf.SharedActivity.n_onCreate(Native Method) at crc64fd99288c2cd04dcf.SharedActivity.onCreate(SharedActivity.java:30) at android.app.Activity.performCreate(Activity.java:7802) at android.app.Activity.performCreate(Activity.java:7791) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1306) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3245) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3409) at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83) at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135) at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2016) at android.os.Handler.dispatchMessage(Handler.java:107) at android.os.Looper.loop(Looper.java:214) at android.app.ActivityThread.main(ActivityThread.java:7356) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930) In this example `App1.dll` is the main app assembly, but `ClassLibrary1.SharedActivity` is the `MainLauncher`. What was strange is that when I looked at the list of assemblies in `AppDomain.CurrentDomain.GetAssemblies ()` before the failure, `App1.dll` was not in the list! So I enabled a bunch of logging: adb shell setprop debug.mono.log default,assembly,timing The log messages like this did not mention `App1.dll`: 12-19 09:11:44.425 22695 22695 I monodroid-assembly: open_from_update_dir: loaded assembly: 0x7723bca880 12-19 09:11:44.425 22695 22695 I monodroid-timing: Assembly load: ClassLibrary1.dll preloaded; elapsed: 0s:1::252032 Which lead me to this code: /* skip element 0, as that's loaded in create_domain() */ for (size_t i = 1; i < assemblies.get_length (); ++i) { I don't actually see anything in `create_domain` that would load `App1.dll`? Looking through the commit history I don't understand how this project would have ever worked? Changing `i = 1` to `i = 0` solves the crash in the project. However, there might be a better fix here. I added a test that reproduces the issue. I also added a `SetTargetFrameworkAndManifest` helper method to cleanup `DebuggingTest.cs`.
eedcbfe to
ad5cf6b
Compare
dellis1972
approved these changes
Jan 6, 2020
Member
Author
|
The MSBuild w/ emulator job is doing something weird: I'm not sure how this PR would break this, but I'll try restarting. |
Member
Author
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
grendello
approved these changes
Jan 7, 2020
Member
Author
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
jonpryor
pushed a commit
that referenced
this pull request
Jan 7, 2020
Fixes: https://developercommunity.visualstudio.com/content/problem/788217/xamarin-android-resource-ids-mismatch-1.html In a project where: 1. The `MainLauncher` activity is in a class library 2. This activity uses a value from `Resource.designer.cs` You get a crash such as: UNHANDLED EXCEPTION: Android.Content.Res.Resources+NotFoundException: Resource ID #0x7f09001c at Java.Interop.JniEnvironment+InstanceMethods.CallNonvirtualVoidMethod (Java.Interop.JniObjectReference instance, Java.Interop.JniObjectReference type, Java.Interop.JniMethodInfo method, Java.Interop.JniArgumentValue* args) [0x0008e] in <e7e2d009b69d4e5f9a00e6ee600b8a8e>:0 at Java.Interop.JniPeerMembers+JniInstanceMethods.InvokeVirtualVoidMethod (System.String encodedMember, Java.Interop.IJavaPeerable self, Java.Interop.JniArgumentValue* parameters) [0x0005d] in <e7e2d009b69d4e5f9a00e6ee600b8a8e>:0 at Android.App.Activity.SetContentView (System.Int32 layoutResID) [0x00022] in <82e50ec67af648c3b9f43b3d70e21b96>:0 at ClassLibrary1.SharedActivity.OnCreate (Android.OS.Bundle savedInstanceState) [0x00011] in <aff3f2d8f15f4b618f6674d9c306f099>:0 at Android.App.Activity.n_OnCreate_Landroid_os_Bundle_ (System.IntPtr jnienv, System.IntPtr native__this, System.IntPtr native_savedInstanceState) [0x00011] in <82e50ec67af648c3b9f43b3d70e21b96>:0 at (wrapper dynamic-method) Android.Runtime.DynamicMethodNameCounter.4(intptr,intptr,intptr) --- End of managed Android.Content.Res.Resources+NotFoundException stack trace --- android.content.res.Resources$NotFoundException: Resource ID #0x7f09001c at android.content.res.ResourcesImpl.getValue(ResourcesImpl.java:237) at android.content.res.Resources.loadXmlResourceParser(Resources.java:2281) at android.content.res.Resources.getLayout(Resources.java:1175) at android.view.LayoutInflater.inflate(LayoutInflater.java:532) at android.view.LayoutInflater.inflate(LayoutInflater.java:481) at android.support.v7.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:469) at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140) at crc64fd99288c2cd04dcf.SharedActivity.n_onCreate(Native Method) at crc64fd99288c2cd04dcf.SharedActivity.onCreate(SharedActivity.java:30) at android.app.Activity.performCreate(Activity.java:7802) at android.app.Activity.performCreate(Activity.java:7791) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1306) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3245) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3409) at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83) at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135) at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2016) at android.os.Handler.dispatchMessage(Handler.java:107) at android.os.Looper.loop(Looper.java:214) at android.app.ActivityThread.main(ActivityThread.java:7356) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930) In this example `App1.dll` is the main app assembly, but `ClassLibrary1.SharedActivity` is the `MainLauncher`. What was strange is that when I looked at the list of assemblies in `AppDomain.CurrentDomain.GetAssemblies ()` before the failure, `App1.dll` was not in the list! So I enabled a bunch of logging: adb shell setprop debug.mono.log default,assembly,timing The log messages like this did not mention `App1.dll`: I monodroid-assembly: open_from_update_dir: loaded assembly: 0x7723bca880 I monodroid-timing: Assembly load: ClassLibrary1.dll preloaded; elapsed: 0s:1::252032 Which lead me to this code: /* skip element 0, as that's loaded in create_domain() */ for (size_t i = 1; i < assemblies.get_length (); ++i) { I don't actually see anything in `create_domain()` that would load `App1.dll`? Looking through the commit history I don't understand how this project would have ever worked? Changing `i = 1` to `i = 0` solves the crash in the project. I added a test that reproduces the issue. I also added a `DebuggingTest.SetTargetFrameworkAndManifest()` helper method to cleanup `DebuggingTest.cs`.
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes: https://developercommunity.visualstudio.com/content/problem/788217/xamarin-android-resource-ids-mismatch-1.html
In a project where:
MainLauncheractivity is in a class libraryResource.designer.csYou get a crash such as:
In this example
App1.dllis the main app assembly, butClassLibrary1.SharedActivityis theMainLauncher.What was strange is that when I looked at the list of assemblies in
AppDomain.CurrentDomain.GetAssemblies ()before the failure,App1.dllwas not in the list!So I enabled a bunch of logging:
The log messages like this did not mention
App1.dll:Which lead me to this code:
I don't actually see anything in
create_domainthat would loadApp1.dll? Looking through the commit history I don't understand howthis project would have ever worked?
Changing
i = 1toi = 0solves the crash in the project. However,there might be a better fix here.