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 AOT startup crash #102166

Closed
kerams opened this issue May 13, 2024 · 7 comments
Closed

Android AOT startup crash #102166

kerams opened this issue May 13, 2024 · 7 comments

Comments

@kerams
Copy link

kerams commented May 13, 2024

Description

Avalonia application for Android compiled with AOT and 9.0.0-preview.3.24172.9 crashes on an Android 10 ARM64 device, but not in x64 emulator.

Reproduction Steps

It's a closed source application, but I'm almsot willing to bet it could be reproduced with a minimal Avalonia template. In any case, here are the fsproj settings:

Details
<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net9.0-android</TargetFramework>
    <SupportedOSPlatformVersion>26.0</SupportedOSPlatformVersion>
    <AndroidPackageFormat>apk</AndroidPackageFormat>
    <SatelliteResourceLanguages>en</SatelliteResourceLanguages>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)'=='Release'">
    <PublishTrimmed>true</PublishTrimmed>
    <TrimMode>partial</TrimMode>
    <RunAOTCompilation>True</RunAOTCompilation>
    <AndroidKeyStore>False</AndroidKeyStore>
    <AndroidLinkTool>r8</AndroidLinkTool>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)'=='Debug'">
    <AndroidKeyStore>False</AndroidKeyStore>
  </PropertyGroup>
  <Target Name="ConfigureTrimming" BeforeTargets="PrepareForILLink">
    <ItemGroup>
      <ManagedAssemblyToLink Condition="'%(Filename)' == 'System.Private.CoreLib'">
        <IsTrimmable>false</IsTrimmable>
      </ManagedAssemblyToLink>
    </ItemGroup>
  </Target>
  <ItemGroup>
    <None Include="Properties\AndroidManifest.xml" />
    <AndroidResource Include="Resources\**\*" />
    <Compile Include="MainActivity.fs" />
    <Compile Include="SplashActivity.fs" />
  </ItemGroup>
  <ItemGroup>
    <ProjectReference Include="..\Mobile.Common\Mobile.Common.fsproj" />
  </ItemGroup>
  <Import Project="..\..\..\.paket\Paket.Restore.targets" />
</Project>

Expected behavior

No startup crash.

Actual behavior

Startup crash with

05-13 20:34:25.189 20328 20328 I crash_dump64: performing dump of process 20295 (target tid = 20295)
05-13 20:34:25.203 20328 20328 F DEBUG   : *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
05-13 20:34:25.203 20328 20328 F DEBUG   : LineageOS Version: '17.1-20200924-NIGHTLY-pioneer'
05-13 20:34:25.203 20328 20328 F DEBUG   : Build fingerprint: 'Sony/H3113/H3113:8.0.0/50.1.A.4.76/2209478692:user/release-keys'
05-13 20:34:25.203 20328 20328 F DEBUG   : Revision: '0'
05-13 20:34:25.203 20328 20328 F DEBUG   : ABI: 'arm64'
05-13 20:34:25.204 20328 20328 F DEBUG   : Timestamp: 2024-05-13 20:34:25+0200
05-13 20:34:25.204 20328 20328 F DEBUG   : pid: 20295, tid: 20295, name: com.snipperino  >>> com.snipperino <<<
05-13 20:34:25.204 20328 20328 F DEBUG   : uid: 10140
05-13 20:34:25.204 20328 20328 F DEBUG   : signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x234
05-13 20:34:25.204 20328 20328 F DEBUG   : Cause: null pointer dereference
05-13 20:34:25.204 20328 20328 F DEBUG   :     x0  0000000000000000  x1  665f746f615f6f6e  x2  6f666e695f656c69  x3  0000000000000006
05-13 20:34:25.204 20328 20328 F DEBUG   :     x4  20434c4120640000  x5  0000007069ff6de0  x6  6f6e20646c756f43  x7  7320646e69662074
05-13 20:34:25.204 20328 20328 F DEBUG   :     x8  0000000000000234  x9  000000706e216b00  x10 0000000000000001  x11 0000007040000000
05-13 20:34:25.204 20328 20328 F DEBUG   :     x12 0000000000000060  x13 000000000b006518  x14 0000000000000060  x15 0000008000000000
05-13 20:34:25.204 20328 20328 F DEBUG   :     x16 000000715dd998f0  x17 000000715dd8bb50  x18 0000007161f9a000  x19 000000706dfea320
05-13 20:34:25.204 20328 20328 F DEBUG   :     x20 00000070cc142580  x21 0000007069f85a10  x22 0000007069d428e0  x23 0000000000000000
05-13 20:34:25.204 20328 20328 F DEBUG   :     x24 0000007069f859e0  x25 000000706dfea330  x26 0000007075c3dc81  x27 00000070cc5e2d24
05-13 20:34:25.204 20328 20328 F DEBUG   :     x28 0000007069f85a30  x29 0000007fef3929b0
05-13 20:34:25.204 20328 20328 F DEBUG   :     sp  0000007fef392920  lr  00000070cc41f198  pc  00000070cc41f1a4
05-13 20:34:25.205 20328 20328 F DEBUG   :
05-13 20:34:25.205 20328 20328 F DEBUG   : backtrace:
05-13 20:34:25.205 20328 20328 F DEBUG   :       #00 pc 00000000001361a4  /data/app/com.snipperino-a456wxPK2kFg2-Xouzh1dA==/lib/arm64/libmonosgen-2.0.so (BuildId: 2929beb5d26398447fb2d28409a70eccf684c59e)
05-13 20:34:25.205 20328 20328 F DEBUG   :       #01 pc 00000000001fbb08  /data/app/com.snipperino-a456wxPK2kFg2-Xouzh1dA==/lib/arm64/libmonosgen-2.0.so (BuildId: 2929beb5d26398447fb2d28409a70eccf684c59e)
05-13 20:34:25.205 20328 20328 F DEBUG   :       #02 pc 00000000001fc830  /data/app/com.snipperino-a456wxPK2kFg2-Xouzh1dA==/lib/arm64/libmonosgen-2.0.so (BuildId: 2929beb5d26398447fb2d28409a70eccf684c59e)
05-13 20:34:25.206 20328 20328 F DEBUG   :       #03 pc 00000000001fdd0c  /data/app/com.snipperino-a456wxPK2kFg2-Xouzh1dA==/lib/arm64/libmonosgen-2.0.so (mono_assembly_load_from_full+116) (BuildId: 2929beb5d26398447fb2d28409a70eccf684c59e)
05-13 20:34:25.206 20328 20328 F DEBUG   :       #04 pc 000000000001c060  /data/app/com.snipperino-a456wxPK2kFg2-Xouzh1dA==/lib/arm64/libmonodroid.so (xamarin::android::internal::EmbeddedAssemblies::open_from_bundles(void*, _MonoAssemblyName*, char**, void*, _MonoError*)+7028) (BuildId: 941d3c28803eb1b4b2fb9ecfdf447edfd0a21e95)

