"Pause" migrating everything to a common template, and pivot to moving the remaining packages from the GPS repository to the AndroidX repository. This should enable us to eliminate the circular dependencies between the two repositories which should help fix the majority of the https://github.com/xamarin/AndroidX/issues/764 issues going forward.
Bring in the GPS and Glide templates as new "templateSet", and merge in all the build infrastructure pieces that the GPS repository had to make it build correctly.
Move the packages in GPS that use the following package-specific templates to this repository and switch them to using the default template:
- brotli
- chromium-cronet
- codehaus-mojo
- datatransport
- flatbuffers
- grpc
- opencensus
- perfmark
- protobuf-lite
- squareup-okhttp
- squareup-okhttp3
- squareup-picasso
- squareup-retrofit
- squareup-retrofit2
- squareup-okio
- squareup-javapoet
- tensorflow-lite
- user-messaging-platform
- zxing
One wrinkle is that AndroidX does not allow a stable package to depend on a prerelease package:
```xml
<!-- Warnings we want to error on: -->
<!-- NU5104: A stable release of a package should not have a prerelease dependency. -->
<WarningsAsErrors>$(WarningsAsErrors);NU5104</WarningsAsErrors>
```
Although we should always abide by this rule, we are bound by Google's packaging decisions and sometimes we have no choice. The `Xamarin.TensorFlow.Lite.Support.Api` and `Xamarin.TensorFlow.Lite.Task.Vision.PlayServices.Library` packages we are moving from GPS have a prerelease dependency. (GPS repository does not enforce this rule.)
In order to keep this rule globally, but allow packages to opt out of it, add the `allowPrereleaseDependencies` artifact-level field to `config.json`:
```json
{
"groupId": "org.tensorflow",
"artifactId": "tensorflow-lite-task-vision-play-services",
"version": "0.4.4",
"nugetVersion": "0.4.4.6",
"nugetId": "Xamarin.TensorFlow.Lite.Task.Vision.PlayServices.Library",
"allowPrereleaseDependencies": true,
"comments": "Depends on Xamarin.Google.Android.ODML.Image which only has a prerelease version.",
...
}
```
Companion PR that removes these packages from GPS: https://github.com/xamarin/GooglePlayServicesComponents/pull/906
Move the packages in GPS that use the following package-specific templates to this repository and switch them to using the default template:
- annotations
- aopalliance
- dagger
- errorprone
- findbugs
- inject-guice
- jakarta
- javax-inject
- ow2-asm
Companion PR that removes them from GPS: https://github.com/xamarin/GooglePlayServicesComponents/pull/905
- Removed `onCues` method in `Player.Listener`.
- Removed `onPositionDiscontinuity` method from `Player.Listener`.
- Added `<remove-node>` tags to address issues with `Media3.ExoPlayer`.
- Made all methods in `Player.Listener` interface abstract.
Remove the following package-specific templates in favor of using the default template:
- accompanist
- antmedia-rtpm-client
- auto-value
- dev-chrisbanes-snapper
- flogger
- napier
- reactive-streams
- rxjava
- tink
Additionally, the `Xamarin.Android.ReactiveX.RxJava` NuGet package was relying on a `<JavaSourceJar>` for some parameter names.
Add the artifact-level `documentationType` field to `config.json` that can be specified if a `<JavaSourceJar>` or `<JavaDocJar>` is needed. The default value is `none`, the values `javasource` and `javadoc` are supported.
Make 2 tweaks to the `update-config` console output. Note these do not affect anything that is written to `config.json`, just what is written to the console.
- Add number of packages and dependencies to table header:
```console
| 340 Packages (* = Has Update) | Currently Bound | Latest Stable |
|------------------------------------------------------------|-------------------|-----------------|
| androidx.activity.activity | 1.9.1 | 1.9.1 |
...
| 18 Dependencies (* = Has Update) | Current Reference | Latest Publish |
|------------------------------------------------------------|-------------------|-----------------|
| Xamarin.GooglePlayServices.Ads.Identifier | 118.1.0.1 | 118.1.0.1 |
...
```
- Show if there are updates available for "Frozen" packages. Previously it would just show as frozen and not show if there were updates available.
```console
// Previous behavior
| # com.google.android.material.material | 1.11.0 | 1.11.0 |
// New behavior
| #* com.google.android.material.material | 1.11.0 | 1.12.0 |
```
Some of the final pieces needed to start removing package-specific templates:
- We use the top level `mavenRepositoryType` to default all packages to Google's Maven, and then use the templates to override this to `MavenCentral`. Without templates we will need to specify this directly on the artifact, so add support for an artifact level `mavenRepositoryType`.
- We have several different "types" of packages that we create today:
- `EmbeddedJar` - Basic use of `<EmbeddedJar>` to include the Java payload in the NuGet package next to the managed bindings `.dll`. (This is equivalent to the preferred `<AndroidLibrary>` in .NET 6+.)
- `Targets` - Uses `<InputJar>` to create the binding `.dll` and `<None>` to add the Java payload manually into the NuGet package and uses a `.targets` file to add it to the Android application.
- `NoBindings` - Uses `<None>` to add the Java payload manually into the NuGet package and uses a `.targets` file to add it to the Android application. Does not create managed bindings.
- `XBD` - Uses `<InputJar>` to create the binding `.dll`. The Java payload is not included in the NuGet package. Instead a `.targets` file is used to download the payload at compile time using `Xamarin.Build.Download`.
The default package type is `targets`, which is what the current default template uses. That is, this is the one that all AndroidX packages currently use.
To specify a different package type, we add a new artifact level `type` attribute. The only currently supported value for this is `androidlibrary` which provides the `EmbeddedJar` package type behavior.
As a proof of concept, migrate `GoogleGson` from the `gson` template to the default template.
### Results
Before:
```json
{
"groupId": "com.google.code.gson",
"artifactId": "gson",
"version": "2.11.0",
"nugetVersion": "2.11.0.1",
"nugetId": "GoogleGson",
"dependencyOnly": false,
"templateSet": "gson"
}
```
![image](https://github.com/user-attachments/assets/968d3251-52fc-449f-a629-f28c86b44321)
After:
```json
{
"groupId": "com.google.code.gson",
"artifactId": "gson",
"version": "2.11.0",
"nugetVersion": "2.11.0.1",
"nugetId": "GoogleGson",
"dependencyOnly": false,
"type": "androidlibrary",
"mavenRepositoryType": "MavenCentral"
}
```
![image](https://github.com/user-attachments/assets/97bed63c-10c3-4827-992c-669f153f8c12)
The `update-config.csx` script should no longer be used in AndroidX repository.
Instead, use one of the following:
- `dotnet cake -t=update-config`
- `dotnet cake -t=bump-config`
- `dotnet cake -t=sort-config`
- `dotnet cake -t=published-config`
Commands are documented [here](https://github.com/xamarin/AndroidX/blob/main/BUILDING.md).
Instead of manually maintaining licensing information for packages, pull the license information from the package's POM file. This information looks like:
```xml
<licenses>
<license>
<name>The Apache Software License, Version 2.0</name>
<url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
<distribution>repo</distribution>
</license>
</licenses>
```
We need to be able to "understand" this license and properties about it, like its SPDX identifier and whether it is proprietary or not. To do this, we match the license name to a new section in `config.json`:
```json
"licenses": [
{
"name": "The Apache Software License, Version 2.0",
"file": "templates/licenses/apache-2.0.txt",
"spdx": "Apache-2.0",
"proprietary": false
}, ...
]
```
Note there may be multiple entries for the "same" license, as different POM files may give it a slightly different name.
These license entries also point to a local copy of the license text that we can use to build `THIRD-PARTY-NOTICES.txt` when `binderator` runs.
Modify the project template to include the generated `THIRD-PARTY-NOTICES.txt` which contains the correct notices for each package rather than the generic repo `External-Dependency-Info.txt` which was not correct for packages not licensed under Apache-2.0.
Finally, if the package is open source and all its license(s) have valid SPDX identifiers, calculate the compound SPDX expression and apply it to the package with `<PackageLicenseExpression>`. If not, use `<PackageLicenseFile>` instead. (SPDX doesn't allow a "proprietary" identifier.)
Note in some cases we may not be able to automatically pull license information from the POM. In these cases we can override the POM information with a new `overrideLicenses` entry on an artifact in `config.json`:
```json
"overrideLicenses": [
"Apache 2.0|http://www.apache.org/licenses/LICENSE-2.0.txt"
],
```
The format is `{license name}|{license url}`.