How androidx.tech Worked

I have received inquiries as to how my former androidx.tech site worked. It offered a catalogof every Jetpack artifact version, including the source code. It was designed to be a workaroundfor the fact that Google did not offer this sort of stuff back in the day. Nowadays,maven.google.com kinda has this, insofar as it offers ���source���links (and you need to inspect for yourself which is the actual artifact source and which is sample code).

So, here is how androidx.tech worked.

Step 1: Find the POMs

Google���s Maven publications have long had links to source JARs for their artifact versionsin their POM files. The POM files also had information about dependencies that I wanted todisplay. So, I needed the POM files for all the artifacts and their versions. And, to saveme having to re-download them, I wanted to store each of those POMs locally.

The simplest solution, given this need plus the need for the source code, would be to mirrormaven.google.com. I could not figure out how to do this five years ago, and I may also havebeen concerned about how much disk space would be needed by all of this.

I created a Kotlin project, reporeader, that would traverse the artifacts in a Mavenrepository and pull their POMs. This involved:

Downloading https://dl.google.com/dl/android/mave... and parsing the XMLto get the list of artifact groups

Filtering that list to only worry about androidx. groups, as Google���s Maven repository hasa lot of other stuff as well, such as Play Services

Generating the URL for the artifact group index, which involves replacing all the .characters in the artifact group with / and using that to get a group index XML URL,such as https://dl.google.com/dl/android/mave... forandroidx.activity

Downloading and parsing that XML to get the artifacts and versions that are in thatgroup

Generating the URL for the POM, which replaces group-index.xml in the group index URLwith /$artifact/$version/$artifact-$version.pom for a given artifact name and artifactversion, giving you something likehttps://dl.google.com/dl/android/mave...

Downloading that POM

This tool also knew to emit a roster of what was new: new artifact groups, new artifact IDswithin a group, and new artifact versions. I still use this tool today, to generate thelist of changes that go into posts like this one.

Step 2: Download the Sources

A POM file is an XML file with lots of interesting info:

xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-inst..." xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.... 4.0.0 androidx.activity activity-compose 1.10.0-alpha03 aar Activity Compose Compose integration with Activity https://developer.android.com/jetpack... 2020 The Android Open Source Project The Apache Software License, Version 2.0 http://www.apache.org/licenses/LICENS... repo The Android Open Source Project scm:git:https://android.googlesource.com/plat... https://cs.android.com/androidx/platf... androidx.activity activity 1.10.0-alpha03 androidx.activity activity-ktx 1.10.0-alpha03 androidx.compose.runtime runtime-saveable 1.7.0 compile androidx.activity activity-ktx [1.10.0-alpha03] compile aar androidx.compose.runtime runtime 1.7.0 compile androidx.compose.ui ui 1.0.1 compile androidx.core core-ktx 1.13.0 compile aar org.jetbrains.kotlinx kotlinx-coroutines-core 1.7.3 runtime androidx.lifecycle lifecycle-runtime 2.6.1 runtime androidx.savedstate savedstate 1.2.1 runtime androidx.lifecycle lifecycle-viewmodel 2.6.1 compile org.jetbrains.kotlin kotlin-stdlib 1.8.22 runtime androidx.lifecycle lifecycle-common 2.6.1 runtime

However, it does not contain a link to the sources JAR for the artifact. Fortunately, Googletended to use a consistent naming convention of $artifact-$version-sources.jar. So, if I did notalready have the sources for that artifact version, I generated the URL for it(e.g., https://dl.google.com/dl/android/mave... downloaded it. Since JAR files are ZIP files, I could then use ordinary unZIP code to convertthe JAR into a directory tree of source code.

Step 3: Generate the Site

androidx.tech was a static site, generated by Jekyll. Jekyll is Ruby code and is not designedfor a site of this size, with hundreds of thousands of pages. Still, given a big enough Amazon EC2 instance,I could plow through it.

I had a separate Kotlin project, gen2, that would generate the Markdown source for the site, giventhe POM files and source trees. My publish script would then set Jekyll loose to generate thesite, and from there it was a matter of rsync to push the changes up to the actual host.

 •  0 comments  •  flag
Share on Twitter
Published on November 10, 2024 07:05
No comments have been added yet.