Skip to content

Fix bundled app crash on startup - #1683

Merged
jonpryor merged 1 commit into
dotnet:masterfrom
grendello:issue1651
May 17, 2018
Merged

Fix bundled app crash on startup#1683
jonpryor merged 1 commit into
dotnet:masterfrom
grendello:issue1651

Conversation

@grendello

Copy link
Copy Markdown
Contributor

Fixes: #1651

Recent update to mono brought in changes in the code generated by mkbundle
when dealing with AOT. Unfortunately, the changes require the bundle to be able
to find the mono_jit_set_aot_mode runtime function which isn't exported in the
Xamarin.Android up and thus the loading of the bundle crashes on startup with
the following message:

dlopen failed: cannot locate symbol "mono_jit_set_aot_mode" referenced by libmonodroid_bundle_app.so

To fix this we need to augment the bundle's mono_mkbundle_init function in
generated code to take a third parameter - pointer to the abovementioned
function. With the current code this requires a set of rather ugly changes, as
seen in this commit, but it makes the application not crash on start and is the
fastest way to fix the issue right now.

This is a short-term fix, a long-term one will be presented at a later time.

@grendello

Copy link
Copy Markdown
Contributor Author

The test failures aren't related to this PR. They're due to the two servers used in HTTP tests malfunctioning.

@jonpryor jonpryor added the full-mono-integration-build For PRs; run a full build (~6-10h for mono bumps), not the faster PR subset (~2h for mono bumps) label May 16, 2018
@jonpryor

Copy link
Copy Markdown
Contributor

build

@jonpryor

Copy link
Copy Markdown
Contributor

Rebuilding with the full-mono-integration-build label so that we can see if the $(BundleAssemblies)=True build works, as that's currently Conditional on Release builds, and the default PR builder won't build in Release.

@jonpryor

Copy link
Copy Markdown
Contributor

The macOS PR Build is broken:

Task "Exec" (TaskId:3)
  Task Parameter:Command=mono --debug=casts "/Users/builder/jenkins/workspace/xamarin-android-pr-builder/xamarin-android/bin/Debug/lib/xamarin.android/xbuild/Xamarin/Android/jcw-gen.exe" -v10 -o "/Users/builder/jenkins/workspace/xamarin-android-pr-builder/xamarin-android/src/OpenTK-1.0/obj/Debug/MonoAndroid403/jcw/src" -L "/Users/builder/jenkins/workspace/xamarin-android-pr-builder/xamarin-android/bin/Debug/lib/xamarin.android/xbuild-frameworks/MonoAndroid/v4.0.3/" -L "/Users/builder/jenkins/workspace/xamarin-android-pr-builder/xamarin-android/bin/Debug/lib/xamarin.android/xbuild-frameworks/MonoAndroid/v4.0.3/../v1.0" -L "/Users/builder/jenkins/workspace/xamarin-android-pr-builder/xamarin-android/bin/Debug/lib/xamarin.android/xbuild-frameworks/MonoAndroid/v4.0.3/../v1.0/Facades" "/Users/builder/jenkins/workspace/xamarin-android-pr-builder/xamarin-android/src/OpenTK-1.0/obj/Debug/MonoAndroid403/OpenTK-1.0.dll" (TaskId:3)
  mono --debug=casts "/Users/builder/jenkins/workspace/xamarin-android-pr-builder/xamarin-android/bin/Debug/lib/xamarin.android/xbuild/Xamarin/Android/jcw-gen.exe" -v10 -o "/Users/builder/jenkins/workspace/xamarin-android-pr-builder/xamarin-android/src/OpenTK-1.0/obj/Debug/MonoAndroid403/jcw/src" -L "/Users/builder/jenkins/workspace/xamarin-android-pr-builder/xamarin-android/bin/Debug/lib/xamarin.android/xbuild-frameworks/MonoAndroid/v4.0.3/" -L "/Users/builder/jenkins/workspace/xamarin-android-pr-builder/xamarin-android/bin/Debug/lib/xamarin.android/xbuild-frameworks/MonoAndroid/v4.0.3/../v1.0" -L "/Users/builder/jenkins/workspace/xamarin-android-pr-builder/xamarin-android/bin/Debug/lib/xamarin.android/xbuild-frameworks/MonoAndroid/v4.0.3/../v1.0/Facades" "/Users/builder/jenkins/workspace/xamarin-android-pr-builder/xamarin-android/src/OpenTK-1.0/obj/Debug/MonoAndroid403/OpenTK-1.0.dll" (TaskId:3)
  jcw-gen: System.IO.FileNotFoundException: Could not load assembly 'OpenTK-1.0, Version=0.0.0.0, Culture=neutral, PublicKeyToken='. Perhaps it doesn't exist in the Mono for Android profile? (TaskId:3)
  File name: 'OpenTK-1.0.dll' (TaskId:3)
    at Java.Interop.Tools.Cecil.DirectoryAssemblyResolver.Resolve (Mono.Cecil.AssemblyNameReference reference, Mono.Cecil.ReaderParameters parameters) [0x000c3] in /Users/builder/jenkins/workspace/xamarin-android-pr-builder/xamarin-android/external/Java.Interop/src/Java.Interop.Tools.Cecil/Java.Interop.Tools.Cecil/DirectoryAssemblyResolver.cs:241  (TaskId:3)
