{"action":"created","issue":{"url":"https://api.github.com/repos/xamarin/xamarin-android/issues/2019","repository_url":"https://api.github.com/repos/xamarin/xamarin-android","labels_url":"https://api.github.com/repos/xamarin/xamarin-android/issues/2019/labels{/name}","comments_url":"https://api.github.com/repos/xamarin/xamarin-android/issues/2019/comments","events_url":"https://api.github.com/repos/xamarin/xamarin-android/issues/2019/events","html_url":"https://github.com/xamarin/xamarin-android/pull/2019","id":346021792,"node_id":"MDExOlB1bGxSZXF1ZXN0MjA0OTg2MzQ4","number":2019,"title":"D8 and R8 integration","user":{"login":"jonathanpeppers","id":840039,"node_id":"MDQ6VXNlcjg0MDAzOQ==","avatar_url":"https://avatars0.githubusercontent.com/u/840039?v=4","gravatar_id":"","url":"https://api.github.com/users/jonathanpeppers","html_url":"https://github.com/jonathanpeppers","followers_url":"https://api.github.com/users/jonathanpeppers/followers","following_url":"https://api.github.com/users/jonathanpeppers/following{/other_user}","gists_url":"https://api.github.com/users/jonathanpeppers/gists{/gist_id}","starred_url":"https://api.github.com/users/jonathanpeppers/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jonathanpeppers/subscriptions","organizations_url":"https://api.github.com/users/jonathanpeppers/orgs","repos_url":"https://api.github.com/users/jonathanpeppers/repos","events_url":"https://api.github.com/users/jonathanpeppers/events{/privacy}","received_events_url":"https://api.github.com/users/jonathanpeppers/received_events","type":"User","site_admin":false},"labels":[{"id":1048806988,"node_id":"MDU6TGFiZWwxMDQ4ODA2OTg4","url":"https://api.github.com/repos/xamarin/xamarin-android/labels/run-tests-release","name":"run-tests-release","color":"1d76db","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":7,"created_at":"2018-07-31T03:29:31Z","updated_at":"2018-10-12T13:54:50Z","closed_at":null,"author_association":"CONTRIBUTOR","pull_request":{"url":"https://api.github.com/repos/xamarin/xamarin-android/pulls/2019","html_url":"https://github.com/xamarin/xamarin-android/pull/2019","diff_url":"https://github.com/xamarin/xamarin-android/pull/2019.diff","patch_url":"https://github.com/xamarin/xamarin-android/pull/2019.patch"},"body":"Fixes: https://github.com/xamarin/xamarin-android/issues/1423\r\nFixes: https://github.com/xamarin/xamarin-android/issues/2040\r\n\r\n## Overview\r\n\r\nThis enables d8 and r8 integration for Xamarin.Android. d8 is a\r\n\"next-generation\" dex compiler (over dx), and r8 is a replacement for\r\nproguard. For full details on the feature, see\r\n`Documentation/guides/D8andR8.md`.\r\n\r\n## MSBuild targets changes\r\n\r\nNew MSBuild properties include:\r\n\r\n- `$(AndroidDexGenerator)` - an enum-style property with options: `dx`\r\n  and `d8`. Defaults to `dx`.\r\n- `$(AndroidLinkTool)` - an enum-style property, that can be left\r\n  blank to disable code shrinking. Valid values are `proguard` and\r\n  `r8`.\r\n\r\nExisting MSBuild properties still retain the old behavior:\r\n\r\n- `$(AndroidEnableProguard)` will set `$(AndroidLinkTool)` to\r\n  `proguard`, although it is no longer used internally by\r\n  Xamarin.Android targets.\r\n- `$(AndroidEnableDesugar)` will default to `true` if `d8` or `r8` are\r\n  used.\r\n\r\nNew MSBuild tasks include:\r\n\r\n- `<D8 />` - runs `d8.jar` with the required options for\r\n  Xamarin.Android.\r\n- `<R8 />` - subclasses `<D8 />`, and adds functionality for multi-dex\r\n  and code-shrinking.\r\n\r\nAdditionally, any new MSBuild targets are placed in a new\r\n`Xamarin.Android.D8.targets` file. This is good first step to make\r\n`Xamarin.Android.Common.targets` smaller.\r\n\r\nAdditionally:\r\n\r\n* `build.props` is now invalidated via the `$(AndroidDexGenerator)`\r\n  and `$(AndroidLinkTool)` properties, instead of\r\n  `$(AndroidEnableProguard)`\r\n* `build.props` is invalidated via `$(AndroidEnableDesugar)`\r\n\r\n## Test changes\r\n\r\nTests that need to validate various combinations of properties are now\r\nusing parameters such as:\r\n\r\n    [Values (\"dx\", \"d8\")] string dexGenerator, [Values (\"\", \"proguard\", \"r8\")] string linkTool\r\n\r\nSet on the `XamarinAndroidApplicationProject` such as:\r\n\r\n    var proj = new XamarinAndroidApplicationProject {\r\n        DexGenerator = dexGenerator,\r\n        LinkTool = linkTool,\r\n    };\r\n\r\nIn other cases, a simple `useD8` flag was added to set\r\n`DexGenerator=\"d8\"`.\r\n\r\nSince adding test parameters, exponentially causes our test cases to\r\nexpand, I removed some non-essential parameters:\r\n\r\n- `BuildProguardEnabledProject` dropped `useLatestSdk`, as it does not\r\n  seem applicable here (and is deprecated). Otherwise would have 24\r\n  test cases...\r\n- `BuildApplicationWithSpacesInPath` dropped `isRelease` and defaulted\r\n  it to `true`. We aren't going to likely encounter issues with spaces\r\n  in a path that happen *only* in a `Debug` build. Otherwise we would\r\n  have 24 test cases here...\r\n- `Desugar` dropped `enableDesugar` because it is certain this\r\n  application project will not build *without* desugar. We don't need\r\n  to test this, and would have 24 test cases otherwise...\r\n\r\nAlso dropped some `[TestCaseSource]` attributes where the `[Values]`\r\nparameter was much cleaner.\r\n\r\n## Changes to test/sample projects\r\n\r\n`HelloWorld` - `$(AndroidDexGenerator)` set to `d8` if unspecified. So\r\nwe can track the performance benefit.\r\n\r\n`Xamarin.Forms Integration` - uses `d8` and `$(AndroidLinkTool)` set\r\nto `r8`, using a `proguard.cfg` file for Xamarin.Forms. Will help us\r\ntrack startup performance benefits of Java code shrinking and build\r\nperformance.\r\n\r\n`Mono.Android-Tests` - uses `d8` and `$(AndroidLinkTool)` set to `r8`,\r\nto verify these on-device tests pass.\r\n\r\n`Runtime-MultiDex` - `$(AndroidDexGenerator)` set to `d8` if\r\nunspecified, to validate multi-dex is working properly with `d8`.\r\n\r\n## Xamarin.Android build changes\r\n\r\nThis adds https://r8.googlesource.com/r8 as a submodule in\r\n`external/r8`, and builds `d8.jar` and `r8.jar` via `src/r8/r8.csproj`.\r\n\r\nCurrently using version 1.2.48 of r8.\r\n\r\n## Deployment changes\r\n\r\nThree new files will need to be included in Xamarin.Android\r\ninstallers:\r\n\r\n- `d8.jar`\r\n- `r8.jar`\r\n- `Xamarin.Android.D8.targets`\r\n\r\n## General changes\r\n\r\n* Fixed doc for `xa4304` error code\r\n* Added `xa4305` error code for `CompileToDalvik`, `R8`, and\r\n  `CreateMultiDexMainDexClassList`\r\n* Removed log messages in `CreateMultiDexMainDexClassList`\r\n\r\n## Performance Comparison\r\n\r\n| MSBuild Target         | Options Enabled        | Time    | APK size (bytes) | dex size (bytes) |\r\n| ---                    | ---                    | ---:    | ---:             | ---:             |\r\n| _CompileToDalvikWithDx | n/a                    | 11074ms | 13378157         | 3894720          |\r\n| _CompileToDalvikWithD8 | d8, (desugar enabled)  | 8543ms  | 13124205         | 3314064          |\r\n| _CompileToDalvikWithD8 | d8, (desugar disabled) | 9550ms  | 13124205         | 3314064          |\r\n| _CompileToDalvikWithDx | multi-dex              | 15632ms | 13390498         | 3916496          |\r\n| _CompileToDalvikWithD8 | d8, multi-dex          | 25979ms | 13054626         | 3264096          |\r\n| _CompileToDalvikWithDx | proguard               | 11903ms | 12804717         | 2446964          |\r\n| _CompileToDalvikWithD8 | d8, r8                 | 13799ms | 12513901         | 1835588          |\r\n| _CompileToDalvikWithDx | multi-dex, proguard    | 17279ms | 12804770         | 2449512          |\r\n| _CompileToDalvikWithD8 | d8, multi-dex, r8      | 13792ms | 12513954         | 1837588          |\r\n\r\n_NOTE: desugar is enabled by default with d8/r8_\r\n\r\nI timed this builds with [this script](https://github.com/jonathanpeppers/HelloWorld/blob/39e2854f6ca39c0941fb8bd6f2a16d8b7663003e/build.ps1), with a \"Hello World\" Xamarin.Forms app. Build logs here: [d8andr8.zip](https://github.com/xamarin/xamarin-android/files/2470385/d8andr8.zip)\r\n\r\n\r\nOne can draw their own conclusions on which options are faster, better, smaller.\r\n\r\nSome of my thoughts:\r\n- Default options for d8 and r8 seem to be faster?\r\n- Disabling `desugar` is slower?\r\n- Enabling `multi-dex` makes the dex file larger, because new classes are required. The app wasn't large enough to warrant a `classes2.dex`.\r\n- `d8` does not support multi-dex, and so choosing `d8` + `multi-dex` actually runs `r8` with `--no-tree-shaking --no-minification`. These options are _slower_?"},"comment":{"url":"https://api.github.com/repos/xamarin/xamarin-android/issues/comments/429333785","html_url":"https://github.com/xamarin/xamarin-android/pull/2019#issuecomment-429333785","issue_url":"https://api.github.com/repos/xamarin/xamarin-android/issues/2019","id":429333785,"node_id":"MDEyOklzc3VlQ29tbWVudDQyOTMzMzc4NQ==","user":{"login":"jonathanpeppers","id":840039,"node_id":"MDQ6VXNlcjg0MDAzOQ==","avatar_url":"https://avatars0.githubusercontent.com/u/840039?v=4","gravatar_id":"","url":"https://api.github.com/users/jonathanpeppers","html_url":"https://github.com/jonathanpeppers","followers_url":"https://api.github.com/users/jonathanpeppers/followers","following_url":"https://api.github.com/users/jonathanpeppers/following{/other_user}","gists_url":"https://api.github.com/users/jonathanpeppers/gists{/gist_id}","starred_url":"https://api.github.com/users/jonathanpeppers/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jonathanpeppers/subscriptions","organizations_url":"https://api.github.com/users/jonathanpeppers/orgs","repos_url":"https://api.github.com/users/jonathanpeppers/repos","events_url":"https://api.github.com/users/jonathanpeppers/events{/privacy}","received_events_url":"https://api.github.com/users/jonathanpeppers/received_events","type":"User","site_admin":false},"created_at":"2018-10-12T13:54:50Z","updated_at":"2018-10-12T13:54:50Z","author_association":"CONTRIBUTOR","body":"The Windows test failures are expected, since we have 2 `BuildAotApplication*` tests that are failing on master, MacOS is green!"}}
{"actor":{"display_login":"jonathanpeppers"}}