In order to find the problem, the Unity project is exported to the native project, and then through the gradlew :dependencies command, we can see that some libraries depend on the library of support.v4;
Well, if you need to deal with projects to support androidx and resolve conflicts, there are two ways.
With Android Studio version 3.x, you can operate directly.
If the Unity project directly supports AndoridX, you need to modify gradle.properties to solve the compatibility problem of androidx.
Then, we also know that Unity directly exports the apk package and compiles it through gradle. However, in this case, it is not convenient to modify gradle.properties every time we process it in tempDir, so we need to write a plug-in every time we package it, and then modify this configuration file, with the support of androidx.
I looked at Unity's plug-in method, Android. ipostGenerateGradeLeandroidProject。
Modify the gradle configuration file when building the project.
Create a new C# file under the project's Asset/Plugins/Editor, and name it supportandroidGradePropertiesBuildProcessor.cs (of course, you can also change the class name to what you want).
I posted the realization of this file directly, that is, I realized the interface of iPostgenerate GradeleandroidProject.
Ok, in this way, when you build apk directly with Unity, write it in the configuration of androidx, and it will be compatible with androidx!
(As a Unity scum, I still have to record this question today ~)