forked from dotnet/android
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Xamarin.Android.Build.Tasks] Special Char Support (dotnet#6273)
What would we like? The ability for Xamarin.Android projects to reside in directories containing non-ASCII characters. The problem(s)? For starters, many Android SDK utilities don't support non-ASCII characters when running on Windows, e.g.: * https://issuetracker.google.com/issues/188679588 Android Studio (kinda/sorta) "enforces" this, showing a warning message when **Save location** contains non-ASCII characters: ![Android Studio New Project dialog with non-ASCII characters](https://user-images.githubusercontent.com/184788/134550831-b5c5335a-11ca-4296-b30c-cb54e3302917.png) > Save location: /tmp/テスト > … >⚠️ Your project location contains non-ASCII characters. These are not particularly encouraging foundations. Improve support for non-ASCII characters by updating various parts of our build system to: 1. Prefer *relatives* paths when possible, as we can ensure ASCII-only paths this way, and 2. "Otherwise" change *how* we invoke Android tools to avoid their use of full paths and directory traversal. Additionally, we've long used GNU Binutils to build `libxamarin-app.so` (commit decfbcc, fc3f028, others), and we discovered that Binutils 2.36 introduced [code][0] to deal extra long path names on Windows which makes compilation (in our case using `as`) and linking to break if the source/object files reside in a directory which has non-ASCII characters (in our case they were `テスト`): Xamarin.Android.Common.targets(1887,3): error XA3006: Could not compile native assembly file: typemaps.armeabi-v7a.s [SmokeTestBuildWithSpecialCharactersFalse\テスト\テスト.csproj] [aarch64-linux-android-as.EXE stderr] Assembler messages: (TaskId:187) [aarch64-linux-android-as.EXE stderr] Fatal error: can't create typemaps.arm64-v8a.o: Invalid argument (TaskId:187) Downgrade to Binutils 2.35.2, which doesn't contain the offending code block and will work for us, so long as we use relative paths. It will **still** break with full paths if the path contains special characters, but since our use case involves only relative paths, this is fine. There is also a bug in [`aapt2`][1] which stops it processing a directory which has certain special characters on Windows. This will only appear on projects which have library resources, such as Xamarin.Forms. The problem only appears when processing a directory into a `.flata` archive. Oddly it works fine when processing a file directly. In order to work around this we now generate a resource only `res.zip` file when we extract the library resources. `res.zip` is then used during the generation of the `.flata` archive. Weirdly, this works where directory transversal does not. Additionally it seems to be slightly quicker during incremental builds: * Before 581 ms Aapt2Compile 1 calls * After 366 ms Aapt2Compile 1 calls So the time taken to generate the `res.zip` is offset by the quicker execution of `aapt2 compile`. Finally, Java tooling such as `zipalign` and `apksigner` also failed with the special characters. This was because we were using full paths to the files we were signing/aligning. Switching over to use relative paths fixes this particular problem. Add a set of Unit tests to make sure we can handle the special characters. [0]: https://sourceware.org/git/?p=binutils-gdb.git;a=blob;f=bfd/bfdio.c;h=463b3879c52ba6beac47190f8eb0810b0c330e65;hb=HEAD#l124 [1]: https://issuetracker.google.com/issues/188679588
- Loading branch information
1 parent
e244cbf
commit fd5f31c
Showing
11 changed files
with
113 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters