Working on unreleased Glean code in android-components

This is a companion to the equivalent instructions for the android-components repository.

Modern Gradle supports composite builds, which allows to substitute on-disk projects for binary publications. Composite builds transparently accomplish what is usually a frustrating loop of:

  1. change library
  2. publish library snapshot to the local Maven repository
  3. consume library snapshot in application

Preparation

Clone the Glean SDK and android-components repositories:

git clone https://github.com/mozilla/glean
git clone https://github.com/mozilla-mobile/android-components

Cargo build targets

By default when building Android Components using gradle, the rust-android plugin will compile Glean for every possible platform, which might end up in build failures. You can customize which targets are built in glean/local.properties (more information):

# For physical devices:
rust.targets=arm

# For unit tests:
# rust.targets=darwin # Or linux-*, windows-* (* = x86/x64)

# For emulator only:
rust.targets=x86

Substituting projects

android-components has custom build logic for dealing with composite builds, so you should be able to configure it by simply adding the path to the Glean repository in the correct local.properties file:

In android-components/local.properties:

autoPublish.glean.dir=../glean

This will auto-publish Glean SDK changes to a local repository and consume them in android-components.

Replacing the Glean Gradle plugin

Note: If you only need to replace the glean_parser used in the build see Substituting glean_parser. This is only necessary if you changed GleanGradlePlugin.groovy.

If you need to replace the Glean Gradle Plugin used by other components within Android Components, follow these steps:

  1. In your Glean repository increment the version number in .buildconfig.yml

    libraryVersion: 60.0.0
    
  2. Build and publish the plugin locally:

    ./gradlew publishToMavenLocal
    
  3. In the Android Components repository change the required Glean version buildSrc/src/main/java/Dependencies.kt:

    const val mozilla_glean = "60.0.0"
    
  4. In the Android Components repository add the following at the top of the settings.gradle file:

    pluginManagement {
        repositories {
            mavenLocal()
            gradlePluginPortal()
        }
    }
    

Building any component will now use your locally published Glean Gradle Plugin (and Glean SDK).