When adding the MQTT dependency library today, an error was prompted during the build:
Caused by: org.gradle.api.internal.artifacts.ivyservice.DefaultLenientConfiguration$ArtifactResolveException: Could not resolve all files for configuration ':app:debugRuntimeClasspath'.
Later, according to the wrong prompt, it may be related to the sentence added in build.gradle(:app) in the project:
implementation 'com.android.support:support-v4:4.4.1'
I checked some information on the Internet, and finally found that it was because I used the Androidx library when creating a new project in Android Studio. If the third-party dependency library used at this time contains the old version of the Support library, it will cause conflicts and errors.
The solution is also relatively simple, that is, add a sentence to the gradle.properties file in the project:
android.enableJetifier=true
In this way, the file contains both android.useAndroidX=true and android.enableJetifier=true. Let's analyze the understanding of these two sentences:
android.useAndroidX
:true
When , the Android plugin uses the corresponding AndroidX library instead of the support library. If not specified, this flag defaults tofalse
.android.enableJetifier
:true
When , the Android plugin automatically migrates existing third-party libraries to use AndroidX dependencies by rewriting their binaries. If not specified, this flag defaults tofalse
.
There is a detailed introduction on the official website of Android, please refer to: AndroidX Overview | Android Developers | Android Developers (google.cn) https://developer.android.google.cn/jetpack/androidx