Tuesday, October 16, 2018

Hello World, Androidx

Posted past times Alan Viverette (/u/alanviverette), Kathy Kam (@kathykam) , Lukas Bergstrom (@lukasb)

Today, nosotros launch an early on preview of the novel Android extension libraries (AndroidX) which represents a novel era for the Support Library. Please preview the change as well as make us your feedback. Since this is an early on preview, nosotros practise non recommend trying this on whatever production projects equally at that topographic point are approximately known issues.

The Support Library started over 7+ years agone to render backwards compatibility to framework APIs. Over the years, the library has grown to include device-specific UX, debugging, testing as well as other utilities. The adoption of the Support Library has been phenomenal; most Android apps purpose the Support Library today. We desire to increase our investment inwards this area, as well as it is critical that nosotros lay a company foundation.

In that vein, nosotros took a measuring dorsum as well as chatted alongside many of you. The feedback has been consistent as well as unanimous; the organic growth of the library has larn confusing. There are components as well as packages named "v7" when the minimal SDK marker nosotros back upwards is 14! We desire to arrive clear for y'all to empathize the sectionalisation betwixt APIs that are bundled alongside the platform as well as which are static libraries for app developers that locomote across dissimilar versions of Android.

With that inwards mind, tell "Hello World" to "AndroidX". As previously noted inwards the Android KTX announcement, nosotros are adding novel features nether this package, as well as updating approximately existing ones.

android.* vs androidx.* namespaces

Writing Android apps agency depending on ii kinds of classes:

  • Classes similar PackageManager, which are bundled alongside the operating arrangement as well as tin stimulate got dissimilar APIs as well as conduct for dissimilar Android versions
  • Classes similar AppCompatActivity or ViewModel, which are unbundled from the operating arrangement as well as send inwards your apk. These libraries are written to render a unmarried API surface alongside conduct that's equally consistent equally possible across Android versions.

Many times, unbundled libraries tin locomote a improve choice, since they render a unmarried API surface across dissimilar Android versions. This refactor moves the unbundled libraries - including all of the Support Library as well as Architecture Components - into the AndroidX package, to arrive clear to know which dependencies to include.

Revised naming for packages as well as Maven artifacts

We redesigned the packet construction to encourage smaller, to a greater extent than focused libraries that salve pressure level on apps as well as tests that aren't using Proguard or Multidex. Maven groupIds as well as artifactIds stimulate got been updated to improve reverberate library contents, as well as nosotros stimulate got moved to prefixing library packages alongside their groupId to practise an obvious link betwixt the shape that y'all are using as well as the Maven artifact from which it came.

Generally, y'all tin hold off the next mapping from onetime to novel packages:

Old New
android.support.** androidx.@
android.databinding.** androidx.databinding.@
android.design.** com.google.android.material.@
android.support.test.** (in a futurity release) androidx.test.@

The Architecture Components libraries stimulate got also been moved nether androidx as well as their packet names simplified to reverberate their integration alongside heart as well as individual libraries. H5N1 sample of changes to these libraries:

Old New
android.arch.** androidx.@
android.arch.persistence.room.** androidx.room.@
android.arch.persistence.** androidx.sqlite.@

Additionally, next the introduction inwards 28.0.0-alpha1 of Material Components for Android equally a drop-in replacement for Design Library, nosotros stimulate got refactored the blueprint packet to reverberate its novel direction.

For a consummate listing of mappings from 28.0.0-alpha1 (android.support) to 1.0.0-alpha1 (androidx), delight regard the total AndroidX refactoring map. Please banking concern complaint that at that topographic point may locomote nipper changes to this map during the alpha phase.

Per-artifact strict semantic versioning

Starting alongside the AndroidX refactor, library versions stimulate got been reset from 28.0.0 to 1.0.0. Future updates volition locomote versioned on a per-library basis, next strict semantic versioning rules where the major version indicates binary compatibility. This means, for example, that a characteristic may locomote added to RecyclerView as well as used inwards your app without requiring an update to every other library used past times your app. This also agency that libraries depending on androidx may render reasonable guarantees virtually binary compatibility alongside futurity releases of AndroidX -- that a dependency on a 1.5.0 revision volition soundless locomote when run against 1.7.0 but volition probable non locomote against 2.0.0.

Migration from 28.0.0-alpha1

Moving your app from android.support to androidx-packaged dependencies has ii major parts: source refactoring as well as dependency translation.

Source refactoring updates your Java code, XML resources, as well as Gradle configuration to reference the refactored classes as well as Maven artifacts. This characteristic is available inwards Android Studio Canary 14 for applications targeting Android P.

If y'all depend on a library that references the older Support Library, Android Studio volition update that library to reference androidx instead via dependency translation. Dependency translation is automatically applied past times the Android Gradle Plugin 3.2.0-alpha14, which rewrites bytecode as well as resources of JAR as well as AAR dependencies (and transitive dependencies) to reference the novel androidx-packaged classes as well as artifacts. We volition also render a standalone translation tool equally a JAR.

What's next?

We empathize this is a big alter for existing projects as well as codebases. Our intention is to render a rigid foundation that sets Android library projects upwards for to a greater extent than sustainable growth, improve modularity, as well as smaller code size.

We promise that these changes also arrive easier for developers to break features as well as implement high-quality apps inwards less time; however, nosotros empathize that migration takes fourth dimension as well as may non check into everyone's production schedule. For this reason, nosotros volition maintain to render parallel updates to an android.support-packaged laid of libraries for the duration of the P preview SDK timeframe. These updates volition maintain the 28.0.0 versioning system that began alongside 28.0.0-alpha1 inwards March 2018, as well as they volition maintain to locomote source-compatible alongside existing projects that depend on the android.support package.

The stable loose of 28.0.0 volition locomote the terminal characteristic loose packaged equally android.support. All subsequent characteristic releases volition simply locomote made available equally androidx-packaged artifacts.

We'd dear to listen from y'all equally nosotros iterate on this exciting future. Send us feedback past times posting comments below, as well as delight file whatever bugs y'all encounter on AOSP.

We aspect forrad to a novel era of Android libraries!

Related Post

Hello World, Androidx
4/ 5
Oleh