-
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
D8 and R8 Integration #2040
Comments
TODO: Spec has been updated above. |
This proposal is very well done and covers the bases. I find it to be very straight-forward and sensible. 👍 One note on The history of the flavors of For our current implementation of Similar to Just a generic question, what is the sensible default from a project perspective? From what I understand, |
Both of them
In the future, projects could default to: <Project>
<PropertyGroup>
<AndroidDexGenerator>d8</AndroidDexGenerator>
</PropertyGroup>
</Project> This would use I'm not sure if using |
Thanks for the clarification. I was thinking along the same lines. I believe the current default is d8 and opt-ing into r8 via flag. ( |
does d8 have issues with enabling If i mess with the settings with Desugaring in the csproj i get errors like here and here. This doc and the links i shared are the closest i get to this bug. |
@gmoney494 That initial support is a bit old using a 0.2.1 version of d8. In comparison, the latest version is 1.3.20. I would recommend waiting for our official support of d8/r8 as outlined in this issue. This will ensure the proper tool chain is used for desugaring and multidex. |
@JonDouglas where can i find the latest nuget packages for those? I only went up to 0.2.1 because of what was available, last published by @atsushieno . And how long until this becomes the official support? I cant wait too long to get past this issue. |
Fixes: #2143 Context: #1639 Xamarin.Android's current implementation of desugar runs a command such as: java -jar desugar_deploy.jar --bootclasspath_entry ~\android-toolchain\sdk\platforms\android-28\android.jar --min_sdk_version 11 --classpath_entry xamarin-android\bin\Debug\lib\xamarin.android\xbuild-frameworks\MonoAndroid\v9.0\mono.android.jar --input Lambda.jar --output obj\Debug\android\bin\desugared\14-57-25-90-94-EE-16-09-B8-68-88-BC-9D-FC-6C-89Lambda.jar However, certain jars are failing with messages such as: Exception in thread "main" java.lang.TypeNotPresentException: Type okhttp3.Interceptor not present Or another example: Error: java.lang.TypeNotPresentException : Type io.reactivex.functions.Action not present The first fix here is to add the `--classpath_entry` flag for every `--input`, for some reason `Desugar` is not treating `--input` jars as classpath entries? Next, we expanded on the `BuildTest.Desugar` test using a complicated set of Java libraries from Maven central: proj.OtherBuildItems.Add (new BuildItem ("AndroidJavaLibrary", "okio-1.13.0.jar") { WebContent = "http://central.maven.org/maven2/com/squareup/okio/okio/1.13.0/okio-1.13.0.jar" }); proj.OtherBuildItems.Add (new BuildItem ("AndroidJavaLibrary", "okhttp-3.8.0.jar") { WebContent = "http://central.maven.org/maven2/com/squareup/okhttp3/okhttp/3.8.0/okhttp-3.8.0.jar" }); proj.OtherBuildItems.Add (new BuildItem ("AndroidJavaLibrary", "retrofit-2.3.0.jar") { WebContent = "http://central.maven.org/maven2/com/squareup/retrofit2/retrofit/2.3.0/retrofit-2.3.0.jar" }); proj.OtherBuildItems.Add (new BuildItem ("AndroidJavaLibrary", "converter-gson-2.3.0.jar") { WebContent = "http://central.maven.org/maven2/com/squareup/retrofit2/converter-gson/2.3.0/converter-gson-2.3.0.jar" }); proj.OtherBuildItems.Add (new BuildItem ("AndroidJavaLibrary", "gson-2.7.jar") { WebContent = "http://central.maven.org/maven2/com/google/code/gson/gson/2.7/gson-2.7.jar" }); proj.OtherBuildItems.Add (new BuildItem ("AndroidAarLibrary", "twitter-core-3.3.0.aar") { WebContent = "http://repo.spring.io/libs-release/com/twitter/sdk/android/twitter-core/3.3.0/twitter-core-3.3.0.aar", }); This was working, as long as you had `android:minSdkVersion="24"` in your `AndroidManifest.xml`. This wasn't ideal if you wanted to run your app on older API levels... Luckily, another command line switched solved this problem: //Added to the Desugar MSBuild task if (minApiVersion < 24) { cmd.AppendSwitch("--desugar_try_with_resources_omit_runtime_classes "); } What a crazy name for a flag! Documented by `desugar` as: --[no]desugar_try_with_resources_omit_runtime_classes (a boolean; default: "false") Omits the runtime classes necessary to support try-with-resources from the output. This property has effect only if -- desugar_try_with_resources_if_needed is used. --min_sdk_version (an integer; default: "1") Minimum targeted sdk version. If >= 24, enables default methods in interfaces. This makes sense that something would happen at API level 24... Once doing this, the `Desugar` test passes without modifying `minSdkVersion`. The expanded `Desugar` test will also greatly help with our D8/R8 implementation (#2040). This complex set of Java dependencies from Maven will be useful.
Fixes: dotnet#1423 Fixes: dotnet#2040 WIP * Using r8 version 1.2.48: https://r8.googlesource.com/r8/+/1.2.48
Fixes: dotnet#1423 Fixes: dotnet#2040 [WIP] Changes in Sprint 141: * Using r8 version 1.2.48: https://r8.googlesource.com/r8/+/1.2.48 * Split the `R8` MSBuild task into `D8` and `R8` tasks. * Fixed `Configuration` property, should be `Debug="$(AndroidIncludeDebugSymbols)"` * Renamed `R8JarPath` and `R8ExtraArguments` * Added `D8andR8.md` specification / Documentation * Updated MSBuild property naming as per spec * Added `--no-daemon` for gradle calls, to fix file-locking on Windows Co-authored-by: Atsushi Eno <[email protected]>
Fixes: dotnet#1423 Fixes: dotnet#2040 [WIP] Changes in Sprint 142: * Using r8 version 1.2.48: https://r8.googlesource.com/r8/+/1.2.48 * Split the `R8` MSBuild task into `D8` and `R8` tasks. * Fixed `Configuration` property, should be `Debug="$(AndroidIncludeDebugSymbols)"` * Renamed `R8JarPath` and `R8ExtraArguments` * Added `D8andR8.md` specification / Documentation * Updated MSBuild property naming as per spec * Added `--no-daemon` for gradle calls, to fix file-locking on Windows * Support `JavaOptions` and `JavaMaximumHeapSize` * Call `<D8 />` separate from `<R8 />` * Support `<Proguard />` + `<D8 />` * Fixed broken multi-dex test * Generating multidex.keep file with r8 now, when d8 is used TODO: * `MultiDexCustomMainDexFileList(true)` test is failing with `Illegal main-dex-list entry 'MyTest'.` * Response file support with D8/R8 * General MSBuild targets cleanup. I want to move some subset of stuff to a new file. Co-authored-by: Atsushi Eno <[email protected]>
Fixes: dotnet#1423 Fixes: dotnet#2040 [WIP] Changes in Sprint 142: * Using r8 version 1.2.48: https://r8.googlesource.com/r8/+/1.2.48 * Split the `R8` MSBuild task into `D8` and `R8` tasks. * Fixed `Configuration` property, should be `Debug="$(AndroidIncludeDebugSymbols)"` * Renamed `R8JarPath` and `R8ExtraArguments` * Added `D8andR8.md` specification / Documentation * Updated MSBuild property naming as per spec * Added `--no-daemon` for gradle calls, to fix file-locking on Windows * Support `JavaOptions` and `JavaMaximumHeapSize` * Call `<D8 />` separate from `<R8 />` * Support `<Proguard />` + `<D8 />` * Fixed broken multi-dex test * Generating multidex.keep file with r8 now, when d8 is used * Expanded upon `MultiDexCustomMainDexFileList` to use d8 TODO: * Response file support with D8/R8 * General MSBuild targets cleanup. I want to move some subset of stuff to a new file. Co-authored-by: Atsushi Eno <[email protected]>
Fixes: dotnet#1423 Fixes: dotnet#2040 [WIP] Changes in Sprint 142: * Using r8 version 1.2.48: https://r8.googlesource.com/r8/+/1.2.48 * Split the `R8` MSBuild task into `D8` and `R8` tasks. * Fixed `Configuration` property, should be `Debug="$(AndroidIncludeDebugSymbols)"` * Renamed `R8JarPath` and `R8ExtraArguments` * Added `D8andR8.md` specification / Documentation * Updated MSBuild property naming as per spec * Added `--no-daemon` for gradle calls, to fix file-locking on Windows * Support `JavaOptions` and `JavaMaximumHeapSize` * Call `<D8 />` separate from `<R8 />` * Support `<Proguard />` + `<D8 />` * Fixed broken multi-dex test * Generating multidex.keep file with r8 now, when d8 is used * Expanded upon `MultiDexCustomMainDexFileList` to use d8 TODO: * General MSBuild targets cleanup. I want to move some subset of stuff to a new file. Co-authored-by: Atsushi Eno <[email protected]>
Fixes: dotnet#1423 Fixes: dotnet#2040 [WIP] Changes in Sprint 142: * Using r8 version 1.2.48: https://r8.googlesource.com/r8/+/1.2.48 * Split the `R8` MSBuild task into `D8` and `R8` tasks. * Fixed `Configuration` property, should be `Debug="$(AndroidIncludeDebugSymbols)"` * Renamed `R8JarPath` and `R8ExtraArguments` * Added `D8andR8.md` specification / Documentation * Updated MSBuild property naming as per spec * Added `--no-daemon` for gradle calls, to fix file-locking on Windows * Support `JavaOptions` and `JavaMaximumHeapSize` * Call `<D8 />` separate from `<R8 />` * Support `<Proguard />` + `<D8 />` * Fixed broken multi-dex test * Generating multidex.keep file with r8 now, when d8 is used * Expanded upon `MultiDexCustomMainDexFileList` to use d8 * Put all d8/r8 related MSBuild targets in a new `Xamarin.Android.D8.targets` file TODO: * TEST! * Profile dx / proguard vs d8 / r8 * Write a real commit message, drop all WIP/do-not-merge labels Co-authored-by: Atsushi Eno <[email protected]>
Fixes: dotnet#1423 Fixes: dotnet#2040 [WIP] Changes in Sprint 142: * Using r8 version 1.2.48: https://r8.googlesource.com/r8/+/1.2.48 * Split the `R8` MSBuild task into `D8` and `R8` tasks. * Fixed `Configuration` property, should be `Debug="$(AndroidIncludeDebugSymbols)"` * Renamed `R8JarPath` and `R8ExtraArguments` * Added `D8andR8.md` specification / Documentation * Updated MSBuild property naming as per spec * Added `--no-daemon` for gradle calls, to fix file-locking on Windows * Support `JavaOptions` and `JavaMaximumHeapSize` * Call `<D8 />` separate from `<R8 />` * Support `<Proguard />` + `<D8 />` * Fixed broken multi-dex test * Generating multidex.keep file with r8 now, when d8 is used * Expanded upon `MultiDexCustomMainDexFileList` to use d8 * Put all d8/r8 related MSBuild targets in a new `Xamarin.Android.D8.targets` file TODO: * TEST! * Profile dx / proguard vs d8 / r8 * Write a real commit message, drop all WIP/do-not-merge labels Co-authored-by: Atsushi Eno <[email protected]>
Fixes: dotnet#1423 Fixes: dotnet#2040 ~~ Overview ~~ This enables d8 and r8 integration for Xamarin.Android. d8 is a "next-generation" dex compiler (over dx), and r8 is a replacement for proguard. For full details on the feature, see `Documentation/guides/D8andR8.md`. ~~ MSBuild targets changes ~~ New MSBuild properties include: - `$(AndroidDexGenerator)` - an enum-style property with options: `dx` and `d8`. Defaults to `dx`. - `$(AndroidLinkTool)` - an enum-style property, that can be left blank to disable code shrinking. Valid values are `proguard` and `r8`. Existing MSBuild properties still retain the old behavior: - `$(AndroidEnableProguard)` will set `$(AndroidLinkTool)` to `proguard`, although it is no longer used internally by Xamarin.Android targets. - `$(AndroidEnableDesugar)` will default to `true` if `d8` or `r8` are used. New MSBuild tasks include: - `<D8 />` - runs `d8.jar` with the required options for Xamarin.Android. - `<R8 />` - subclasses `<D8 />`, and adds functionality for multi-dex and code-shrinking. Additionally, any new MSBuild targets are placed in a new `Xamarin.Android.D8.targets` file. This is good first step to make `Xamarin.Android.Common.targets` smaller. Additionally: * `build.props` is now invalidated via the `$(AndroidDexGenerator)` and `$(AndroidLinkTool)` properties, instead of `$(AndroidEnableProguard)` * `build.props` is invalidated via `$(AndroidEnableDesugar)` ~~ Test changes ~~ Tests that need to validate various combinations of properties are now using parameters such as: [Values ("dx", "d8")] string dexGenerator, [Values ("", "proguard", "r8")] string linkTool Set on the `XamarinAndroidApplicationProject` such as: var proj = new XamarinAndroidApplicationProject { DexGenerator = dexGenerator, LinkTool = linkTool, }; In other cases, a simple `useD8` flag was added to set `DexGenerator="d8"`. Since adding test parameters, exponentially causes our test cases to expand, I removed some non-essential parameters: - `BuildProguardEnabledProject` dropped `useLatestSdk`, as it does not seem applicable here (and is deprecated). Otherwise would have 24 test cases... - `BuildApplicationWithSpacesInPath` dropped `isRelease` and defaulted it to `true`. We aren't going to likely encounter issues with spaces in a path that happen *only* in a `Debug` build. Otherwise we would have 24 test cases here... - `Desugar` dropped `enableDesugar` because it is certain this application project will not build *without* desugar. We don't need to test this, and would have 24 test cases otherwise... Also dropped some `[TestCaseSource]` attributes where the `[Values]` parameter was much cleaner. ~~ Changes to test/sample projects ~~ `HelloWorld` - `$(AndroidDexGenerator)` set to `d8` if unspecified. So we can track the performance benefit. `Xamarin.Forms Integration` - uses `d8` and `$(AndroidLinkTool)` set to `r8`, using a `proguard.cfg` file for Xamarin.Forms. Will help us track startup performance benefits of Java code shrinking and build performance. `Mono.Android-Tests` - uses `d8` and `$(AndroidLinkTool)` set to `r8`, to verify these on-device tests pass. `Runtime-MultiDex` - `$(AndroidDexGenerator)` set to `d8` if unspecified, to validate multi-dex is working properly with `d8`. ~~ Xamarin.Android build changes ~~ This adds https://r8.googlesource.com/r8 as a submodule in `external/r8`, and builds `d8.jar` and `r8.jar` via `src/r8/r8.csproj`. Currently using version 1.2.48 of r8. ~~ Deployment changes ~~ Three new files will need to be included in Xamarin.Android installers: - `d8.jar` - `r8.jar` - `Xamarin.Android.D8.targets` ~~ General changes ~~ * Fixed doc for `xa4304` error code * Added `xa4305` error code for `CompileToDalvik`, `R8`, and `CreateMultiDexMainDexClassList` * Removed log messages in `CreateMultiDexMainDexClassList` Co-authored-by: Atsushi Eno <[email protected]>
Fixes: dotnet#1423 Fixes: dotnet#2040 ~~ Overview ~~ This enables d8 and r8 integration for Xamarin.Android. d8 is a "next-generation" dex compiler (over dx), and r8 is a replacement for proguard. For full details on the feature, see `Documentation/guides/D8andR8.md`. ~~ MSBuild targets changes ~~ New MSBuild properties include: - `$(AndroidDexGenerator)` - an enum-style property with options: `dx` and `d8`. Defaults to `dx`. - `$(AndroidLinkTool)` - an enum-style property, that can be left blank to disable code shrinking. Valid values are `proguard` and `r8`. Existing MSBuild properties still retain the old behavior: - `$(AndroidEnableProguard)` will set `$(AndroidLinkTool)` to `proguard`, although it is no longer used internally by Xamarin.Android targets. - `$(AndroidEnableDesugar)` will default to `true` if `d8` or `r8` are used. New MSBuild tasks include: - `<D8 />` - runs `d8.jar` with the required options for Xamarin.Android. - `<R8 />` - subclasses `<D8 />`, and adds functionality for multi-dex and code-shrinking. Additionally, any new MSBuild targets are placed in a new `Xamarin.Android.D8.targets` file. This is good first step to make `Xamarin.Android.Common.targets` smaller. Additionally: * `build.props` is now invalidated via the `$(AndroidDexGenerator)` and `$(AndroidLinkTool)` properties, instead of `$(AndroidEnableProguard)` * `build.props` is invalidated via `$(AndroidEnableDesugar)` ~~ Test changes ~~ Tests that need to validate various combinations of properties are now using parameters such as: [Values ("dx", "d8")] string dexGenerator, [Values ("", "proguard", "r8")] string linkTool Set on the `XamarinAndroidApplicationProject` such as: var proj = new XamarinAndroidApplicationProject { DexGenerator = dexGenerator, LinkTool = linkTool, }; In other cases, a simple `useD8` flag was added to set `DexGenerator="d8"`. Since adding test parameters, exponentially causes our test cases to expand, I removed some non-essential parameters: - `BuildProguardEnabledProject` dropped `useLatestSdk`, as it does not seem applicable here (and is deprecated). Otherwise would have 24 test cases... - `BuildApplicationWithSpacesInPath` dropped `isRelease` and defaulted it to `true`. We aren't going to likely encounter issues with spaces in a path that happen *only* in a `Debug` build. Otherwise we would have 24 test cases here... - `Desugar` dropped `enableDesugar` because it is certain this application project will not build *without* desugar. We don't need to test this, and would have 24 test cases otherwise... Also dropped some `[TestCaseSource]` attributes where the `[Values]` parameter was much cleaner. ~~ Changes to test/sample projects ~~ `HelloWorld` - `$(AndroidDexGenerator)` set to `d8` if unspecified. So we can track the performance benefit. `Xamarin.Forms Integration` - uses `d8` and `$(AndroidLinkTool)` set to `r8`, using a `proguard.cfg` file for Xamarin.Forms. Will help us track startup performance benefits of Java code shrinking and build performance. `Mono.Android-Tests` - uses `d8` and `$(AndroidLinkTool)` set to `r8`, to verify these on-device tests pass. `Runtime-MultiDex` - `$(AndroidDexGenerator)` set to `d8` if unspecified, to validate multi-dex is working properly with `d8`. ~~ Xamarin.Android build changes ~~ This adds https://r8.googlesource.com/r8 as a submodule in `external/r8`, and builds `d8.jar` and `r8.jar` via `src/r8/r8.csproj`. Currently using version 1.2.48 of r8. ~~ Deployment changes ~~ Three new files will need to be included in Xamarin.Android installers: - `d8.jar` - `r8.jar` - `Xamarin.Android.D8.targets` ~~ General changes ~~ * Fixed doc for `xa4304` error code * Added `xa4305` error code for `CompileToDalvik`, `R8`, and `CreateMultiDexMainDexClassList` * Removed log messages in `CreateMultiDexMainDexClassList` ~~ Performance Comparison ~~ | MSBuild Target | Options Enabled | Time | APK size (bytes) | dex size (bytes) | | --- | --- | ---: | ---: | ---: | | _CompileToDalvikWithDx | n/a | 11074ms | 13378157 | 3894720 | | _CompileToDalvikWithD8 | d8, (desugar enabled) | 8543ms | 13124205 | 3314064 | | _CompileToDalvikWithD8 | d8, (desugar disabled) | 9550ms | 13124205 | 3314064 | | _CompileToDalvikWithDx | multi-dex | 15632ms | 13390498 | 3916496 | | _CompileToDalvikWithD8 | d8, multi-dex | 25979ms | 13054626 | 3264096 | | _CompileToDalvikWithDx | proguard | 11903ms | 12804717 | 2446964 | | _CompileToDalvikWithD8 | d8, r8 | 13799ms | 12513901 | 1835588 | | _CompileToDalvikWithDx | multi-dex, proguard | 17279ms | 12804770 | 2449512 | | _CompileToDalvikWithD8 | d8, multi-dex, r8 | 13792ms | 12513954 | 1837588 | _NOTE: desugar is enabled by default with d8/r8_ I timed this builds with [this script][powershell_script], with a "Hello World" Xamarin.Forms app. Build logs here: [d8andr8.zip][d8andr8_zip] One can draw their own conclusions on which options are faster, better, smaller. See further detail in `D8andR8.md`. [powershell_script]: https://github.com/jonathanpeppers/HelloWorld/blob/39e2854f6ca39c0941fb8bd6f2a16d8b7663003e/build.ps1 [d8andr8_zip]: https://github.com/xamarin/xamarin-android/files/2470385/d8andr8.zip Co-authored-by: Atsushi Eno <[email protected]>
Please fix because we cannot use the latest ExoPlayer. |
Fixes: dotnet#1423 Fixes: dotnet#2040 ~~ Overview ~~ This enables d8 and r8 integration for Xamarin.Android. d8 is a "next-generation" dex compiler (over dx), and r8 is a replacement for proguard. For full details on the feature, see `Documentation/guides/D8andR8.md`. ~~ MSBuild targets changes ~~ New MSBuild properties include: - `$(AndroidDexTool)` - an enum-style property with options: `dx` and `d8`. Defaults to `dx`. - `$(AndroidLinkTool)` - an enum-style property, that can be left blank to disable code shrinking. Valid values are `proguard` and `r8`. Existing MSBuild properties still retain the old behavior: - `$(AndroidEnableProguard)` will set `$(AndroidLinkTool)` to `proguard`, although it is no longer used internally by Xamarin.Android targets. - `$(AndroidEnableDesugar)` will default to `true` if `d8` or `r8` are used. New MSBuild tasks include: - `<D8 />` - runs `d8.jar` with the required options for Xamarin.Android. - `<R8 />` - subclasses `<D8 />`, and adds functionality for multi-dex and code-shrinking. Additionally, any new MSBuild targets are placed in a new `Xamarin.Android.D8.targets` file. This is good first step to make `Xamarin.Android.Common.targets` smaller. Additionally: * `build.props` is now invalidated via the `$(AndroidDexTool)` and `$(AndroidLinkTool)` properties, instead of `$(AndroidEnableProguard)` * `build.props` is invalidated via `$(AndroidEnableDesugar)` ~~ Test changes ~~ Tests that need to validate various combinations of properties are now using parameters such as: [Values ("dx", "d8")] string dexTool, [Values ("", "proguard", "r8")] string linkTool Set on the `XamarinAndroidApplicationProject` such as: var proj = new XamarinAndroidApplicationProject { DexTool = dexTool, LinkTool = linkTool, }; In other cases, a simple `useD8` flag was added to set `DexTool="d8"`. Since adding test parameters, exponentially causes our test cases to expand, I removed some non-essential parameters: - `BuildProguardEnabledProject` dropped `useLatestSdk`, as it does not seem applicable here (and is deprecated). Otherwise would have 24 test cases... - `BuildApplicationWithSpacesInPath` dropped `isRelease` and defaulted it to `true`. We aren't going to likely encounter issues with spaces in a path that happen *only* in a `Debug` build. Otherwise we would have 24 test cases here... - `Desugar` dropped `enableDesugar` because it is certain this application project will not build *without* desugar. We don't need to test this, and would have 24 test cases otherwise... Also dropped some `[TestCaseSource]` attributes where the `[Values]` parameter was much cleaner. ~~ Changes to test/sample projects ~~ `HelloWorld` - `$(AndroidDexTool)` set to `d8` if unspecified. So we can track the performance benefit. `Xamarin.Forms Integration` - uses `d8` and `$(AndroidLinkTool)` set to `r8`, using a `proguard.cfg` file for Xamarin.Forms. Will help us track startup performance benefits of Java code shrinking and build performance. `Mono.Android-Tests` - uses `d8` and `$(AndroidLinkTool)` set to `r8`, to verify these on-device tests pass. `Runtime-MultiDex` - `$(AndroidDexTool)` set to `d8` if unspecified, to validate multi-dex is working properly with `d8`. ~~ Xamarin.Android build changes ~~ This adds https://r8.googlesource.com/r8 as a submodule in `external/r8`, and builds `d8.jar` and `r8.jar` via `src/r8/r8.csproj`. Currently using version 1.2.50 of r8. ~~ Deployment changes ~~ Three new files will need to be included in Xamarin.Android installers: - `d8.jar` - `r8.jar` - `Xamarin.Android.D8.targets` ~~ General changes ~~ * Fixed doc for `xa4304` error code * Added `xa4305` error code for `CompileToDalvik`, `R8`, and `CreateMultiDexMainDexClassList` * Removed log messages in `CreateMultiDexMainDexClassList` ~~ Performance Comparison ~~ | MSBuild Target | Options Enabled | Time | APK size (bytes) | dex size (bytes) | | --- | --- | ---: | ---: | ---: | | _CompileToDalvikWithDx | n/a | 11074ms | 13378157 | 3894720 | | _CompileToDalvikWithD8 | d8, (desugar enabled) | 8543ms | 13124205 | 3314064 | | _CompileToDalvikWithD8 | d8, (desugar disabled) | 9550ms | 13124205 | 3314064 | | _CompileToDalvikWithDx | multi-dex | 15632ms | 13390498 | 3916496 | | _CompileToDalvikWithD8 | d8, multi-dex | 25979ms | 13054626 | 3264096 | | _CompileToDalvikWithDx | proguard | 11903ms | 12804717 | 2446964 | | _CompileToDalvikWithD8 | d8, r8 | 13799ms | 12513901 | 1835588 | | _CompileToDalvikWithDx | multi-dex, proguard | 17279ms | 12804770 | 2449512 | | _CompileToDalvikWithD8 | d8, multi-dex, r8 | 13792ms | 12513954 | 1837588 | _NOTE: desugar is enabled by default with d8/r8_ I timed this builds with [this script][powershell_script], with a "Hello World" Xamarin.Forms app. Build logs here: [d8andr8.zip][d8andr8_zip] One can draw their own conclusions on which options are faster, better, smaller. See further detail in `D8andR8.md`. [powershell_script]: https://github.com/jonathanpeppers/HelloWorld/blob/39e2854f6ca39c0941fb8bd6f2a16d8b7663003e/build.ps1 [d8andr8_zip]: https://github.com/xamarin/xamarin-android/files/2470385/d8andr8.zip Co-authored-by: Atsushi Eno <[email protected]>
Any idea when this is going to land? These changes are needed in combination with dotnet/java-interop#341 and dotnet/java-interop#25 |
Fixes: dotnet#1423 Fixes: dotnet#2040 ~~ Overview ~~ This enables d8 and r8 integration for Xamarin.Android. d8 is a "next-generation" dex compiler (over dx), and r8 is a replacement for proguard. For full details on the feature, see `Documentation/guides/D8andR8.md`. ~~ MSBuild targets changes ~~ New MSBuild properties include: - `$(AndroidDexTool)` - an enum-style property with options: `dx` and `d8`. Defaults to `dx`. - `$(AndroidLinkTool)` - an enum-style property, that can be left blank to disable code shrinking. Valid values are `proguard` and `r8`. Existing MSBuild properties still retain the old behavior: - `$(AndroidEnableProguard)` will set `$(AndroidLinkTool)` to `proguard`, although it is no longer used internally by Xamarin.Android targets. - `$(AndroidEnableDesugar)` will default to `true` if `d8` or `r8` are used. New MSBuild tasks include: - `<D8 />` - runs `d8.jar` with the required options for Xamarin.Android. - `<R8 />` - subclasses `<D8 />`, and adds functionality for multi-dex and code-shrinking. Additionally, any new MSBuild targets are placed in a new `Xamarin.Android.D8.targets` file. This is good first step to make `Xamarin.Android.Common.targets` smaller. Additionally: * `build.props` is now invalidated via the `$(AndroidDexTool)` and `$(AndroidLinkTool)` properties, instead of `$(AndroidEnableProguard)` * `build.props` is invalidated via `$(AndroidEnableDesugar)` ~~ Test changes ~~ Tests that need to validate various combinations of properties are now using parameters such as: [Values ("dx", "d8")] string dexTool, [Values ("", "proguard", "r8")] string linkTool Set on the `XamarinAndroidApplicationProject` such as: var proj = new XamarinAndroidApplicationProject { DexTool = dexTool, LinkTool = linkTool, }; In other cases, a simple `useD8` flag was added to set `DexTool="d8"`. Since adding test parameters, exponentially causes our test cases to expand, I removed some non-essential parameters: - `BuildProguardEnabledProject` dropped `useLatestSdk`, as it does not seem applicable here (and is deprecated). Otherwise would have 24 test cases... - `BuildApplicationWithSpacesInPath` dropped `isRelease` and defaulted it to `true`. We aren't going to likely encounter issues with spaces in a path that happen *only* in a `Debug` build. Otherwise we would have 24 test cases here... - `Desugar` dropped `enableDesugar` because it is certain this application project will not build *without* desugar. We don't need to test this, and would have 24 test cases otherwise... Also dropped some `[TestCaseSource]` attributes where the `[Values]` parameter was much cleaner. ~~ Changes to test/sample projects ~~ `HelloWorld` - `$(AndroidDexTool)` set to `d8` if unspecified. So we can track the performance benefit. `Xamarin.Forms Integration` - uses `d8` and `$(AndroidLinkTool)` set to `r8`, using a `proguard.cfg` file for Xamarin.Forms. Will help us track startup performance benefits of Java code shrinking and build performance. `Mono.Android-Tests` - uses `d8` and `$(AndroidLinkTool)` set to `r8`, to verify these on-device tests pass. `Runtime-MultiDex` - `$(AndroidDexTool)` set to `d8` if unspecified, to validate multi-dex is working properly with `d8`. ~~ Xamarin.Android build changes ~~ This adds https://r8.googlesource.com/r8 as a submodule in `external/r8`, and builds `d8.jar` and `r8.jar` via `src/r8/r8.csproj`. Currently using version 1.2.50 of r8. ~~ Deployment changes ~~ Three new files will need to be included in Xamarin.Android installers: - `d8.jar` - `r8.jar` - `Xamarin.Android.D8.targets` ~~ General changes ~~ * Fixed doc for `xa4304` error code * Added `xa4305` error code for `CompileToDalvik`, `R8`, and `CreateMultiDexMainDexClassList` * Removed log messages in `CreateMultiDexMainDexClassList` ~~ Performance Comparison ~~ | MSBuild Target | Options Enabled | Time | APK size (bytes) | dex size (bytes) | | --- | --- | ---: | ---: | ---: | | _CompileToDalvikWithDx | n/a | 11074ms | 13378157 | 3894720 | | _CompileToDalvikWithD8 | d8, (desugar enabled) | 8543ms | 13124205 | 3314064 | | _CompileToDalvikWithD8 | d8, (desugar disabled) | 9550ms | 13124205 | 3314064 | | _CompileToDalvikWithDx | multi-dex | 15632ms | 13390498 | 3916496 | | _CompileToDalvikWithD8 | d8, multi-dex | 25979ms | 13054626 | 3264096 | | _CompileToDalvikWithDx | proguard | 11903ms | 12804717 | 2446964 | | _CompileToDalvikWithD8 | d8, r8 | 13799ms | 12513901 | 1835588 | | _CompileToDalvikWithDx | multi-dex, proguard | 17279ms | 12804770 | 2449512 | | _CompileToDalvikWithD8 | d8, multi-dex, r8 | 13792ms | 12513954 | 1837588 | _NOTE: desugar is enabled by default with d8/r8_ I timed this builds with [this script][powershell_script], with a "Hello World" Xamarin.Forms app. Build logs here: [d8andr8.zip][d8andr8_zip] One can draw their own conclusions on which options are faster, better, smaller. See further detail in `D8andR8.md`. [powershell_script]: https://github.com/jonathanpeppers/HelloWorld/blob/39e2854f6ca39c0941fb8bd6f2a16d8b7663003e/build.ps1 [d8andr8_zip]: https://github.com/xamarin/xamarin-android/files/2470385/d8andr8.zip Co-authored-by: Atsushi Eno <[email protected]>
Fixes: dotnet#1423 Fixes: dotnet#2040 ~~ Overview ~~ This enables d8 and r8 integration for Xamarin.Android. d8 is a "next-generation" dex compiler (over dx), and r8 is a replacement for proguard. For full details on the feature, see `Documentation/guides/D8andR8.md`. ~~ MSBuild targets changes ~~ New MSBuild properties include: - `$(AndroidDexTool)` - an enum-style property with options: `dx` and `d8`. Defaults to `dx`. - `$(AndroidLinkTool)` - an enum-style property, that can be left blank to disable code shrinking. Valid values are `proguard` and `r8`. Existing MSBuild properties still retain the old behavior: - `$(AndroidEnableProguard)` will set `$(AndroidLinkTool)` to `proguard`, although it is no longer used internally by Xamarin.Android targets. - `$(AndroidEnableDesugar)` will default to `true` if `d8` or `r8` are used. New MSBuild tasks include: - `<D8 />` - runs `d8.jar` with the required options for Xamarin.Android. - `<R8 />` - subclasses `<D8 />`, and adds functionality for multi-dex and code-shrinking. Additionally, any new MSBuild targets are placed in a new `Xamarin.Android.D8.targets` file. This is good first step to make `Xamarin.Android.Common.targets` smaller. Additionally: * `build.props` is now invalidated via the `$(AndroidDexTool)` and `$(AndroidLinkTool)` properties, instead of `$(AndroidEnableProguard)` * `build.props` is invalidated via `$(AndroidEnableDesugar)` ~~ Test changes ~~ Tests that need to validate various combinations of properties are now using parameters such as: [Values ("dx", "d8")] string dexTool, [Values ("", "proguard", "r8")] string linkTool Set on the `XamarinAndroidApplicationProject` such as: var proj = new XamarinAndroidApplicationProject { DexTool = dexTool, LinkTool = linkTool, }; In other cases, a simple `useD8` flag was added to set `DexTool="d8"`. Since adding test parameters, exponentially causes our test cases to expand, I removed some non-essential parameters: - `BuildProguardEnabledProject` dropped `useLatestSdk`, as it does not seem applicable here (and is deprecated). Otherwise would have 24 test cases... - `BuildApplicationWithSpacesInPath` dropped `isRelease` and defaulted it to `true`. We aren't going to likely encounter issues with spaces in a path that happen *only* in a `Debug` build. Otherwise we would have 24 test cases here... - `Desugar` dropped `enableDesugar` because it is certain this application project will not build *without* desugar. We don't need to test this, and would have 24 test cases otherwise... Also dropped some `[TestCaseSource]` attributes where the `[Values]` parameter was much cleaner. ~~ Changes to test/sample projects ~~ `HelloWorld` - `$(AndroidDexTool)` set to `d8` if unspecified. So we can track the performance benefit. `Xamarin.Forms Integration` - uses `d8` and `$(AndroidLinkTool)` set to `r8`, using a `proguard.cfg` file for Xamarin.Forms. Will help us track startup performance benefits of Java code shrinking and build performance. `Mono.Android-Tests` - uses `d8` and `$(AndroidLinkTool)` set to `r8`, to verify these on-device tests pass. `Runtime-MultiDex` - `$(AndroidDexTool)` set to `d8` if unspecified, to validate multi-dex is working properly with `d8`. ~~ Xamarin.Android build changes ~~ This adds https://r8.googlesource.com/r8 as a submodule in `external/r8`, and builds `d8.jar` and `r8.jar` via `src/r8/r8.csproj`. Currently using version 1.2.50 of r8. ~~ Deployment changes ~~ Three new files will need to be included in Xamarin.Android installers: - `d8.jar` - `r8.jar` - `Xamarin.Android.D8.targets` ~~ General changes ~~ * Fixed doc for `xa4304` error code * Added `xa4305` error code for `CompileToDalvik`, `R8`, and `CreateMultiDexMainDexClassList` * Removed log messages in `CreateMultiDexMainDexClassList` ~~ Performance Comparison ~~ | MSBuild Target | Options Enabled | Time | APK size (bytes) | dex size (bytes) | | --- | --- | ---: | ---: | ---: | | _CompileToDalvikWithDx | n/a | 11074ms | 13378157 | 3894720 | | _CompileToDalvikWithD8 | d8, (desugar enabled) | 8543ms | 13124205 | 3314064 | | _CompileToDalvikWithD8 | d8, (desugar disabled) | 9550ms | 13124205 | 3314064 | | _CompileToDalvikWithDx | multi-dex | 15632ms | 13390498 | 3916496 | | _CompileToDalvikWithD8 | d8, multi-dex | 25979ms | 13054626 | 3264096 | | _CompileToDalvikWithDx | proguard | 11903ms | 12804717 | 2446964 | | _CompileToDalvikWithD8 | d8, r8 | 13799ms | 12513901 | 1835588 | | _CompileToDalvikWithDx | multi-dex, proguard | 17279ms | 12804770 | 2449512 | | _CompileToDalvikWithD8 | d8, multi-dex, r8 | 13792ms | 12513954 | 1837588 | _NOTE: desugar is enabled by default with d8/r8_ I timed this builds with [this script][powershell_script], with a "Hello World" Xamarin.Forms app. Build logs here: [d8andr8.zip][d8andr8_zip] One can draw their own conclusions on which options are faster, better, smaller. See further detail in `D8andR8.md`. [powershell_script]: https://github.com/jonathanpeppers/HelloWorld/blob/39e2854f6ca39c0941fb8bd6f2a16d8b7663003e/build.ps1 [d8andr8_zip]: https://github.com/xamarin/xamarin-android/files/2470385/d8andr8.zip Co-authored-by: Atsushi Eno <[email protected]>
Fixes: dotnet#1423 Fixes: dotnet#2040 ~~ Overview ~~ This enables d8 and r8 integration for Xamarin.Android. d8 is a "next-generation" dex compiler (over dx), and r8 is a replacement for proguard. For full details on the feature, see `Documentation/guides/D8andR8.md`. ~~ MSBuild targets changes ~~ New MSBuild properties include: - `$(AndroidDexTool)` - an enum-style property with options: `dx` and `d8`. Defaults to `dx`. - `$(AndroidLinkTool)` - an enum-style property, that can be left blank to disable code shrinking. Valid values are `proguard` and `r8`. Existing MSBuild properties still retain the old behavior: - `$(AndroidEnableProguard)` will set `$(AndroidLinkTool)` to `proguard`, although it is no longer used internally by Xamarin.Android targets. - `$(AndroidEnableDesugar)` will default to `true` if `d8` or `r8` are used. New MSBuild tasks include: - `<D8 />` - runs `d8.jar` with the required options for Xamarin.Android. - `<R8 />` - subclasses `<D8 />`, and adds functionality for multi-dex and code-shrinking. Additionally, any new MSBuild targets are placed in a new `Xamarin.Android.D8.targets` file. This is good first step to make `Xamarin.Android.Common.targets` smaller. Additionally: * `build.props` is now invalidated via the `$(AndroidDexTool)` and `$(AndroidLinkTool)` properties, instead of `$(AndroidEnableProguard)` * `build.props` is invalidated via `$(AndroidEnableDesugar)` ~~ Test changes ~~ Tests that need to validate various combinations of properties are now using parameters such as: [Values ("dx", "d8")] string dexTool, [Values ("", "proguard", "r8")] string linkTool Set on the `XamarinAndroidApplicationProject` such as: var proj = new XamarinAndroidApplicationProject { DexTool = dexTool, LinkTool = linkTool, }; In other cases, a simple `useD8` flag was added to set `DexTool="d8"`. Since adding test parameters, exponentially causes our test cases to expand, I removed some non-essential parameters: - `BuildProguardEnabledProject` dropped `useLatestSdk`, as it does not seem applicable here (and is deprecated). Otherwise would have 24 test cases... - `BuildApplicationWithSpacesInPath` dropped `isRelease` and defaulted it to `true`. We aren't going to likely encounter issues with spaces in a path that happen *only* in a `Debug` build. Otherwise we would have 24 test cases here... - `Desugar` dropped `enableDesugar` because it is certain this application project will not build *without* desugar. We don't need to test this, and would have 24 test cases otherwise... Also dropped some `[TestCaseSource]` attributes where the `[Values]` parameter was much cleaner. ~~ Changes to test/sample projects ~~ `HelloWorld` - `$(AndroidDexTool)` set to `d8` if unspecified. So we can track the performance benefit. `Xamarin.Forms Integration` - uses `d8` and `$(AndroidLinkTool)` set to `r8`, using a `proguard.cfg` file for Xamarin.Forms. Will help us track startup performance benefits of Java code shrinking and build performance. `Mono.Android-Tests` - uses `d8` and `$(AndroidLinkTool)` set to `r8`, to verify these on-device tests pass. `Runtime-MultiDex` - `$(AndroidDexTool)` set to `d8` if unspecified, to validate multi-dex is working properly with `d8`. ~~ Xamarin.Android build changes ~~ This adds https://r8.googlesource.com/r8 as a submodule in `external/r8`, and builds `d8.jar` and `r8.jar` via `src/r8/r8.csproj`. Currently using version 1.2.50 of r8. ~~ Deployment changes ~~ Three new files will need to be included in Xamarin.Android installers: - `d8.jar` - `r8.jar` - `Xamarin.Android.D8.targets` ~~ General changes ~~ * Fixed doc for `xa4304` error code * Added `xa4305` error code for `CompileToDalvik`, `R8`, and `CreateMultiDexMainDexClassList` * Removed log messages in `CreateMultiDexMainDexClassList` ~~ Performance Comparison ~~ | MSBuild Target | Options Enabled | Time | APK size (bytes) | dex size (bytes) | | --- | --- | ---: | ---: | ---: | | _CompileToDalvikWithDx | n/a | 11074ms | 13378157 | 3894720 | | _CompileToDalvikWithD8 | d8, (desugar enabled) | 8543ms | 13124205 | 3314064 | | _CompileToDalvikWithD8 | d8, (desugar disabled) | 9550ms | 13124205 | 3314064 | | _CompileToDalvikWithDx | multi-dex | 15632ms | 13390498 | 3916496 | | _CompileToDalvikWithD8 | d8, multi-dex | 25979ms | 13054626 | 3264096 | | _CompileToDalvikWithDx | proguard | 11903ms | 12804717 | 2446964 | | _CompileToDalvikWithD8 | d8, r8 | 13799ms | 12513901 | 1835588 | | _CompileToDalvikWithDx | multi-dex, proguard | 17279ms | 12804770 | 2449512 | | _CompileToDalvikWithD8 | d8, multi-dex, r8 | 13792ms | 12513954 | 1837588 | _NOTE: desugar is enabled by default with d8/r8_ I timed this builds with [this script][powershell_script], with a "Hello World" Xamarin.Forms app. Build logs here: [d8andr8.zip][d8andr8_zip] One can draw their own conclusions on which options are faster, better, smaller. See further detail in `D8andR8.md`. [powershell_script]: https://github.com/jonathanpeppers/HelloWorld/blob/39e2854f6ca39c0941fb8bd6f2a16d8b7663003e/build.ps1 [d8andr8_zip]: https://github.com/xamarin/xamarin-android/files/2470385/d8andr8.zip Co-authored-by: Atsushi Eno <[email protected]>
Fixes: #1423 Fixes: #2040 Bumps to r8/d8-1.2@125b72. ~~ Overview ~~ This enables `d8` and `r8` integration for Xamarin.Android. `d8` is a "next-generation" dex compiler (over `dx`), and `r8` is a replacement for ProGuard. For full details on the feature, see `Documentation/guides/D8andR8.md`. ~~ MSBuild targets changes ~~ New MSBuild properties include: - `$(AndroidDexTool)` - an enum-style property with options `dx` and `d8`. Defaults to `dx`. - `$(AndroidLinkTool)` - an enum-style property, that can be left blank to disable code shrinking. Valid values are `proguard` and `r8`. Existing MSBuild properties still retain the old behavior: - `$(AndroidEnableProguard)` will set `$(AndroidLinkTool)` to `proguard`, although it is no longer used internally by Xamarin.Android targets. - `$(AndroidEnableDesugar)` will default to `true` if `d8` or `r8` are used. New MSBuild tasks include: - `<D8/>`: runs `d8.jar` with the required options for Xamarin.Android. - `<R8/>`: subclasses `<D8/>`, and adds functionality for multi-dex and code-shrinking. Additionally, any new MSBuild targets are placed in a new `Xamarin.Android.D8.targets` file. This is good first step to make `Xamarin.Android.Common.targets` smaller. Additionally: * `build.props` is now invalidated via the `$(AndroidDexTool)` and `$(AndroidLinkTool)` properties, instead of `$(AndroidEnableProguard)` * `build.props` is invalidated via `$(AndroidEnableDesugar)` * Refactored `$(IntermediateOutputPath)_dex_stamp` stamp file in `_CompileToDalvikWithDx` and `_CompileToDalvikWithD8` to match the new convention of `$(_AndroidStampDirectory)_CompileToDalvik.stamp` * `*.dex` files weren't in `@(FileWrites)`?! * `<CompileToDalvik/>` had a `DexOutputs` output property that was completely unused, so I removed it. Also removed extra log messages. ~~ Test changes ~~ Tests that need to validate various combinations of properties are now using parameters such as: [Values ("dx", "d8")] string dexTool, [Values ("", "proguard", "r8")] string linkTool Set on the `XamarinAndroidApplicationProject` such as: var proj = new XamarinAndroidApplicationProject { DexTool = dexTool, LinkTool = linkTool, }; In other cases, a simple `useD8` flag was added to set `DexTool="d8"`. Since adding test parameters, exponentially causes our test cases to expand, I removed some non-essential parameters: - `BuildProguardEnabledProject()` dropped `useLatestSdk`, as it does not seem applicable here (and is deprecated). Otherwise would have 24 test cases... - `BuildApplicationWithSpacesInPath()` dropped `isRelease` and defaulted it to `true`. We aren't going to likely encounter issues with spaces in a path that happen *only* in a `Debug` build. Otherwise we would have 24 test cases here... - `Desugar()` dropped `enableDesugar` because it is certain this application project will not build *without* desugar. We don't need to test this, and would have 24 test cases otherwise... Also dropped some `[TestCaseSource]` attributes where the `[Values]` parameter was much cleaner. ~~ Changes to test/sample projects ~~ `HelloWorld` - `$(AndroidDexTool)` set to `d8` if unspecified, so we can track the performance benefit. `Xamarin.Forms Integration` - uses `d8` and `$(AndroidLinkTool)` set to `r8`, using a `proguard.cfg` file for Xamarin.Forms. Will help us track startup performance benefits of Java code shrinking and build performance. `Mono.Android-Tests` - uses `d8` and `$(AndroidLinkTool)` set to `r8`, to verify these on-device tests pass. `Runtime-MultiDex` - `$(AndroidDexTool)` set to `d8` if unspecified, to validate multi-dex is working properly with `d8`. ~~ xamarin-android build changes ~~ The `<DownloadUri/>` MSBuild task now has an optional `HashHeader` property. When set, an http HEAD request is made to the URL, and the destination file path gets a suffix added for the value. `DownloadUri.DestinationFiles` is changed to an `[Output]` property, as the destination paths could change due to the `HashHeader`. Chromium's `depot_tools` are downloaded the same as all of our other dependencies. As the `depot_tools` distribution filename is unversioned, we use the `x-goog-hash` header to derive a "version" so that we don't needlessly download the file. ~~ Deployment changes ~~ Three new files will need to be included in Xamarin.Android installers: - `d8.jar` - `r8.jar` - `Xamarin.Android.D8.targets` ~~ General changes ~~ * Fixed doc for `xa4304` error code * Added `xa4305` error code for `CompileToDalvik`, `R8`, and `<CreateMultiDexMainDexClassList/>` * Removed log messages in `<CreateMultiDexMainDexClassList/>` ~~ Performance Comparison ~~ | MSBuild Target | Options Enabled | Time | APK size (bytes) | dex size (bytes) | | --- | --- | ---: | ---: | ---: | | _CompileToDalvikWithDx | n/a | 11074ms | 13378157 | 3894720 | | _CompileToDalvikWithD8 | d8, (desugar enabled) | 8543ms | 13124205 | 3314064 | | _CompileToDalvikWithD8 | d8, (desugar disabled) | 9550ms | 13124205 | 3314064 | | _CompileToDalvikWithDx | multi-dex | 15632ms | 13390498 | 3916496 | | _CompileToDalvikWithD8 | d8, multi-dex | 25979ms | 13054626 | 3264096 | | _CompileToDalvikWithDx | proguard | 11903ms | 12804717 | 2446964 | | _CompileToDalvikWithD8 | d8, r8 | 13799ms | 12513901 | 1835588 | | _CompileToDalvikWithDx | multi-dex, proguard | 17279ms | 12804770 | 2449512 | | _CompileToDalvikWithD8 | d8, multi-dex, r8 | 13792ms | 12513954 | 1837588 | *NOTE: desugar is enabled by default with d8/r8* I timed this builds with [this script][powershell_script], with a "Hello World" Xamarin.Forms app. Build logs here: [d8andr8.zip][d8andr8_zip] One can draw their own conclusions on which options are faster, better, smaller. See further detail in `D8andR8.md`. [powershell_script]: https://github.com/jonathanpeppers/HelloWorld/blob/39e2854f6ca39c0941fb8bd6f2a16d8b7663003e/build.ps1 [d8andr8_zip]: https://github.com/xamarin/xamarin-android/files/2470385/d8andr8.zip Co-authored-by: Atsushi Eno <[email protected]>
This is the D8 and R8 integration specification for Xamarin.Android.
What is D8? What is R8?
At a high level, here are the steps that occur during an Android application's Java compilation:
javac
compiles Java codedesugar
remove's the "sugar" (from Java 8 features) that are not fully supported on Androidproguard
shrinks compiled Java codedx
"dexes" compiled Java code into Android dex format. This is an alternate Java bytecode format supported by the Android platform.This process has a few issues, such as:
dx
is slower than it could beSo in 2017, Google announced a "next-generation" dex compiler named D8.
dx
proguard
, that also "dexes" at the same time. If using R8, a D8 call is not needed.Both tools have support for various other Android-specifics:
desugar
by default unless the--no-desugaring
switch is specifiedmultidex.keep
file, thatproguard
can generateAdditionally, R8 is geared to be backwards compatible to
proguard
. It uses the same file format for configuration and command-line parameters asproguard
. However, at the time of writing this, there are still several flags/features not implemented in R8 yet.For more information on how R8 compares to
proguard
, see a great article written by theproguard
team here.You can find the source for D8 and R8 here.
For reference,
d8 --help
:For reference,
r8 --help
:What does Xamarin.Android do now?
In other words, what is currently happening before we introduce D8/R8 support?
*.java
files to aclasses.zip
file.desugar_deploy.jar
if$(AndroidEnableDesugar)
isTrue
.$(AndroidEnableProguard)
isTrue
. Developers may also supply custom proguard configuration files viaProguardConfiguration
build items.proguard
to generate a final, combinedmultidex.keep
file if$(AndroidEnableMultiDex)
isTrue
. Developers can also supply custommultidex.keep
files viaMultiDexMainDexList
build items.dx.jar
to generate a finalclasses.dex
file in$(IntermediateOutputPath)android\bin
. Ifmultidex
is enabled, aclasses2.dex
(and potentially more) are also generated in this location.What would this process look like with D8 / R8?
Two new MSBuild tasks named
R8
andD8
will be created.R8
will be invoked to create amultidex.keep
file if$(AndroidEnableMultiDex)
isTrue
.D8
will run if$(AndroidEnableProguard)
isFalse
and "desugar" by default.R8
will run if$(AndroidEnableProguard)
isTrue
and will also "desugar" by default.So in addition to be being faster (if Google's claims are true), we will be calling less tooling to accomplish the same results.
So how do developers use it? What are sensible MSBuild property defaults?
Currently, a
csproj
file might have the following properties:To enable the new behavior, we should introduce two new enum-style properties:
$(AndroidDexGenerator)
- supportsdx
ord8
$(AndroidLinkTool)
- supportsproguard
orr8
But for an existing project, a developer could opt-in to the new behavior with two properties:
There should be two new MSBuild properties to configure here, because:
D8
in combination withproguard
, asR8
is not "feature complete" in comparison toproguard
.D8
instead ofdx
.dx
in combination withR8
, it doesn't make sense.multidex
, anddesugar
.Our reasonable defaults would be:
AndroidDexGenerator
is omitted,dx
andCompileToDalvik
should be used. Until D8/R8 integration is deemed stable and enabled by default.AndroidDexGenerator
isd8
andAndroidEnableDesugar
is omitted,AndroidEnableDesugar
should be enabled.AndroidLinkTool
is omitted andAndroidEnableProguard
istrue
, we should defaultAndroidLinkTool
toproguard
.MSBuild properties default to something like:
If a user specifies combinations of properties:
AndroidDexGenerator
=d8
andAndroidEnableProguard
=True
AndroidLinkTool
will get set toproguard
AndroidDexGenerator
=dx
andAndroidLinkTool
=r8
R8
will be called because it dexes and shrinks at the same time.AndroidEnableDesugar
is enabled when omitted, if eitherd8
orr8
are usedFor new projects that want to use D8/R8, code shrinking, and
multidex
, it would make sense to specify:Additional D8 / R8 settings?
--debug
or--release
needs to be explicitly specified for both D8 and R8. We should use the AndroidIncludeDebugSymbols property for this.$(D8ExtraArguments)
and$(R8ExtraArguments)
can be used to explicitly pass additional flags to D8 and R8.How are we compiling / shipping D8 and R8?
We will add a submodule to
xamarin-android
for r8. It should be pinned to a commit with a reasonable release tag, such as1.2.35
for now.To build r8, we have to:
depot_tools
in$PATH
gclient
so it will download/bootstrap gradle, python, and other toolspython tools\gradle.py d8 r8
to compiled8.jar
andr8.jar
d8.jar
andr8.jar
in our installers, similar to how we are shippingdesugar_deploy.jar
Current Implementation
PR #2019 is the current implementation.
However, it became clear that a lot of the ideas around D8/R8 are not formalized or known.
The goal here will be to actually explain what everything should do, before I finish the implementation.
The text was updated successfully, but these errors were encountered: