dotnet / android

.NET for Android provides open-source bindings of the Android SDK for use with .NET managed languages such as C#
MIT License
1.92k stars 526 forks source link

Only first RuntimeIdentifier used in dotnet publish #7428

Open rgroenewoudt opened 1 year ago

rgroenewoudt commented 1 year ago

Android application type

Android for .NET (net6.0-android, etc.)

Affected platform version

VS2022 17.3.4

Description

I would like to set the runtime identifiers (x86/arm) when using the dotnet publish CLI.

dotnet publish -c Release -p:RuntimeIdentifiers="android-x86;android-arm" -p:AndroidPackageFormat=apk -o test However this doesn't seem to work, only the first runtime identifier is used. The APK only contains libraries for x86 and not arm. The same problem happens when an a different runtime identifier is used such as android-arm64.

Steps to Reproduce

Did you find any workaround?

No

Relevant log output

No response

jonathanpeppers commented 1 year ago

@rgroenewoudt do you see some of the same issues with a .NET 6 console app? You can publish with win-x64 and win-x86, for example.

The reason I'm asking, is this might actually be an issue with the .NET SDK/CLI -- and not the Android workload.

ghost commented 1 year ago

Hi @rgroenewoudt. 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.

rgroenewoudt commented 1 year ago

I am not sure how to check this as far I know assemblies/exe cannot contain both 32-bit and 64-bit? Isn't Android a bit different that it can contain multiple?

Wat I did is create new .NET 6 console app and ran dotnet publish twice and used different orders for win-x86;win-x64. I used DotPeek to look at the assembly (project.dll, not exe) and only when win-x64 was first, then the DLL was a 64-bit version (dotPeek uses the IMAGE_FILE_HEADER in PE file format)

Current dotnet version is 6.0.401 (6.0.9)

rgroenewoudt commented 1 year ago

Is there an workaround to specifically build an APK with x86 and one without x86?

jonathanpeppers commented 1 year ago

I think the problem here is the dotnet CLI.

To workaround, you can put this in your project file:

<RuntimeIdentifiers Condition=" '$(No86)' == 'true' ">android-arm;android-arm64;android-x64</RuntimeIdentifiers>

And then pass -p:No86=true from the command-line. You can name No86 whatever you like, and add appropriate logic as needed?

rgroenewoudt commented 1 year ago

Thanks that works as a workaround. I forgot that conditions can be used in the project file.