Detailed logcat output: logcat.zip

Regression?

Yes, application launches when compiled using 9.0.100-preview.2.24157.14

It's also slightly concerning that the output apk containing libraries for all 4 ABIs is 85MB on Preview 3 and 65MB on Preview 2.

Known Workarounds

No response

Configuration

No response

Other information

No response

@dotnet-issue-labeler dotnet-issue-labeler bot added the needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners label May 13, 2024
@dotnet-policy-service dotnet-policy-service bot added the untriaged New issue has not been triaged by the area owner label May 13, 2024
@kerams kerams changed the title Android AOT startup crassh Android AOT startup crash May 13, 2024
@vcsjones vcsjones added os-android area-VM-meta-mono and removed needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners labels May 14, 2024
@lambdageek
Copy link
Member

/cc @steveisok

@steveisok
Copy link
Member

I can reproduce with an avalonia sample using F# as the language. If I stick with C#, it works as expected.

Unsure what's missing with F#, but I presume something is and that's what is causing the crash. Will continue to investigate.

@steveisok steveisok removed the untriaged New issue has not been triaged by the area owner label May 14, 2024
@steveisok steveisok added this to the 9.0.0 milestone May 14, 2024
@steveisok steveisok self-assigned this May 14, 2024
@steveisok
Copy link
Member

@jonathanpeppers could there be something missing from our end w/ f# as the target language?

@kerams
Copy link
Author

kerams commented May 15, 2024

Well, FSharp.Core has limited compatibility with trimming/AOT, but maybe it doesn't come into play until later during startup?

As I said, this works just fine with Preview 2 on ARM64 in addition to x64 on Preview 3, so the problem is hopefully not too hard to pinpoint.

@jonathanpeppers
Copy link
Member

@kerams if you remove this setting, does it change anything <AndroidLinkTool>r8</AndroidLinkTool>? That is the only thing that looks non-default to me.

We have a few F# tests, but they are basically empty "hello world" projects. We don't even have dotnet new android templates for F#.

Regarding:

apk containing libraries for all 4 ABIs is 85MB on Preview 3 and 65MB on Preview 2.

This is on-purpose, due to the change:

Going forward, we are relying on Google Play splitting up your app per architecture. If you want to compare, check the file size Google Play reports, or you can build for a single arch like android-arm64 to estimate.

@kerams
Copy link
Author

kerams commented May 15, 2024

Removed the link tool setting. The apk size increased, so it did have some effect, but still crashes.

@kerams
Copy link
Author

kerams commented May 21, 2024

Works again on Preview 4. Feel free to close if you do not want to investigate further.

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

No branches or pull requests

5 participants