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: new cil-strip feature causes app crashes #88538

Closed
Tracked by #80953
jonathanpeppers opened this issue Jul 7, 2023 · 4 comments · Fixed by dotnet/android#8172
Closed
Tracked by #80953

Android: new cil-strip feature causes app crashes #88538

jonathanpeppers opened this issue Jul 7, 2023 · 4 comments · Fixed by dotnet/android#8172
Assignees
Milestone

Comments

@jonathanpeppers
Copy link
Member

jonathanpeppers commented Jul 7, 2023

Description

This was originally implemented in:

But the app crashes at runtime, log snippet with mono --trace on:

07-07 08:33:25.712 18759 18759 D Mono    : AOT: FOUND method Android.Runtime.JNIEnvInit:Initialize (Android.Runtime.JNIEnvInit/JnienvInitializeArgs*) [0x74d4760990 - 0x74d4760d10 0x74d476a970]
07-07 08:33:25.712 18759 18759 V mono    : [0x78158e04f8: 0.01401 0] 
07-07 08:33:25.712 18759 18759 V mono    : ENTER:c (wrapper alloc) object:AllocSmall (intptr,intptr)(
07-07 08:33:25.712 18759 18759 V mono    : 0xb4000076dbe1f8e0
07-07 08:33:25.712 18759 18759 V mono    : , 
07-07 08:33:25.712 18759 18759 V mono    : 0x40
07-07 08:33:25.712 18759 18759 V mono    : )
07-07 08:33:25.712 18759 18759 V mono    : [0x78158e04f8: 0.01405 0] 
07-07 08:33:25.712 18759 18759 V mono    : LEAVE:c (wrapper alloc) object:AllocSmall (intptr,intptr)(
07-07 08:33:25.712 18759 18759 V mono    : [Java.Interop.JniMethodInfo:0x74d7c01898]
07-07 08:33:25.712 18759 18759 V mono    : 
07-07 08:33:25.712 18759 18759 D Mono    : AOT: FOUND method Java.Interop.JniMethodInfo:.ctor (intptr,bool) [0x74d46f8c20 - 0x74d46f8c60 0x74d47042de]
07-07 08:33:25.712 18759 18759 D Mono    : AOT NOT FOUND: (wrapper managed-to-native) object:__icall_wrapper_ves_icall_object_new_specific (intptr).
07-07 08:33:25.712 18759 18759 V mono    : [0x78158e04f8: 0.01425 0] 
07-07 08:33:25.712 18759 18759 V mono    : ENTER:c (wrapper managed-to-native) object:__icall_wrapper_ves_icall_object_new_specific (intptr)(
07-07 08:33:25.712 18759 18759 V mono    : 0xb4000076dbe209d8
07-07 08:33:25.712 18759 18759 V mono    : )
07-07 08:33:25.712 18759 18759 V mono    : [0x78158e04f8: 0.01428 0] 
07-07 08:33:25.712 18759 18759 V mono    : LEAVE:c (wrapper managed-to-native) object:__icall_wrapper_ves_icall_object_new_specific (intptr)(
07-07 08:33:25.712 18759 18759 V mono    : [Android.Runtime.AndroidRuntime:0x74d7c018d8]
07-07 08:33:25.712 18759 18759 V mono    :
...
07-07 08:33:25.714 18759 18759 E companyname.foo: * Assertion at /__w/1/s/src/mono/mono/mini/mini-trampolines.c:1416, condition `invoke' not met

The method in question, looks like it is stripped as expected:

image

I also get the log message:

07-07 08:33:25.712 18759 18759 D Mono    : AOT: FOUND method Android.Runtime.JNIEnvInit:Initialize (Android.Runtime.JNIEnvInit/JnienvInitializeArgs*) [0x74d4760990 - 0x74d4760d10 0x74d476a970]

Reproduction Steps

Expected behavior

A dotnet new android app runs.

Actual behavior

dotnet new android app appears to crash at the first managed method that was stripped away.

Regression?

No, this is a new feature.

Known Workarounds

Don't use -p:AndroidStripIL=true, as this is the new feature.

Configuration

.NET SDK 8.0.100-preview.7.23330.16

Other information

Full adb log: log.txt
Assembly files: uncompressed-com.companyname.foo.zip
Method tokens: tokens.zip

@ghost ghost added the untriaged New issue has not been triaged by the area owner label Jul 7, 2023
@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 Jul 7, 2023
@jonathanpeppers jonathanpeppers changed the title Android new cil-strip feature causes app crashes Android: new cil-strip feature causes app crashes Jul 7, 2023
@vcsjones vcsjones removed the needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners label Jul 7, 2023
@akoeplinger akoeplinger added area-Codegen-AOT-mono and removed area-Build-mono untriaged New issue has not been triaged by the area owner labels Jul 10, 2023
@akoeplinger akoeplinger added this to the 8.0.0 milestone Jul 10, 2023
@ghost ghost added the in-pr There is an active PR which will close this issue when it is merged label Aug 7, 2023
@fanyang-mono
Copy link
Member

Running _RemoveRegisterAttribute task before MonoAOTCompiler and ILStrip would probably fix this issue. It worked when I tested it with disabling RemoveRegisterAttribute locally.

Sending it back to you @jonathanpeppers

@ghost ghost removed the in-pr There is an active PR which will close this issue when it is merged label Aug 11, 2023
@jonathanpeppers
Copy link
Member Author

@fanyang-mono you got a sample "hello android" to work. Do you have a link to your changes somewhere?

@SamMonoRT
Copy link
Member

PR completing this work was merged - dotnet/android#8172

/cc @fanyang-mono - please add details when that will be available for public release, and close this issue.

@fanyang-mono
Copy link
Member

fanyang-mono commented Aug 22, 2023

@SamMonoRT I will add release details in #44855 directly. This issue that @jonathanpeppers ran into when trying to enable IL trim for Android apps. now has been resolved by dotnet/android#8172.

@ghost ghost locked as resolved and limited conversation to collaborators Sep 21, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.