When Alipay App meets AndroidX...

Posted by ryanthegecko on Tue, 28 Sep 2021 11:41:32 +0200

Author: Yangzhou

This article mainly introduces some new (xin) Suan (lei) in Alipay Android end embrace AndroidX process.

  • What are the differences / difficulties of upgrading Alipay to AndroidX?
  • How is the Migrate AndroidX of Android Studio implemented?
  • How does APK product fit Android x?

background

Since Android Support was "revolutionized" in 2018, the Support extension library has been dusty at the age of 28 (the last official version). AndroidX has been widely accepted by the community. Many well-known frameworks have launched versions of AndroidX adaptation, and major App manufacturers have also followed up with AndroidX upgrade.

Irresponsibly, in the long run, the absence of AndroidX will be disconnected from the Android community components, unable to enjoy the maintenance of components, and it is difficult to integrate new components, such as Paging 3.0, CameraX 1.0.0, Hilt 1.0.0, AppSearch 1.0.0, not to mention the rising rookie Jetpack Compose.

Android X industry

The content of AndroidX is not detailed here, but summarized in one sentence: AndroidX is the successor of Support, undertakes the functions of the original Support 28, and continues to iterate out more extension libraries.

By looking at the App packages in an application market and analyzing the Android x adaptation of these apks, we get a data that 70% of the top 50 target groups are adapted to Android x (the list is not authoritative and there is no need to pay too much attention to the ranking):

Number of applications

Android x adapter

percentage

50

35

70%

App list:

Android x is well adapted to apps in the industry. Although 70% of the sampled apps are adapted, the remaining 30% are apps with high volume.

After reading this, you may have to ask: Why are there many applications that have not been adapted?

"Technical debt" is often mentioned in software development, that is, it is a test for R & D personnel every time they face major system adjustment. Specific to each independent App, architecture differences, business R & D modes, component use demands, R & D saturation, etc. will form resistance to upgrading.

Then, Alipay App, who is also facing the above resistance, will encounter the "spark" of AndroidX.

Android x for Wallet

In order to make the huge Alipay App successfully put on the AndroidX robe, we need to design a technical solution that can flexibly adapt to many businesses, and do deep source matching with the wishes and demands of the business. For the business that "strength does not allow" for the time being, we try to provide a thorough plan.

AndroidX adapter

By analyzing the solution, we know that Android x mainly deals with the following:

  1. Java/Class source code, various support classes, package replacement
  2. xml layout, replace support component name
  3. build.gradle, modify GAV in dependency
  4. proguard, confusion rule replacement
  5. pom dependency processing

Wallet architecture status

The Android development of ants is very familiar with the construction system of Alipay. There are some differences between them. Here we simply make an abstraction so that non ant Android developers can quickly understand a whole picture.

From the point of view of the construction of the project, we can draw two pictures, and I named them "traditional Android development" and "Alipay Android development". The plug-in of Android is not discussed here (this is almost a unique trend in China).

PS: the AAB launch plan that Google play will launch in August 2021 is not covered here. Interested students can fill in the big picture by themselves.

Comparing the two figures, the main difference is the difference built with AGP. mPaas is also an output of the commercialization of the wallet system. Relying on in-depth construction customization and combined with the runtime framework of wallet, we have fully realized the parallel development and dynamic delivery of business. If I want to use a few simple words to describe it, I will say this:

  • Business isolation = Bundle
  • Build separation = mPaas+Bundle
  • Product aggregation, dynamic publishing = "mPaas+Portal+Bundle"

This system has many advantages. Predecessors planted trees and later generations enjoyed the cool, but it also needs to bear the pain points and pits left after in-depth customization.

After understanding the Android x adaptation point and the development mode of the wallet, you should be able to guess that the first problem encountered by the wallet to adapt to Android X: the adaptation requires the modification of Java source code or Class bytecode, and the business in the wallet is isolated through APK, with almost no AAR.

Resistance and power

For Alipay, for Android development, we have the original development of benchmarking, including R & D efficiency, compilation chain alignment and so on.

Our resistance to upgrading Android x includes:

  • The Support class library is widely used, and API compatibility challenges;
  • For many cross team modules, change it to "hundred regiments war";
  • The official upgrading mechanism is not applicable to the construction of wallets;
  • Layout dynamic container, conflict.

There is also a lot of power (regardless of order):

  • Android Support is no longer maintained;
  • Android x community integration is improved;
  • Modern Android development is based on Android X;
  • There are demands for use in business.