...

...because monodroid/master is broken: https://jenkins.mono-project.com/view/Xamarin.Android/job/xamarin-android/1003/

@jonpryor

Copy link
Copy Markdown
Contributor

@grendello: Please rebase this PR on be594d2 or later.

Fixes: dotnet#1651

Recent update to mono brought in changes in the code generated by `mkbundle`
when dealing with AOT. Unfortunately, the changes require the bundle to be able
to find the `mono_jit_set_aot_mode` runtime function which isn't exported in the
Xamarin.Android up and thus the loading of the bundle crashes on startup with
the following message:

    dlopen failed: cannot locate symbol "mono_jit_set_aot_mode" referenced by libmonodroid_bundle_app.so

To fix this we need to augment the bundle's `mono_mkbundle_init` function in
generated code to take a third parameter - pointer to the abovementioned
function. With the current code this requires a set of rather ugly changes, as
seen in this commit, but it makes the application not crash on start and is the
fastest way to fix the issue right now.

This is a short-term fix, a long-term one will be presented at a later time.
@jonpryor
jonpryor merged commit 1a45e1e into dotnet:master May 17, 2018
@grendello
grendello deleted the issue1651 branch May 17, 2018 17:36
jonpryor pushed a commit that referenced this pull request May 18, 2018
Fixes: #1651

Recent update to mono (166e7d5) brought in changes in the code
generated by `mkbundle.exe`, which is used when
`$(BundleAssemblies)`=True.  Unfortunately, the changes require the
bundle to be able to find the `mono_jit_set_aot_mode()` mono
embedding function, which doesn't work because
`libmonodroid_bundle_app.so` doesn't link against
`libmonosgen-2.0.so` -- because it can't, because on Android e.g.
`/data/data/@PACKAGE_NAME@/lib` isn't in `$LD_LIBRARY_PATH`, meaning
libraries "next to" `libmonodroid_bundle_app.so` won't be found by
**dlopen**(3), which is a constant source of ironically great fun --
which means that when we *do* try to call
`dlopen("libmonodroid_bundle_app")`, *it fails*:

        dlopen failed: cannot locate symbol "mono_jit_set_aot_mode" referenced by libmonodroid_bundle_app.so

To fix this we need to augment the bundle's `mono_mkbundle_init()`
function (which comes in via generated code) to take a third
parameter: a function pointer to `mono_jit_set_aot_mode`.  With the
current code this requires a set of rather ugly changes, but it makes
the application not crash on start and is the fastest way to fix the
issue right now.

This is a short-term fix.  A longer-term fix is being worked on:

        mono/mono#8742

Additionally, update `RunTests.targets` so that we build
`src/Mono.Android/Test` with `$(BundleAssemblies)`=True and execute
the resulting `Mono.Android_Tests-Signed.apk` on the emulator to
ensure that `$(BundleAssemblies)`=True support works into the future.
radekdoulik added a commit to radekdoulik/xamarin-android that referenced this pull request Nov 7, 2018
Fixes dotnet#2400

With dotnet#1683 we started
to run and measure the apk tests with `BundleAssemblies=True` as
well. To not mix and repeast these measurements with other ones,
introduce `TestsFlavor` property in place of `TestsAotName` to
distinguish the apk tests runs when collecting and processing
measurements data.

It is similar to what we did with AOT before.

Example content of TestResult-Mono.Android_Tests-times.csv after the
fix:

    last-Release,JNI.init-Release,init-Release,NUnit.results-Release,last-Release-Aot,JNI.init-Release-Aot,init-Release-Aot,NUnit.results-Release-Aot,last-Release-Bundle,JNI.init-Release-Bundle,init-Release-Bundle,NUnit.results-Release-Bundle
    518,116,116,8347,647,86,86,7670,755,159,159,8416
@github-actions github-actions Bot locked and limited conversation to collaborators Feb 2, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

full-mono-integration-build For PRs; run a full build (~6-10h for mono bumps), not the faster PR subset (~2h for mono bumps)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bundled app initialization error (vs 15.7 preview)

2 participants