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

Add _AndroidLibraryProjectImportsCache to FileWrites #7780

Merged
merged 2 commits into from
Feb 15, 2023

Conversation

dellis1972
Copy link
Contributor

@dellis1972 dellis1972 commented Feb 8, 2023

On occasion we see the following error when building a Maui app.

MyMauiApp/Platforms/Android/AndroidManifest.xml : error APT2260: resource style/Maui.SplashTheme
(aka com.companyname.mymauiapp:style/Maui.SplashTheme) not found.

Looking in detail at te build log we notice that NONE of the resources in the $(IntermediateOutputPath)\lp folder
are being included in the call to aapt2. Looking further we see two very important lines

Skipping target "_ResolveLibraryProjectImports" because all output files are up-to-date with respect to the input files.

Task "ReadLibraryProjectImportsCache" (TaskId:184)
Task Parameter:CacheFile=obj/Debug/net7.0-android/libraryprojectimports.cache (TaskId:184)
Task ReadLibraryProjectImportsCache (TaskId:184)
    CacheFile: obj/Debug/net7.0-android/libraryprojectimports.cache (TaskId:184)
   obj/Debug/net7.0-android/libraryprojectimports.cache does not exist. No Project Library Imports found (TaskId:184)
 Done executing task "ReadLibraryProjectImportsCache". (TaskId:184)

So in this case it seems that the .cache file which stores the list of resource directories was created, but was then
deleted later on. A search of our build system shows that this case file was never added to the FileWrites ItemGroup.
As a result it gets deleted, but the .stamp file which controls _ResolveLibraryProjectImports is left in place. We end up in a situation where the target which generates the cache will NEVER run again because its stamp file is present.
Only a full Clean will fix this issue.

Copy link
Member

@jonathanpeppers jonathanpeppers left a comment

Choose a reason for hiding this comment

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

Is there a way to test? Maybe we could delete $(_AndroidLibraryProjectImportsCache) in a test and do an incremental build?

@dellis1972
Copy link
Contributor Author

Is there a way to test? Maybe we could delete $(_AndroidLibraryProjectImportsCache) in a test and do an incremental build?

Not sure that would help in this senario. Deleting the file manually in a test would just cause the issue, once you get into that situation I'm not sure there is a way out of it. We could change the Outputs of _ResolveLibraryProjectImports to depend on the cache file rather than a stamp file. That would allow the build to "recover" if the file was deleted.

@dellis1972
Copy link
Contributor Author

This PR is more about stopping it happening in the first place, rather than recover from I guess.

@jonpryor jonpryor merged commit c9ff96f into dotnet:main Feb 15, 2023
@dellis1972 dellis1972 deleted the Aapt2MissingTheme branch February 15, 2023 20:15
grendello added a commit to grendello/xamarin-android that referenced this pull request Feb 15, 2023
* main:
  [Xamarin.Android.Build.Tasks] FileWrites&libraryprojectimports.cache (dotnet#7780)
  Bump to dotnet/installer@d25a3bb 8.0.100-preview.2.23105.6 (dotnet#7769)
grendello added a commit to grendello/xamarin-android that referenced this pull request Feb 17, 2023
* main:
  [tests] Bump NUnit versions to latest (dotnet#7802)
  [Microsoft.Android.Sdk.ILLink] target `net7.0` temporarily (dotnet#7803)
  [tests] `InstallAndroidDependenciesTest` can use `platform-tools` 34.0.0 (dotnet#7800)
  Bump to xamarin/Java.Interop/main@9e0a469 (dotnet#7797)
  [Xamarin.Android.Build.Tasks] FileWrites&libraryprojectimports.cache (dotnet#7780)
  Bump to dotnet/installer@d25a3bb 8.0.100-preview.2.23105.6 (dotnet#7769)
  [lgtm] Fix LGTM-reported issues (dotnet#1074)
  [ci] Report issues in the API docs build log (dotnet#7784)
grendello added a commit to grendello/xamarin-android that referenced this pull request Feb 22, 2023
* main:
  [tests] Bump NUnit versions to latest (dotnet#7802)
  [Microsoft.Android.Sdk.ILLink] target `net7.0` temporarily (dotnet#7803)
  [tests] `InstallAndroidDependenciesTest` can use `platform-tools` 34.0.0 (dotnet#7800)
  Bump to xamarin/Java.Interop/main@9e0a469 (dotnet#7797)
  [Xamarin.Android.Build.Tasks] FileWrites&libraryprojectimports.cache (dotnet#7780)
  Bump to dotnet/installer@d25a3bb 8.0.100-preview.2.23105.6 (dotnet#7769)
grendello added a commit to grendello/xamarin-android that referenced this pull request Feb 22, 2023
* main:
  Add Unit Test for testOnly apps (dotnet#7637)
  [build] Only build the latest API level (dotnet#7786)
  [Xamarin.Android.Build.Tasks] Improve aapt2+file not found handling (dotnet#7644)
  [MSBuildDeviceIntegration] Fix duplicated test parameter (dotnet#7809)
  [tests] Bump NUnit versions to latest (dotnet#7802)
  [Microsoft.Android.Sdk.ILLink] target `net7.0` temporarily (dotnet#7803)
  [tests] `InstallAndroidDependenciesTest` can use `platform-tools` 34.0.0 (dotnet#7800)
  Bump to xamarin/Java.Interop/main@9e0a469 (dotnet#7797)
  [Xamarin.Android.Build.Tasks] FileWrites&libraryprojectimports.cache (dotnet#7780)
  Bump to dotnet/installer@d25a3bb 8.0.100-preview.2.23105.6 (dotnet#7769)
grendello added a commit to grendello/xamarin-android that referenced this pull request Feb 22, 2023
* main:
  Add Unit Test for testOnly apps (dotnet#7637)
  [build] Only build the latest API level (dotnet#7786)
  [Xamarin.Android.Build.Tasks] Improve aapt2+file not found handling (dotnet#7644)
  [MSBuildDeviceIntegration] Fix duplicated test parameter (dotnet#7809)
  [tests] Bump NUnit versions to latest (dotnet#7802)
  [Microsoft.Android.Sdk.ILLink] target `net7.0` temporarily (dotnet#7803)
  [tests] `InstallAndroidDependenciesTest` can use `platform-tools` 34.0.0 (dotnet#7800)
  Bump to xamarin/Java.Interop/main@9e0a469 (dotnet#7797)
  [Xamarin.Android.Build.Tasks] FileWrites&libraryprojectimports.cache (dotnet#7780)
  Bump to dotnet/installer@d25a3bb 8.0.100-preview.2.23105.6 (dotnet#7769)
  [lgtm] Fix LGTM-reported issues (dotnet#1074)
  [ci] Report issues in the API docs build log (dotnet#7784)
jonathanpeppers pushed a commit that referenced this pull request Mar 10, 2023
…7780)

On occasion we see the following error when building a Maui app:

	MyMauiApp/Platforms/Android/AndroidManifest.xml : error APT2260: resource style/Maui.SplashTheme (aka com.companyname.mymauiapp:style/Maui.SplashTheme) not found.

Looking in detail at the build log we notice that *none* of the
resources in the `$(IntermediateOutputPath)\lp` folder are being
included in the call to `aapt2`.

Looking further we see:

	Skipping target "_ResolveLibraryProjectImports" because all output files are up-to-date with respect to the input files.
	…
	Task "ReadLibraryProjectImportsCache" (TaskId:184)
	Task Parameter:CacheFile=obj/Debug/net7.0-android/libraryprojectimports.cache (TaskId:184)
	Task ReadLibraryProjectImportsCache (TaskId:184)
	    CacheFile: obj/Debug/net7.0-android/libraryprojectimports.cache (TaskId:184)
	   obj/Debug/net7.0-android/libraryprojectimports.cache does not exist. No Project Library Imports found (TaskId:184)
	Done executing task "ReadLibraryProjectImportsCache". (TaskId:184)

In this case it seems that the `.cache` file which stores the list of
resource directories was created, but was then deleted later on!

A search of our build system shows that `libraryprojectimports.cache`
was never added to the `@(FileWrites)` ItemGroup.  As a result
`libraryprojectimports.cache` gets deleted, but the `.stamp` file
which controls `_ResolveLibraryProjectImports` is left in place.
We end up in a situation where the target which generates the cache
will *never* run again because its stamp file is present.

Only a full Clean will fix this issue.

Fix this situation by updating the `_ResolveLibraryProjectImports`
target to add `libraryprojectimports.cache` to the `@(FileWrites)`
group, which prevents MSBuild from (occasionally) deleting the file
on [incremental clean][0].

[0]: https://github.com/xamarin/xamarin-android/blob/6cd0d38989178e1c3e5e1d71505b4aef26a1739b/Documentation/guides/MSBuildBestPractices.md#filewrites-and-incrementalclean
@github-actions github-actions bot locked and limited conversation to collaborators Jan 23, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants