Android中使用AndroidX出现 but the ‘android.useAndroidX‘ property is not enabled的问题解决办法

报错如下

Configuration `debugRuntimeClasspath` contains AndroidX dependencies, but the `android.useAndroidX` property is not enabled, which may cause runtime issues.
Set `android.useAndroidX=true` in the `gradle.properties` file and retry.
The following AndroidX dependencies are detected:
debugRuntimeClasspath -> androidx.appcompat:appcompat:1.4.2
debugRuntimeClasspath -> androidx.appcompat:appcompat:1.4.2 -> androidx.annotation:annotation:1.3.0
debugRuntimeClasspath -> androidx.appcompat:appcompat:1.4.2 -> androidx.core:core:1.7.0
debugRuntimeClasspath -> androidx.appcompat:appcompat:1.4.2 -> androidx.fragment:fragment:1.3.6 -> androidx.annotation:annotation-experimental:1.1.0
debugRuntimeClasspath -> androidx.appcompat:appcompat:1.4.2 -> androidx.lifecycle:lifecycle-runtime:2.4.0
debugRuntimeClasspath -> androidx.appcompat:appcompat:1.4.2 -> androidx.fragment:fragment:1.3.6 -> androidx.loader:loader:1.0.0 -> androidx.lifecycle:lifecycle-livedata:2.0.0 -> androidx.arch.core:core-runtime:2.1.0
debugRuntimeClasspath -> androidx.appcompat:appcompat:1.4.2 -> androidx.savedstate:savedstate:1.1.0 -> androidx.arch.core:core-common:2.1.0
debugRuntimeClasspath -> androidx.appcompat:appcompat:1.4.2 -> androidx.savedstate:savedstate:1.1.0 -> androidx.lifecycle:lifecycle-common:2.4.0
 

问题原因:


          This project uses AndroidX dependencies,but the 'android.useAndroidX' property is not enabled:
  这里说明项目使用了AndroidX的依赖,但是并没有在gradle.properties文件中将其使能。

解决方法:

需要在gradle.properties文件中加上如下两句即可

android.useAndroidX=true
android.enableJetifier=true

问题2

Manifest merger failed : android:exported needs to be explicitly specified for <activity>. Apps targeting Android 12 and higher are required to specify an explicit value for `android:exported` when the corresponding component has an intent filter defined.

targetSdkVersion大于等于SDK 31(也就是Android 12)时,如果有的Activity配置了Intent-filter,必须也同时配置exported属性,否则编译失败。 

 解决方法 

  1. 降低targetSdkVersion为30.
  2. 将Manifest中有配置Intent-filter的Activity加上android:exported属性

猜你喜欢

转载自blog.csdn.net/xiaowang_lj/article/details/125226011#comments_25912809