After many times of communication and adjustment, several points of our research scheme should be ensured:

  • Minimize the number of related parties;
  • Compatibility;
  • Less invasive;
  • Pluggable adapter.

You can't require all business developers to adapt the source code to Android x, otherwise you may ask yourself: who am I? Where am i? What am I doing?

It needs to be compatible with historical modules with few iterations, such as modules that have not changed since 16 years. Is it realistic for you to find someone to cooperate?

From the standpoint of business development, adaptation should not be more complex than the official scheme, and try to achieve non perceptual adaptation. The adaptation capability is close to Andoird, and the switch is provided to facilitate the selective processing of services.

Wallet adaptation implementation

Here is an earlier drawing of the process and card points for adapting Android X in the construction.

Class substitution

Java/Class code processing is aimed at source code engineering and AAR. The bundle of the wallet is apk, and the interior is compiled dex and binary xml. In the class replacement phase, we modify the mapping relationship in the support replacement set to dex one by one by parsing the dex file structure.

xml substitution

xml in apk is a binary plain format. It is not a text file and has its own format. This format is simply Chunk. We find the stored xml node in it, replace the set with the corresponding value of the node with support, and save it as binary xml again after modification.

Bundle replacement

Combining the previous two steps, a new apk is obtained. Replace the bundle/devbundle dependency in the dependency.

product

When we start adapting to an karma, its products will change.

After the modification, we will output a txt report for developers to check and use. Here is an example:

OLD: /Users/█████/work/android-phone-█████-git/build/build/outputs/apk/debug/█████-build-debug.apk
NEW: /Users/█████/work/android-phone-█████-git/build/build/bundle-cache/█████-build-debug.apk

class count: 53
xml count: 1

=================
====   DEX   ====
=================

* com/alipay/android/█████/█████/█████ (3)
* com/alipay/android/█████/██████████$█████ (3)
* com/alipay/mobile/██████████/███/██████████$12 (9)
* com/alipay/mobile/█████/█/█████ (45)
* com/alipay/mobile/██/██/█████$██████████ (28)
* com/alipay/mobile/█/███/███████████████ (3)
* com/alipay/android/█████/█████/███████ (3)
* com/alipay/mobile/██████/█/██████$████ (9)
* com/alipay/mobile/███/███/█████████ (13)
* com/alipay/android/███/██/█████ (20)
* com/alipay/mobile/███/█/████$█████ (9)
* com/alipay/android/███/█████████$█████ (12)
* com/alipay/mobile/██/█/██████████████ (27)
* com/alipay/mobile/█/███/███████████████ (3)
* com/alipay/mobile/██/██/█████/████████ (9)
* com/alipay/android/██/█/██████████████████ (6)
* com/alipay/mobile/█/███/███████████████ (3)
* com/alipay/android/█████/███/██████ (23)
* com/alipay/android/██/██/████████████ (30)
* com/huawei/android/█████/████████$███████████ (2880)
* com/alipay/android/████/██████$14 (4)
* com/alipay/android/█████/██/█████████ (41)
* com/alipay/android/████/████/██████████████████ (129)
* com/alipay/android/████/████████████ (22)
* com/alipay/android/████████/███████/█████████████████ (3)
* com/alipay/mobile/████/██████/███████/█████████████████████████ (3)
* com/alipay/android/████████/████/███████████████ (18)
* com/alipay/mobile/████████/███/████████████████████████ (27)
* com/alipay/android/████████/██████████████████$21 (17)
* com/alipay/mobile/██████/██████/████████████████████████████████$██████████████████████ (6)
* com/alipay/android/████████/██████████████████$22 (8)
* com/alipay/mobile/████████/███/██████████████████$5 (9)
* com/alipay/android/████████/██████████████████$20 (6)
* com/alipay/android/████████/████/█████████████ (23)
* com/alipay/mobile/██████/██████/██████████████████████████$4 (3)
* com/alipay/mobile/██████/██████/████████████████████████████████$████████████████████ (38)
* com/alipay/mobile/██████/██████/██████████████████████████$2 (4)
* com/alipay/mobile/██████/██████/██████████████████████████$8 (6)
* com/alipay/android/████████/██████████████████ (293)
* com/alipay/mobile/██████/██████/██████████████████████████$6 (3)
* com/alipay/mobile/██████/██████/█████████/███████████████$5 (9)
* com/alipay/android/████/████████████$1$1 (11)
* com/alipay/mobile/██████/██████/████████████████████████████████ (87)
* com/alipay/android/████████/█████/██████████████████████ (7)
* com/alipay/android/████████/tab/█████████████████$2 (4)
* com/alipay/android/████████/tab/█████████████████$1 (4)
* com/alipay/mobile/██████/██████/████████████████████████████████$2$1 (7)
* com/alipay/android/████/████████████$1 (5)
* com/alipay/android/████████/████/███████████████$████████████████████$1$1 (9)
* com/alipay/mobile/████████/███/████████████$5 (9)
* com/alipay/mobile/████/████████/█████████████████████ (2)
* com/alipay/mobile/████████/███/████████████████████████$4 (9)
* com/alipay/mobile/██████/██████/██████████████████████████ (306)

Reference detail:
* com/alipay/android/████████/█████/█████████████████████ (3)
    | android/support/annotation/NonNull -> androidx/annotation/NonNull (3)

* com/alipay/android/████████/██████████████████$█████████████ (3)
    | android/support/v4/app/FragmentActivity -> androidx/fragment/app/FragmentActivity (3)

* com/alipay/mobile/████████/███/████████████$12 (9)
    | android/support/v4/content/LocalBroadcastManager -> androidx/localbroadcastmanager/content/LocalBroadcastManager (9)

* com/alipay/mobile/████████/███/████████████ (45)
    | android/support/v4/content/LocalBroadcastManager -> androidx/localbroadcastmanager/content/LocalBroadcastManager (45)

* com/alipay/mobile/██████/██████/██████████████████████████$LoginActivityOnWindowsFocusChangeReceiver (28)
    | android/support/v4/app/FragmentActivity -> androidx/fragment/app/FragmentActivity (9)
    | android/support/v4/content/LocalBroadcastManager -> androidx/localbroadcastmanager/content/LocalBroadcastManager (19)

* com/alipay/mobile/████/██████/█████████████████████████ (3)
    | android/support/annotation/NonNull -> androidx/annotation/NonNull (3)

* com/alipay/android/████████/███████/████████████ (3)
    | android/support/annotation/Nullable -> androidx/annotation/Nullable (3)

* com/alipay/mobile/████████/███/████████████$█████████████ (9)
    | android/support/v4/content/LocalBroadcastManager -> androidx/localbroadcastmanager/content/LocalBroadcastManager (9)

* com/alipay/mobile/██████/██████/██████████████████████ (13)
    | android/support/v4/content/LocalBroadcastManager -> androidx/localbroadcastmanager/content/LocalBroadcastManager (10)
    | android/support/annotation/NonNull -> androidx/annotation/NonNull (3)

* com/alipay/android/████████/████/████████████████████████ (20)
    | android/support/v4/app/FragmentPagerAdapter -> androidx/fragment/app/FragmentPagerAdapter (3)
    | android/support/v4/app/FragmentManager -> androidx/fragment/app/FragmentManager (11)
    | android/support/v4/app/Fragment -> androidx/fragment/app/Fragment (6)

* com/alipay/mobile/████████/███/████████████████████████$█████████████ (9)
    | android/support/v4/content/LocalBroadcastManager -> androidx/localbroadcastmanager/content/LocalBroadcastManager (9)

* com/alipay/android/████████/██████████████████$TabChangeTimeRunnable (12)
    | android/support/v4/app/FragmentActivity -> androidx/fragment/app/FragmentActivity (12)

* com/alipay/mobile/████████/███/██████████████████ (27)
    | android/support/v4/content/LocalBroadcastManager -> androidx/localbroadcastmanager/content/LocalBroadcastManager (27)

* com/alipay/mobile/base/config/ConfigServiceLmacSyncCallback (3)
    | android/support/annotation/NonNull -> androidx/annotation/NonNull (3)

* com/alipay/mobile/██████/██████/█████████/███████████████ (9)
    | android/support/v4/content/LocalBroadcastManager -> androidx/localbroadcastmanager/content/LocalBroadcastManager (9)

* com/alipay/android/████████/████/█████████████████████████████████████████ (6)
    | android/support/v4/app/FragmentActivity -> androidx/fragment/app/FragmentActivity (6)

* com/alipay/mobile/█████/█████/████████████████████ (3)
    | android/support/annotation/NonNull -> androidx/annotation/NonNull (3)

* com/alipay/android/████████/████/███████████████ (23)
    | android/support/v4/app/Fragment -> androidx/fragment/app/Fragment (7)
    | android/support/v4/app/FragmentActivity -> androidx/fragment/app/FragmentActivity (16)

* com/alipay/android/████████/████/████████████████████ (30)
    | android/support/v4/view/ViewPager -> androidx/viewpager/widget/ViewPager (18)
    | android/support/v4/app/FragmentManager -> androidx/fragment/app/FragmentManager (7)
    | android/support/v4/view/PagerAdapter -> androidx/viewpager/widget/PagerAdapter (5)

* com/huawei/android/██████████/███████████████$████████████████████ (2880)
    | android/support/v4/view/ViewPager -> androidx/viewpager/widget/ViewPager (277)
    | android/support/v4/app/FragmentManager -> androidx/fragment/app/FragmentManager (166)
    | android/support/v4/app/Fragment -> androidx/fragment/app/Fragment (270)
    | android/support/v4/view/PagerAdapter -> androidx/viewpager/widget/PagerAdapter (92)
    | android/support/v4/app/FragmentActivity -> androidx/fragment/app/FragmentActivity (1018)
    | android/support/v4/content/LocalBroadcastManager -> androidx/localbroadcastmanager/content/LocalBroadcastManager (542)
    | android/support/v4/view/ViewPager$OnPageChangeListener -> androidx/viewpager/widget/ViewPager$OnPageChangeListener (105)
    | android/support/v4/app/FragmentTransaction -> androidx/fragment/app/FragmentTransaction (144)
    | android/support/v4/util/ArrayMap -> androidx/collection/ArrayMap (106)
    | android/support/v4/app/FragmentPagerAdapter -> androidx/fragment/app/FragmentPagerAdapter (52)
    | android/support/v4/content/ContextCompat -> androidx/core/content/ContextCompat (48)
    | android/support/annotation/Nullable -> androidx/annotation/Nullable (26)
    | android/support/annotation/NonNull -> androidx/annotation/NonNull (34)

* com/alipay/android/████████/██████████████████$14 (4)
    | android/support/v4/app/FragmentActivity -> androidx/fragment/app/FragmentActivity (4)

* com/alipay/android/████████/tab/█████████████████ (41)
    | android/support/v4/util/ArrayMap -> androidx/collection/ArrayMap (41)

* com/alipay/android/████████/████/██████████████████ (129)
    | android/support/v4/view/ViewPager -> androidx/viewpager/widget/ViewPager (69)
    | android/support/v4/view/ViewPager$OnPageChangeListener -> androidx/viewpager/widget/ViewPager$OnPageChangeListener (39)
    | android/support/v4/view/PagerAdapter -> androidx/viewpager/widget/PagerAdapter (21)

* com/alipay/android/████/████████████ (22)
    | android/support/v4/app/Fragment -> androidx/fragment/app/Fragment (5)
    | android/support/v4/app/FragmentActivity -> androidx/fragment/app/FragmentActivity (14)
    | android/support/annotation/Nullable -> androidx/annotation/Nullable (3)

* com/alipay/android/████████/███████/█████████████████ (3)
    | android/support/annotation/Nullable -> androidx/annotation/Nullable (3)

* com/alipay/mobile/████/██████/███████/█████████████████████████ (3)
    | android/support/annotation/NonNull -> androidx/annotation/NonNull (3)

* com/alipay/android/████████/████/███████████████ (18)
    | android/support/v4/content/LocalBroadcastManager -> androidx/localbroadcastmanager/content/LocalBroadcastManager (18)

* com/alipay/mobile/████████/███/████████████████████████ (27)
    | android/support/v4/content/LocalBroadcastManager -> androidx/localbroadcastmanager/content/LocalBroadcastManager (27)

* com/alipay/android/████████/██████████████████$21 (17)
    | android/support/v4/app/FragmentActivity -> androidx/fragment/app/FragmentActivity (17)

* com/alipay/mobile/██████/██████/████████████████████████████████$██████████████████████ (6)
    | android/support/v4/app/FragmentActivity -> androidx/fragment/app/FragmentActivity (6)

* com/alipay/android/████████/██████████████████$22 (8)
    | android/support/v4/content/LocalBroadcastManager -> androidx/localbroadcastmanager/content/LocalBroadcastManager (8)

* com/alipay/mobile/████████/███/██████████████████$5 (9)
    | android/support/v4/content/LocalBroadcastManager -> androidx/localbroadcastmanager/content/LocalBroadcastManager (9)

* com/alipay/android/████████/██████████████████$20 (6)
    | android/support/v4/app/FragmentActivity -> androidx/fragment/app/FragmentActivity (6)

* com/alipay/android/████████/████/█████████████ (23)
    | android/support/v4/view/ViewPager$OnPageChangeListener -> androidx/viewpager/widget/ViewPager$OnPageChangeListener (7)
    | android/support/v4/view/ViewPager -> androidx/viewpager/widget/ViewPager (16)

* com/alipay/mobile/██████/██████/██████████████████████████$4 (3)
    | android/support/v4/app/FragmentActivity -> androidx/fragment/app/FragmentActivity (3)

* com/alipay/mobile/██████/██████/████████████████████████████████$████████████████████ (38)
    | android/support/v4/app/FragmentActivity -> androidx/fragment/app/FragmentActivity (29)
    | android/support/v4/content/LocalBroadcastManager -> androidx/localbroadcastmanager/content/LocalBroadcastManager (9)

* com/alipay/mobile/██████/██████/██████████████████████████$2 (4)
    | android/support/v4/app/FragmentActivity -> androidx/fragment/app/FragmentActivity (4)

* com/alipay/mobile/██████/██████/██████████████████████████$8 (6)
    | android/support/v4/app/FragmentActivity -> androidx/fragment/app/FragmentActivity (6)

* com/alipay/android/████████/██████████████████ (293)
    | android/support/v4/app/Fragment -> androidx/fragment/app/Fragment (23)
    | android/support/v4/util/ArrayMap -> androidx/collection/ArrayMap (3)
    | android/support/v4/app/FragmentActivity -> androidx/fragment/app/FragmentActivity (184)
    | android/support/v4/content/LocalBroadcastManager -> androidx/localbroadcastmanager/content/LocalBroadcastManager (77)
    | android/support/annotation/Nullable -> androidx/annotation/Nullable (6)

* com/alipay/mobile/██████/██████/██████████████████████████$6 (3)
    | android/support/annotation/Nullable -> androidx/annotation/Nullable (3)

* com/alipay/mobile/██████/██████/█████████/███████████████$5 (9)
    | android/support/v4/content/LocalBroadcastManager -> androidx/localbroadcastmanager/content/LocalBroadcastManager (9)

* com/alipay/android/████/████████████$1$1 (11)
    | android/support/v4/app/FragmentActivity -> androidx/fragment/app/FragmentActivity (11)

* com/alipay/mobile/██████/██████/████████████████████████████████ (87)
    | android/support/v4/app/FragmentActivity -> androidx/fragment/app/FragmentActivity (69)
    | android/support/v4/content/LocalBroadcastManager -> androidx/localbroadcastmanager/content/LocalBroadcastManager (18)

* com/alipay/android/████████/█████/██████████████████████ (7)
    | android/support/annotation/NonNull -> androidx/annotation/NonNull (7)

* com/alipay/android/████████/tab/█████████████████$2 (4)
    | android/support/v4/util/ArrayMap -> androidx/collection/ArrayMap (4)

* com/alipay/android/████████/tab/█████████████████$1 (4)
    | android/support/v4/util/ArrayMap -> androidx/collection/ArrayMap (4)

* com/alipay/mobile/██████/██████/████████████████████████████████$2$1 (7)
    | android/support/v4/app/FragmentActivity -> androidx/fragment/app/FragmentActivity (7)

* com/alipay/android/████/████████████$1 (5)
    | android/support/v4/app/FragmentActivity -> androidx/fragment/app/FragmentActivity (5)

* com/alipay/android/████████/████/███████████████$████████████████████$1$1 (9)
    | android/support/v4/content/LocalBroadcastManager -> androidx/localbroadcastmanager/content/LocalBroadcastManager (9)

* com/alipay/mobile/████████/███/████████████$5 (9)
    | android/support/v4/content/LocalBroadcastManager -> androidx/localbroadcastmanager/content/LocalBroadcastManager (9)

* com/alipay/mobile/████/████████/█████████████████████ (2)
    | android/support/v4/content/ContextCompat -> androidx/core/content/ContextCompat (2)

* com/alipay/mobile/████████/███/████████████████████████$4 (9)
    | android/support/v4/content/LocalBroadcastManager -> androidx/localbroadcastmanager/content/LocalBroadcastManager (9)

* com/alipay/mobile/██████/██████/██████████████████████████ (306)
    | android/support/v4/app/FragmentActivity -> androidx/fragment/app/FragmentActivity (202)
    | android/support/v4/content/LocalBroadcastManager -> androidx/localbroadcastmanager/content/LocalBroadcastManager (22)
    | android/support/v4/app/FragmentManager -> androidx/fragment/app/FragmentManager (36)
    | android/support/v4/app/FragmentTransaction -> androidx/fragment/app/FragmentTransaction (38)
    | android/support/v4/app/Fragment -> androidx/fragment/app/Fragment (8)

=================
====   XML   ====
=================

* res/layout/███████████████.xml (1)

Reference detail:
* res/layout/███████████████.xml (1)
    | android.support.v4.view.ViewPager -> androidx.viewpager.widget.ViewPager

Based on apk's ability to adapt to Android x, we package it as an independent jar project, which can be integrated into Gradle Plugin or published as a command-line tool. The following describes the use of the command line:

bx --input=src/test/resources/█████ .apk --output=build/intermediate
user % bx --help
    ___              __           _     ___  __
   /   |  ____  ____/ /________  (_)___/ / |/ /
  / /| | / __ \/ __  / ___/ __ \/ / __  /|   / 
 / ___ |/ / / / /_/ / /  / /_/ / / /_/ //   |  
/_/  |_/_/ /_/\__,_/_/   \____/_/\__,_//_/|_|  
                                               
Translate apk to compat with AndroidX dependency.
Usage: bx [OPTIONS] [ARGS]...

Options:
 --help         display help information
 --input        Pending apk route, Example: --input=input.apk
 --output       Catalogue of products after treatment, Example: --output=output-dir
 --clean        Clean up intermediate products, Example: --clean=true
 --verbose      Output debug log, Example: --verbose=true
 --jetify       use jetify handle, Example: --jetifye=true

Build platform packaging. According to different package types, there are differences in the engineering modules to be compiled and plug-in logic, such as coverage, plug-in pile, etc. Therefore, the overall time consumption of different types of construction is different. The incremental time consumption of Android x mainly comes from the volume of centralized escape modules. With the increase of the number of independent adaptation modules, the centralized time consumption will gradually decrease. According to the data collection and analysis, the time consumption of a full amount of escape is relatively stable. In the end, the ideal situation is that the construction of the general contractor basically does not add additional time.

After bx is applied to the wallet build-up plug-in, batch bundle compatibility can be made based on the portal baseline. After the compatibility capability is enabled, there is a certain increment in the overall construction time, and the incremental time can be gradually reduced through continuous optimization.

Native adaptation

Google itself provides a one-day adaptation scheme for aar, which can be used directly. The scheme can be used in three ways:

  • First, through migrate androidx of AS, which requires AGP version 3.2.0 or higher;
  • The second is to execute the jar application separately through the command line, which is context independent;
  • The third is the source code transformation. Refer to the internal implementation of AGP to link the Jetify module.
./jetifier-standalone -i <source-library> -o <output-library>

About the introduction of Jetify, a document description is excerpted here:

Jetifier migrates Java, XML, POM, and ProGuard references to android.support. * packages and changes them to point to the corresponding Android X. * packages.

Since the ProGuard wildcard of android.support. * does not always map directly to the Android X. * package, Jetifier generates all qualified alternatives.

If a type in the android.support. * package is not from any support library artifact, Jetifier will migrate the type as long as there is a relevant mapping for the type. However, there is no guarantee that this migration will work because there may not be enough common mapping rules to cover all custom types.

This tool can even execute in reverse, transposing the Android x product to the supportg product. If you are interested, you can try the - r parameter.

In AS, we can activate the jetify mechanism after enabling the gradle parameter configuration. This mechanism will preprocess the dependency dependency and compile the aar that depends on the support extension library into the Android x version.

android.useAndroidX=true
android.enableJetifier=true

As for the code implementation, it uses Gradle's Artifact Transform mechanism to disassemble the dependent aar files. For relevant source code, please refer to: com.android.build.gradle.internal.dependency.JetifyTransform

In this transform, the jetify tool mentioned above will eventually be called. Google has made the tool into an independent maven dependency:

androidx.jetifier:jetifier-core:1.0.0-beta10

https://developer.android.com/jetpack/androidx/releases/jetifier

follow-up

At present, most of the services that Alipay App has completed has been adapted to some parts of the business, including the Support extension library, such as reflection and instantiation of View. The scheme is also being continuously promoted.

In addition to AndroidX, we are also promoting the implementation of Kotlin, Java8 and other wallet building systems. We expect that after the upgrade of AndroidX, the whole business of the wallet can move closer to the original biochemical and modern Android development.

Welcome the partners who are also actively embracing AndroidX to leave messages and share experiences / lessons of adapting to AndroidX.

Pay attention to us, 3 mobile technology practices per week & dry goods for you to think!

Topics: Android Design Pattern app