Author: Mr. Point time: 2019.3.2

gossip

To be fair, I should have posted an article on the 26th of last month, but you know, it’s Chinese New Year. Only once a year, how precious. So I got lazy and rested. This late article is to make up for what was not written in February. There will be another post on March 26. For February, let’s just water it. (Whisper: I am much better than the rest of the team, they didn’t write in February, but AT least I made it up! JPG!)

What’s AndroidX

New Year’s Day I have not been idle, busy review, ready to job-hopping. I learned about AndroidX on the way.

To put it simply, AndroidX is an improved version of the Android Support Library. In the future, new things will only be updated in AndroidX, and the Support Library will gradually be abandoned. This is probably good news, don’t worry about v4 or V7, just X instead. But it’s not recommended for commercial development right now, just play with it.

How to use AndroidX

  1. Make sure your AS is above version 3.2 or 3.2;
  2. CompileSdkVersion at least 28(Android 9.0);
  3. Set “android.useAndroidX=true”, “android.enableJetifier=true” (useAndroidX: Whether to use the androidX library. If false, use the support library. EnableJetifier: Whether to enable third-party libraries to automatically use androidX.
  4. On the menu bar select Refactor > Migrate to AndroidX

Note: If you are using the Android KTX module, be sure to update your dependencies to avoid migration issues. For the latest version of each module, see Android KTX. For details about the package name after the migration, see the official documents.

Problems that may occur after migration

Problem: after migrating the demo I wrote before to androidX, I found some packages and couldn’t import them. Check that the package name is correct, but import failed. Solution: Delete the packages referenced in the extends/implements class once and let AS import them automatically. Delete the package name, save it, and write the package name again. Do this once, and it can be referenced by another class.

Problem: Not all third-party libraries support anroidX. The workaround: don’t worry, most libraries in common use today already support androidX. AndroidX is a trend that needs to be popularized by programmers. This problem won’t be a problem with androidX.

If you have any other questions after the transfer, please leave a message below the article and I will try my best to answer them.

My AndroidX project

I wrote a demo of the Clean framework, which I have now upgraded to the androdX version. The new address: AndroidXCleanDemo https://github.com/GuitarDian/AndroidXCleanDemo