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] use a custom Resource.designer.cs #2606

Merged
merged 1 commit into from
Sep 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions DEVELOPMENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,32 @@ To build and run WinUI 3 support, please install the additional components menti
dotnet tool restore
dotnet cake --target=VS-WINUI
```

### Android
Copy link
Member Author

@jonathanpeppers jonathanpeppers Sep 21, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@PureWeen are you the one that would know: How often do you add new @(AndroidResource) files?

Are the steps below reasonable?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rarely, especially once we're GA

I'd say these steps are fine

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As luck would have it, I have a PR currently open that this will break :-)

So, I'll be able to give the steps a test right after merging.


To workaround a performance issue, all `Resource.designer.cs`
generation is disabled for class libraries in this repo.

If you need to add a new `@(AndroidResource)` value to be used from C#
code in .NET MAUI:

1. Comment out the `<PropertyGroup>` in `Directory.Build.targets` that
sets `$(AndroidGenerateResourceDesigner)` and
`$(AndroidUseIntermediateDesignerFile)` to `false`.

2. Build .NET MAUI as you normally would. You will get compiler errors
about duplicate fields, but `obj\Debug\net6.0-android\Resource.designer.cs`
should now be generated.

3. Open `obj\Debug\net6.0-android\Resource.designer.cs`, and find the
field you need such as:

```csharp
// aapt resource value: 0x7F010000
public static int foo = 2130771968;
```

4. Copy this field to the `Resource.designer.cs` checked into source
control, such as: `src\Controls\src\Core\Platform\Android\Resource.designer.cs`

5. Restore the commented code in `Directory.Build.targets`.
9 changes: 9 additions & 0 deletions Directory.Build.targets
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,15 @@
<Import Project="eng\AndroidX.targets" />
<Import Project="eng\Microsoft.Extensions.targets" />

<!--
Comment out this section if you need to update Resource.designer.cs files.
See DEVELOPMENT.md#Android for details.
-->
<PropertyGroup Condition="'$(TargetPlatformIdentifier)' == 'Android' and '$(AndroidApplication)' != 'true'">
<AndroidGenerateResourceDesigner>false</AndroidGenerateResourceDesigner>
<AndroidUseIntermediateDesignerFile>false</AndroidUseIntermediateDesignerFile>
</PropertyGroup>

<!-- HACK: Prevent the Platform checks -->
<Target Name="BinPlaceBootstrapDll" />

Expand Down
143 changes: 143 additions & 0 deletions src/Compatibility/Core/src/Android/Resource.designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

140 changes: 140 additions & 0 deletions src/Controls/src/Core/Platform/Android/Resource.designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading