“This is day 9 of my participation in the First Wen Challenge 2022.First challenge in 2022”


Recently in the study of hook technology, when looking for hook points, it is inevitable to read the source code. There is always a lot of variation in the method between different SDK sources. So my device is 8.1, API27. – Reduced the app version to 27, so that you can keep up with the 27 source code. It turned out to be a problem.

I’m currently using Android Studio version 4.1, and since AS3.5, the default integrated support library has changed from V7 to AndroidX for new projects. Androidx supports the minimum API version 28. If you change it to 27, an error will be reported.


Before we solve the problem, let’s take a look at what androidx is. The following content is excerpted from my aunt guo’s blog, please go to the details of what is AndroidX?

When The Android system first came out, even its designers probably didn’t expect it to be so successful, so it’s unlikely that the API was well thought out from the beginning. As versions of Android are updated over time, many new apis are added in each version, but the new apis are not in the old version, so there is a problem of backward compatibility. For example, when The Android system was released to version 3.0, the importance of tablets was suddenly realized. Therefore, in order to make Android better compatible with tablets, the Android team added the Fragment function in system 3.0 (API 11). But fragments aren’t limited to tablets. What if you wanted to use them on older systems? As a result, the Android team launched a well-known Android Support Library to provide backward compatibility. For example, the support-V4 and AppCompat-V7 libraries, which are familiar to everyone, belong to the Android Support Library and are believed to be used by anyone who has done Android development. But many people may not have thought about what the support-V4 library name actually means, so here’s an explanation. 4 here refers to the Android API version number, which corresponds to the system version 1.6. Support-v4 means that the API provided in this library will be backward compatible with Android 1.6. The corresponding package is called Android.support.v4.app. Similarly, AppCompat-v7 refers to the backward compatibility of the apis provided in the library to API 7, or Android 2.1. Its corresponding package called android. Support. V7. Appcompat can find that the android support Library provided in the Library, they package names in android. Support. * at the beginning. However, with the passage of time, the 1.6 and 2.1 systems have long been eliminated. Now the lowest version of the system officially supported by Android is 4.0.1, and the corresponding API version number is 15. The support-V4 and AppCompat-V7 libraries no longer support systems as old as they were, but their names have stuck, even though they don’t actually do what they were named for anymore. It’s clear that the Android team realized that the naming wasn’t appropriate enough, so they reorganized the ARCHITECTURE of these apis and launched AndroidX.

In short, AndroidX is an extension library for the Android operating system, and many of the apis we use for development come from this library.

Fix the problem and change the support library from Androidx to Android.support.v7

Step 1 change compileSdkVersion and targetSdkVersion back to 27

Android resource linking failed, the reason is that the project mentioned above uses the Android X library, the minimum support is API28. If you had just changed it to 28, it would have been fine, but I wanted 27, so I had to keep working on it.

Step 2, change the AndroidX dependency to the support library

The main is the replacement of the support library

Before change implementation 'androidx. Appcompat: appcompat: 1.1.0' changes after implementation 'com. Android. Support: appcompat - v7:28.0.0'Copy the code

Android resource linking failed. The reason is that our project still calls the resources in the Android X library.

The third step is to remove the project calls to surface resources in the androidx library

Error call path, there are hints in the log, one by one open remove, such as:



If you open the file, red marks are displayed, indicating that these resources cannot be found in Support

Will Theme. MaterialComponents. DayNight. DarkActionBar Theme, with the Support in the library of themes, such as the Theme. The AppCompat. Light. NoActionBar, hit the delete the rest of the delete.

There is also the code in the call, AndroidX also need to change to Support library

At this point, however, I found that the code indicated that the Support library was not found

Running at this time still shows linking failed

So I opened Project Structure and looked at Project dependencies. That’s right

But he has an All Moudules on it, showing dependencies that are clearly problematic

So I did a global search, and oh, well, there’s a lot left to change. But the important thing is the android.useAndroidX=true configuration

Step 4 remove the configuration of the androidx library from the project

When you open this folder, you see two configurations. UseAndroidx =true, android.enableJetifier=true. If you are a new project using AndroidX dependencies, you need to add the following configuration to the gradle.properties file:

Copy the code

If you want to use AndroidX, but previously did not migrate, you can configure it like this:

Copy the code

So we don’t want to use Androidx right now, so we’ll just kill these two lines.