Skip to content

[NativeAOT] export for android cannot work #109713

Closed as not planned
Closed as not planned

Description

@llzz19851985

Description

Based on the Android-NativeAOT , I wrote a simple example for exporting a dynamic link library to Android studio called by java,the all code as follow:
`
namespace libdotnet
{
// dotnet build
// dotnet publish -r linux-bionic-arm64 -p:DisableUnsupportedError=true
// echo $Env:ANDROID_NDK_HOME

public enum EnumXX
{
    Common,
    Hello,
    World
};

public class VAotApi
{
    [UnmanagedCallersOnly(EntryPoint = "add")]
    public static int Add(int a, int b)
    {
        Log.Info($"=======================Call add method A34:{EnumXX.Common.ToString()}");
        Type tyx = typeof(EnumXX);
        string name = tyx.Name;
        Log.Info($"=======================Call add method :{name}");
        
        return 100 + a + b;
    }

}

}
`

when use the published shared library ,the following problem occurred:
1)it cannot access System.Type properties such as Name,when access,it crash directly;
2)Enum all converted to int,cannot get the Enum string by Enum.ToString();
3)Is there a way to debug into the NET code from android studio?

Reproduction Steps

use command 'dotnet publish -r linux-bionic-arm64 -p:DisableUnsupportedError=true' to export and import into android project

Expected behavior

1)can access System.Type properties
2)can get Enum string by Enum.Tostring() method;
3)can debug the NET code from android studio;

Actual behavior

1)it cannot access System.Type properties such as Name,when access,it crash directly;
2)Enum all converted to int,cannot get the Enum string by Enum.ToString();
3)cannot debug into the NET code from android studio;

Regression?

No response

Known Workarounds

No response

Configuration

net8.0
android ndk R23
Visual studio 2022 17.11.5

dotnet --list-sdks
2.1.202 [C:\Program Files\dotnet\sdk]
2.1.526 [C:\Program Files\dotnet\sdk]
5.0.409 [C:\Program Files\dotnet\sdk]
8.0.403 [C:\Program Files\dotnet\sdk]

Other information

No response

Activity

  1. ghost added
    needs-area-label
    on Nov 12, 2024
  2. added
    untriaged
    on Nov 12, 2024
  3. MichalStrehovsky commented on Nov 12, 2024

    @MichalStrehovsky
    Member

    Did you specify IlcDisableReflection property?

  4. added and removed
    needs-area-label
    on Nov 12, 2024
  5. added
    needs-author-action
    on Nov 12, 2024
  6. changed the title [-]export for android cannot work[/-] [+][NativeAOT] export for android cannot work[/+] on Nov 12, 2024
  7. llzz19851985 commented on Nov 13, 2024

    @llzz19851985
    Author

    Did you specify IlcDisableReflection property?

    excuse me ,how to add this property?

  8. removed
    needs-author-action
    on Nov 13, 2024
  9. MichalStrehovsky commented on Nov 13, 2024

    @MichalStrehovsky
    Member

    Did you specify IlcDisableReflection property?

    excuse me ,how to add this property?

    The failure mode you're seeing should only be reachable if someone turned on the unsupported IlcDisableReflection property. Make sure your project doesn't specify this anywhere.

    You should be able to debug this same way as debugging a C++ library from Android Studio.

    You might want to publish with symbol stripping turned off to make sure the debugger can find the debugging symbols. Pass -p:StripSymbols=false to dotnet publish and try debugging again with the new library.

  10. llzz19851985 commented on Nov 13, 2024

    @llzz19851985
    Author

    Did you specify IlcDisableReflection property?

    excuse me ,how to add this property?

    The failure mode you're seeing should only be reachable if someone turned on the unsupported IlcDisableReflection property. Make sure your project doesn't specify this anywhere.

    You should be able to debug this same way as debugging a C++ library from Android Studio.

    You might want to publish with symbol stripping turned off to make sure the debugger can find the debugging symbols. Pass -p:StripSymbols=false to dotnet publish and try debugging again with the new library.

    thanks for you reply,i set IlcDisableReflection forcr to false in csproj file and than enum and type can work now,thank you very much!
    Image

    but is it still cannot debug the NET code form android studio,i follow this guide https://github.com/dotnet/runtime/blob/main/docs/workflow/debugging/mono/android-debugging.md,but not work,is there are some guide document?

    Image

  11. MichalStrehovsky commented on Nov 13, 2024

    @MichalStrehovsky
    Member

    Wow, you literally set IlcDisableReflection to true in the <!-- From smolsharp section. Please do not use switches you don't understand or at least remember you set them.

    but is it still cannot debug the NET code form android studio,i follow this guide

    Those instructions are for mono. Can you try building an add method in C and stepping into that? With StripSymbols=false, stepping into C# should be no different from stepping into C. I don't know Android studio, sorry.

  12. llzz19851985 commented on Nov 14, 2024

    @llzz19851985
    Author

    Wow, you literally set IlcDisableReflection to true in the <!-- From smolsharp section. Please do not use switches you don't understand or at least remember you set them.

    but is it still cannot debug the NET code form android studio,i follow this guide

    Those instructions are for mono. Can you try building an add method in C and stepping into that? With StripSymbols=false, stepping into C# should be no different from stepping into C. I don't know Android studio, sorry.

    oh,it is my mistake,i cannot find the IlcDisableReflection is set in csproj file,sorry.

    for debug net code from AS,I will try again,thanks!

  13. removed
    untriaged
    on Nov 18, 2024
  14. locked and limited conversation to collaborators on Dec 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    • Status
      No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions