-
Notifications
You must be signed in to change notification settings - Fork 538
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 check for java reserved works in AndroidResource items #9537
Conversation
src/Xamarin.Android.Build.Tasks/Tasks/CheckForInvalidResourceFileNames.cs
Outdated
Show resolved
Hide resolved
src/Xamarin.Android.Build.Tasks/Tasks/CheckForInvalidResourceFileNames.cs
Outdated
Show resolved
Hide resolved
Fix space before paren, use `$@"…"` strings so `\` doesn't need escaping.
/azp run |
Azure Pipelines successfully started running 1 pipeline(s). |
Draft commit message: Context: /~https://github.com/dotnet/android/issues/9461
[Android Resource names become Java identifiers][0], so if you have
an image named `Resources/drawable/import.png`, *eventually* this
will become part of an `R.java` file with contents:
/* partial */ class R {
public static class drawable {
public static final int import = 0xdeadbeef;
}
}
at which point `javac` gets irate, because `import` is a Java keyword
and that's not a valid location for that keyword.
Other Android tooling also knows about and respects this limitation,
e.g. `aapt2`, which could report:
…com\example\app\R.java: error APT2258: invalid symbol name 'com.example.app:drawable/import'.
This isn't something we can fix; Java keywords cannot be used as
Android Resource names.
What we *can* do is improve the UX, and explicitly call this out.
Introduce a new error `APT0004` error which will explicitly check for
Java keywords in resource filenames. This will allow users to know
why their build is failing:
error APT0004: Invalid file name: Filenames cannot use Java reserved words.
[0]: https://developer.android.com/guide/topics/resources/providing-resources#Accessing |
@dellis1972: while it's good to capture the filename case, that's not the only place where Resource names can appear and become Java identifiers. Two more places that come to mind are:
Can we check for these other occurrences as well? Should that be done as part of this PR, or separately? |
Lets do this in a new PR. The current task does not process the actual files. Plus we might need to take into account custom classes which happen later in the build system. |
Context #9461
Some users are seeing the following error from
aapt2
.This is because
import
is a java reserved word. Theaapt2
code generator is not taking that into account (like we do for C# designer.cs). As a result we get this error. Its not very helpful.So lets introduce a new error
APT0004
which will explicitly check for java keywords in resource filenames.This will allow users to know why their build is failing.