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 publish: error NETSDK1191: A runtime identifier for the property 'SelfContained' couldn't be inferred #15696

Closed
inforithmics opened this issue Jun 16, 2023 · 5 comments · Fixed by dotnet/android#8137
Assignees
Labels
area-publishing Issues with the app packaging/publishing process (ipk/apk/msix/trimming) platform/android 🤖 t/bug Something isn't working

Comments

@inforithmics
Copy link
Contributor

inforithmics commented Jun 16, 2023

Description

After .Net 8 Preview 5 publishing Android App broke.

dotnet publish ./MauiApp1/MauiApp1.csproj -f net8.0-android -c Release
error NETSDK1191: A runtime identifier for the property 'SelfContained' couldn't be inferred

A runtime Identifier cannot be speciified because Android publishes for several Processor Architectures android-arm64 android-arm for example.

Steps to Reproduce

  1. Create new Maui Project select .Net 8.0 (Preview)

  2. Execute on Command line
    dotnet publish ./MauiApp1/MauiApp1.csproj -f net8.0-android -c Release

Link to public reproduction project repository

https://github.com/inforithmics/AndroidMauiPublish

Version with bug

8.0.0-preview.5.8529

Last version that worked well

8.0.0-preview.4.8333

Affected platforms

Android

Affected platform versions

Android

Did you find any workaround?

specifying android runtime:

dotnet publish -r android-arm64 ./MauiApp1/MauiApp1.csproj -f net8.0-android -c Release

but this builds only for android-arm64 in .Net 8

dotnet publish ./MauiApp1/MauiApp1.csproj -f net7.0-android -c Release
built in .Net 7 for the other platforms too (android-arm/android-arm64 for example)

Relevant log output

MSBuild version 17.7.0-preview-23281-03+4ce2ff1f8 for .NET
  Determining projects to restore...
  Restored C:\temp\MauiApp1\MauiApp1\MauiApp1.csproj (in 698 ms).
C:\Program Files\dotnet\sdk\8.0.100-preview.5.23303.2\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.RuntimeIdentifierInf
erence.targets(212,5): error NETSDK1191: A runtime identifier for the property 'SelfContained' couldn't be inferred. Sp
ecify a rid explicitly. [C:\temp\MauiApp1\MauiApp1\MauiApp1.csproj::TargetFramework=net8.0-android]
@inforithmics inforithmics added the t/bug Something isn't working label Jun 16, 2023
@Eilon Eilon added the area-publishing Issues with the app packaging/publishing process (ipk/apk/msix/trimming) label Jun 16, 2023
@daltzctr
Copy link
Contributor

daltzctr commented Jun 20, 2023

Also receiving this, this effectively hard breaks .NET 8 Preview 5. Downgrading to .NET 8 Preview 4 also resolves this problem.

Per here, Android defaults to armeabi-v7a for release builds, so specifying a runtime identifer that way should duplicate the existing behaviour.

Edit: I think the docs are outdated, Android recommends targeting arm64-v8a

@daltzctr
Copy link
Contributor

Doing -p:SelfContained=false seems to be another workaround preserving default architecture targets, but I've yet to test the binary.

@jonathanpeppers
Copy link
Member

This is likely caused by: dotnet/sdk#30038

For Android, can you use dotnet build instead of dotnet publish? publish doesn't actually do anything significant on Android -- it just copies files to $(PublishDir).

@jonathanpeppers jonathanpeppers self-assigned this Jun 20, 2023
jonathanpeppers added a commit to jonathanpeppers/xamarin-android that referenced this issue Jun 20, 2023
Fixes: dotnet/maui#15696
Context: dotnet/sdk#30038

In .NET 8 Preview 5, there are various changes to default values:

* `dotnet publish` is now `Release` by default

* Builds that provide a `$(RuntimeIdentifier)` are no longer "self
  contained" by default.

The result of this change is the problem:

    dotnet new android
    dotnet publish
    Microsoft.NET.RuntimeIdentifierInference.targets(212,5): error NETSDK1191: A runtime identifier for the property 'SelfContained' couldn't be inferred. Specify a rid explicitly.

While these commands all work:

    dotnet build
    dotnet build -c Release
    dotnet publish -c Debug
    dotnet publish -r android-arm64

`Debug` configurations work fine, because trimming is not involved.
`dotnet build` works fine, because the offending default appears to be:

https://github.com/dotnet/sdk/blob/540b197311bc8d1c2a991fed1b935b094a4d7b2d/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.RuntimeIdentifierInference.targets#L64-L76

`Microsoft.NET.RuntimeIdentifierInference.targets` has a lot of MSBuild
validation logic, that its main job is to emit nice error messages for
incorrect combinations of MSBuild properties/settings.

Android is kind of the odd one out when you compare to .NET console
apps, NativeAOT, etc.:

* We default to `RuntimeIdentifiers=android-arm;android-arm64;android-x86;android-x64`.

* We do our own "inner build" for each `RuntimeIdentifier`.

* Inside our build we force `$(SelfContained)` to `true` no matter what.
  As there is no such thing as a system-wide .NET on Android.

The fix appears to be to default `PublishSelfContained=false` and let
our existing logic force `SelfContained=true`.

I added a new test for this scenario. Our existing test didn't work
because it was passing a `RuntimeIdentifier`.
@jonathanpeppers
Copy link
Member

For now, the workarounds are:

  • Use dotnet build instead
  • Set <PublishSelfContained>false</PublishSelfContained> or <SelfContained>false</SelfContained> in your .csproj, the Android build forces SelfContained=true no matter what.

There isn't a non-self-contained Android app, as that would imply some kind of system-wide .NET package from Google Play, etc. that runs on Android. We don't have such a thing.

jonathanpeppers added a commit to dotnet/android that referenced this issue Jun 20, 2023
Fixes: dotnet/maui#15696
Context: dotnet/sdk#30038

In .NET 8 Preview 5, there are various changes to default values:

* `dotnet publish` is now `Release` by default

* Builds that provide a `$(RuntimeIdentifier)` are no longer "self
  contained" by default.

The result of this change is the problem:

    dotnet new android
    dotnet publish
    Microsoft.NET.RuntimeIdentifierInference.targets(212,5): error NETSDK1191: A runtime identifier for the property 'SelfContained' couldn't be inferred. Specify a rid explicitly.

While these commands all work:

    dotnet build
    dotnet build -c Release
    dotnet publish -c Debug
    dotnet publish -r android-arm64

`Debug` configurations work fine, because trimming is not involved.
`dotnet build` works fine, because the offending default appears to be:

https://github.com/dotnet/sdk/blob/540b197311bc8d1c2a991fed1b935b094a4d7b2d/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.RuntimeIdentifierInference.targets#L64-L76

`Microsoft.NET.RuntimeIdentifierInference.targets` has a lot of MSBuild
validation logic, that its main job is to emit nice error messages for
incorrect combinations of MSBuild properties/settings.

Android is kind of the odd one out when you compare to .NET console
apps, NativeAOT, etc.:

* We default to `RuntimeIdentifiers=android-arm;android-arm64;android-x86;android-x64`.

* We do our own "inner build" for each `RuntimeIdentifier`.

* Inside our build we force `$(SelfContained)` to `true` no matter what.
  As there is no such thing as a system-wide .NET on Android.

The fix appears to be to default `PublishSelfContained=false` and let
our existing logic force `SelfContained=true`.

I added a new test for this scenario. Our existing test didn't catch this
because it was passing a `RuntimeIdentifier`.
@inforithmics
Copy link
Contributor Author

inforithmics commented Jun 21, 2023

Setting <SelfContained>false</SelfContained> in the csproj worked - Thanks.

@ghost ghost locked as resolved and limited conversation to collaborators Jul 21, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-publishing Issues with the app packaging/publishing process (ipk/apk/msix/trimming) platform/android 🤖 t/bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants