Closed akrol95 closed 4 months ago
@akrol95 could you try adding the following to your .csproj:
<PropertyGroup>
<EnableLLVM>False</EnableLLVM>
</PropertyGroup>
Your issue appears to be identical to https://github.com/xamarin/xamarin-android/issues/7352 and, if it indeed is, the above should make the problem go away. Please let me know if it worked, thanks!
Hi @akrol95. We have added the "need-info" label to this issue, which indicates that we have an open question for you before we can take further action. This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.
@grendello Is it possible that this issue now happens due to additional check
if (!UseAndroidNdk) {
ldFlags.Append ("--no-relax");
}
Since #6901 --no-relax
flag applies only when AndroidNdkDirectory
is not specified.
@FoggyFinder it is possible and EnableLLVM=False
will test just that theory :)
@grendello The documentation says that the EnableLLVM
flag is set to False
by default, so in our case it doesn't matter if we add it or no because we didn't have it before. However I just tested it with EnableLLVM=False
added to .csproj for release configuration and the result is the same. It's still crashing with the same logcat output.
We had a similar issue and after playing around with the settings quite a bit, the only combination that worked for us was both EnableLLVM=False
and removing AndroidNdkDirectory
from the csproj/build (leaving the value unset)
@akrol95 the setting may come from other sources than the .csproj (it can be in the environment, or set in Directory.Build.props
that's not part of the repo), thus it had to be tested :)
@kevcrooks yes, that might be necessary if the NDK pointed to by AndroidNdkDirectory
uses LLVM 13 or newer (which is the case for the current NDK release). @akrol95 would you mind testing that one too?
The root cause of the issue is described in this commit.
@grendello I tried with:
<EnableLLVM>False</EnableLLVM>
<AndroidNdkDirectory />
It's still crashing for the same reason.
@akrol95 did you rebuild from scratch, after removing all bin
and obj
directories?
I've tried to reproduce the issue, but the app neither crashes nor starts up, it just locks up on the splash screen. However, I see the following in the build logs:
[aot-compiler stdout] Executing the native linker: ".../bin/Release/lib/xamarin.android/xbuild/Xamarin/Android/Linux/binutils/bin/aarch64-linux-android-ld" -Bsymbolic -shared -o obj/Release/aot/arm64-v8a/libaot-Xamarin.Kotlin.StdLib.Jdk7.dll.so.tmp obj/Release/aot/arm64-v8a/Xamarin.Kotlin.StdLib.Jdk7.dll/temp.s.o --no-relax -s
@akrol95 would you mind building with -bl
and then examine the binlog to find a line similar to the above and check if your build passes --no-relax
to the linker? If the flag isn't passed, could you modify the linker script used in the above command line to pass the --no-relax
flag to the actual linker?
On Unix, the script should be modified to look as follows:
#!/bin/bash -e
MY_DIR="$(cd $(dirname $0);pwd)"
exec "${MY_DIR}"/ld --no-relax "$@"
and on Windows, to:
@echo off
setlocal
set BINARIES_DIRECTORY=%~dp0
set "BINARIES_DIRECTORY=" && "%BINARIES_DIRECTORY%ld.exe" --no-relax %*
if not ERRORLEVEL 0 exit /b %errorlevel%
@akrol95 did you rebuild from scratch, after removing all
bin
andobj
directories?
Yes, I did it every time.
I've tried to reproduce the issue, but the app neither crashes nor starts up, it just locks up on the splash screen. However, I see the following in the build logs:
[aot-compiler stdout] Executing the native linker: ".../bin/Release/lib/xamarin.android/xbuild/Xamarin/Android/Linux/binutils/bin/aarch64-linux-android-ld" -Bsymbolic -shared -o obj/Release/aot/arm64-v8a/libaot-Xamarin.Kotlin.StdLib.Jdk7.dll.so.tmp obj/Release/aot/arm64-v8a/Xamarin.Kotlin.StdLib.Jdk7.dll/temp.s.o --no-relax -s
@akrol95 would you mind building with
-bl
and then examine the binlog to find a line similar to the above and check if your build passes--no-relax
to the linker? If the flag isn't passed, could you modify the linker script used in the above command line to pass the--no-relax
flag to the actual linker?On Unix, the script should be modified to look as follows:
#!/bin/bash -e MY_DIR="$(cd $(dirname $0);pwd)" exec "${MY_DIR}"/ld --no-relax "$@"
and on Windows, to:
@echo off setlocal set BINARIES_DIRECTORY=%~dp0 set "BINARIES_DIRECTORY=" && "%BINARIES_DIRECTORY%ld.exe" --no-relax %* if not ERRORLEVEL 0 exit /b %errorlevel%
So for me this line (and all the rest starting with "Executing the native linker...") looks like this:
0>[aot-compiler stdout] Executing the native linker: "/Library/Frameworks/Xamarin.Android.framework/Libraries/xbuild/Xamarin/Android/Darwin/binutils/bin/aarch64-linux-android-ld" -Bsymbolic -shared -o obj/Release/aot/arm64-v8a/libaot-Xamarin.Kotlin.StdLib.Jdk7.dll.so.tmp obj/Release/aot/arm64-v8a/Xamarin.Kotlin.StdLib.Jdk7.dll/temp.s.o -s
Sorry, but I don't get which exact script should I modify. Would you mind describing it more precisely?
Looks like your build isn't passing --no-relax
then, ok, that's promising.
The script to edit would be /Library/Frameworks/Xamarin.Android.framework/Libraries/xbuild/Xamarin/Android/Darwin/binutils/bin/aarch64-linux-android-ld
in your case (and, potentially, others in the same directory ending with -ld
Thank you for clarification. I modified all those scripts, built the app again and it opens and runs properly.
But what's next? What else can I check to have this --no-relax
parameter passing to linker in normal conditions?
You can try adding the below property to your csproj, hopefully it works:
<PropertyGroup>
<AndroidExtraAotOptions>ld-flags=--no-relax -s</AndroidExtraAotOptions>
</PropertyGroup>
@grendello I am getting following error and the build crashes:
Target _AndroidAot:
0>[aot-compiler stderr] Can not open image ld-flags=--no-relax
0>[aot-compiler stderr] Can not open image ld-flags=--no-relax
@akrol95 OK, so that didn't work... I'll try to think about some other approach.
@akrol95 we tested Xamarin.Android 13.1.0.1 locally and it built your app properly. I'm afraid we're going to need a binlog from one of your builds (pass -bl
to msbuild), to see what exactly is going on. Please build from scratch, thanks!
Hi @akrol95. We have added the "need-info" label to this issue, which indicates that we have an open question for you before we can take further action. This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.
I'm unable to reproduce the specified crash on macOS using Xamarin.Android 13.1.0.1:
% git clone https://github.com/bcc-code/bmm-app.git
% cd bmm-app
% git checkout crash-on-start
% msbuild -p:Configuration=Release -restore
% msbuild -p:Configuration=Release
% cd BMM.UI.Android
% msbuild -p:Configuration=Release -t:Install -v:diag > b.txt
% msbuild -p:Configuration=Release -t:_Run
b.txt
shows that --no-relax
is being used, e.g.:
[AOT] response file obj/Release/aot/armeabi-v7a/Java.Interop.dll/response.txt: "--aot=asmwriter,mtriple=armv7-linux-gnueabi,tool-prefix=/Library/Frameworks/Xamarin.Android.framework/Libraries/xbuild/Xamarin/Android/Darwin/binutils/bin/arm-linux-androideabi-,outfile=obj/Release/aot/armeabi-v7a/libaot-Java.Interop.dll.so,llvm-path=/Library/Frameworks/Xamarin.Android.framework/Libraries/xbuild/Xamarin/Android/Darwin,temp-path=obj/Release/aot/armeabi-v7a/Java.Interop.dll,ld-name=ld,ld-flags=--no-relax -s" …/bmm-app/BMM.UI.Android/obj/Release/android/assets/shrunk/Java.Interop.dll
Additionally, EnableLLVM
is not found in b.txt
, and $(AndroidNdkDirectory)
is set.
That said, the app does crash on startup, but for a different reason; from adb logcat
:
E AndroidRuntime: java.lang.RuntimeException: Unable to create service bmm.BmmMessagingService: java.lang.ClassNotFoundException: Didn't find class "bmm.BmmMessagingService" on path: De
xPathList[[zip file "/data/app/~~Pq25oMv7faoUZtt2bGQSbQ==/org.brunstad.bmm-311vZL5HZ-L0WBglMCSGEg==/base.apk"],nativeLibraryDirectories=[/data/app/~~Pq25oMv7faoUZtt2bGQSbQ==/org.brunstad.bmm-311vZL5HZ-L0WBglMCSGEg==/
lib/arm64, /data/app/~~Pq25oMv7faoUZtt2bGQSbQ==/org.brunstad.bmm-311vZL5HZ-L0WBglMCSGEg==/base.apk!/lib/arm64-v8a, /system/lib64, /system_ext/lib64]
I haven't investigated my startup crash further, I just note that it is not an assertion in tramp-arm64.c:53
.
@jonpryor wrote:
…the app does crash on startup, but for a different reason; from
adb logcat
:AndroidRuntime: java.lang.RuntimeException: Unable to create service bmm.BmmMessagingService: java.lang.ClassNotFoundException: Didn't find class "bmm.BmmMessagingService" on path…
Cursory investigation shows that it fails because the type doesn't exist:
% $ANDROID_SDK_PATH/build-tools/31.0.3/dexdump obj/Release/android/bin/classes.dex | grep BmmMessaging
# no matches
git grep BmmMessagingSer
only finds a match in BMM.UI.Android/Properties/AndroidManifest.xml
. If I remove/comment out all <service/>
elements within AndroidManifest.xml
and reinstall. With that change, it doesn't immediately crash on startup. (It also doesn't appear to get past the splash screen…)
@akrol95: the likely immediate cause of your issue is: https://github.com/bcc-code/bmm-app/blob/3c498d48f66994a00168f054a68c56aa726235fa/azure-pipelines-android.yaml#L43
- task: XamarinAndroid@1
inputs:
msbuildArguments: '/p:SolutionDir="$(Build.SourcesDirectory)" -p:AndroidPackageFormat=aab -t:SignAndroidPackage -p:AndroidKeyStore=True -p:AndroidNdkDirectory="$(ANDROID_NDK_LATEST_HOME)"'
MSBuild command-line arguments are immutable; they cannot be changed from project files. For example, given x.targets
:
<Project>
<PropertyGroup>
<Foo>Default</Foo>
</PropertyGroup>
<Target Name="PrintFoo">
<Message Text="Foo=$(Foo)" Importance="High" />
</Target>
</Project>
If you invoke the PrintFoo
target while overriding the Foo
property, the value provided on the command-line is used, even though the <Foo/>
definition is always provided (i.e. is not Conditional=" '$(Foo)' == '' "
):
% msbuild -nologo -v:m x.targets -t:PrintFoo -p:Foo=Override
Foo=Override
Similarly, if we instead "set and clear" the property:
<PropertyGroup>
<Foo>Default</Foo>
<Foo/>
</PropertyGroup>
Then the "default" invocation sees an empty string:
% msbuild -nologo -v:m x.targets -t:PrintFoo
Foo=
while the above "set an override" version continues to show the override value:
% msbuild -nologo -v:m x.targets -t:PrintFoo -p:Foo=Override
Foo=Override
If you build x.targets
with diagnostic logging enabled (msbuild -v:diag -t:PrintFoo -p:Foo=Override
), then the log will contain:
The "Foo" property is a global property, and cannot be modified.
further emphasizing that the property cannot be changed.
Solution/Workaround: If you update azure-pipelines-android.yaml
so that -p:AndroidNdkDirectory="$(ANDROID_NDK_LATEST_HOME)"
is NOT specified, it should run as expected for you.
@jonpryor
I tried you MSBuild commands and the builld output also contains -no-relax
in my case, even using 13.1.0.1.
I realized that something is causing the IDE to pass AndroidNdkDirectory parameter to MSBuild even though it's not explicitly set in the code. In desperation, I decided to completely remove the path to NDK in VS Settings:
And now the build output correctly shows -no-relax
for linker, the app works as expected.
Also, for the pipeline, removing -p:AndroidNdkDirectory
from MSBuild parameter seems to solve the issue.
BTW. Setting AndroidNdkDirectory in .csproj does nothing when building from IDE, because it looks that this value is override anyway from IDE settings and pass as parameter to MSBuild.
@jonpryor @grendello Thank you for your time investigating the issue.
With support for Classic Xamarin.Android ended May 1st, 2024, this issue is likely no longer relevant.
If this still persists in .NET 8+, please open a new issue with updated information based on net8.0-android
or greater. Please include a link to this issue for context.
Android application type
Classic Xamarin.Android (MonoAndroid12.0, etc.)
Affected platform version
Xamarin.Android 13.1.0.1
Description
Our application started to crashing on start recently. During investingation on our side, we found out, that the only change we recently made is change Xamarin.Android package from 13.0.0.0 to 13.1.0.1. The app is crashing only when built in release mode and archived as .apk or .aab. The behaviour is the same, regardless of the platform where the app has been built (Windows, Mac, Azure DevOps hosted agent).
Our configuration:
As we are open source, I have prepared a branch with smallest possible project, where you can reproduce the issue: https://github.com/bcc-code/bmm-app/tree/crash-on-start
I'm also attaching logcat with crash description. I'm open to share more information if needed.
Steps to Reproduce
Did you find any workaround?
Downgrading Xamarin.Android to 13.0.0.0
Relevant log output