最新消息:20210917 已从crifan.com换到crifan.org

【已解决】Android中gradle编译报错:This project uses AndroidX dependencies, but the android.useAndroidX property is not enabled

Android crifan 1442浏览 0评论
折腾:
【未解决】Android Studio中用PreferenceFragmentCompat实现rcsjta的tts的参数设置页面
期间,rcsjta的子项目tts中的 
build.gradle
增加了Androidx的配置:
dependencies {
    implementation project(':api')
    implementation 'com.android.support:support-v4:25.0.1'


    def preference_version = "1.1.1"
    implementation "androidx.preference:preference:$preference_version"
}
结果编译报错:
This project uses AndroidX dependencies, but the 'android.useAndroidX' property is not enabled. Set this property to true in the gradle.properties file and retry.
The following AndroidX dependencies are detected: androidx.appcompat:appcompat:1.1.0, androidx.fragment:fragment:1.2.4, androidx.core:core:1.1.0, androidx.slidingpanelayout:slidingpanelayout:1.0.0, androidx.versionedparcelable:versionedparcelable:1.1.0, androidx.customview:customview:1.0.0, androidx.swiperefreshlayout:swiperefreshlayout:1.0.0, androidx.interpolator:interpolator:1.0.0, androidx.lifecycle:lifecycle-viewmodel-savedstate:2.2.0, androidx.loader:loader:1.0.0, androidx.activity:activity:1.1.0, androidx.drawerlayout:drawerlayout:1.0.0, androidx.collection:collection:1.1.0, androidx.viewpager:viewpager:1.0.0, androidx.localbroadcastmanager:localbroadcastmanager:1.0.0, androidx.arch.core:core-common:2.1.0, androidx.savedstate:savedstate:1.0.0, androidx.annotation:annotation:1.1.0, androidx.lifecycle:lifecycle-common:2.2.0, androidx.appcompat:appcompat-resources:1.1.0, androidx.lifecycle:lifecycle-viewmodel:2.2.0, androidx.lifecycle:lifecycle-livedata:2.0.0, androidx.legacy:legacy-support-core-ui:1.0.0, androidx.preference:preference:1.1.1, androidx.arch.core:core-runtime:2.1.0, androidx.lifecycle:lifecycle-livedata-core:2.2.0, androidx.legacy:legacy-support-core-utils:1.0.0, androidx.documentfile:documentfile:1.0.0, androidx.cursoradapter:cursoradapter:1.0.0, androidx.vectordrawable:vectordrawable-animated:1.1.0, androidx.recyclerview:recyclerview:1.0.0, androidx.vectordrawable:vectordrawable:1.1.0, androidx.coordinatorlayout:coordinatorlayout:1.0.0, androidx.asynclayoutinflater:asynclayoutinflater:1.0.0, androidx.lifecycle:lifecycle-runtime:2.2.0, androidx.print:print:1.0.0
Affected Modules: tts
看起来,好像就是:增加一个配置即可?
然后也要看看加在哪里
but the ‘android.useAndroidX’ property is not enabled
Android中使用AndroidX出现 but the android.useAndroidX property is not enabled的问题解决办法_weixin_42433094的博客-CSDN博客
找到:gradle.properties
加上:
/rcsjta/samples/api/tts/project.properties
android.useAndroidX=true
android.enableJetifier=true
但是顺带也去搞清楚,为何还要加个android.enableJetifier
This project uses AndroidX dependencies, but the ‘android.useAndroidX’ property is not enabled – Mobile SDK / Android – Zoom Developer Forum
Jetifier是JetPack?
This project uses AndroidX dependencies, but the ‘android.useAndroidX’ property is not enabled – Stack Overflow
Can I use library that used android support with Androidx projects. – Stack Overflow
  • android.useAndroidX
    • When set to true, this flag indicates that you want to start using AndroidX from now on. If the flag is absent, Android Studio behaves as if the flag were set to false.
  • android.enableJetifier
    • When set to true, this flag indicates that you want to have tool support (from the Android Gradle plugin) to automatically convert existing third-party libraries as if they were written for AndroidX. If the flag is absent, Android Studio behaves as if the flag were set to false.
好像是:
Jetfier是帮忙 把其他普通android support的tool,自动转换支持androidX?
Android Studio 3.6.1 | Error: “This project uses AndroidX dependencies” – Stack Overflow
另外通过
Can I use library that used android support with Androidx projects. – Stack Overflow
的:
To Enable Jet-fire in project there is option in android Studio
Select Your Project —> Right Click
app—-> Refactor —-> Migrate to AndroidX
间接帮助理解:
android.enableJetifier
实现了部分的 Migrate to AndroidX的作用。
去重新编译试试再说。
结果问题依旧。
另外注意到
/RCS/rcsjta/samples/api/tts/project.properties
前面提示是:
# This file is automatically generated by Android Tools.
# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
说是有工具生成的。
不要自己随便改?
不过感觉还是:
上述android.useAndroidX等参数,需要加到:整个项目的根目录?
而不是此处的rcsjta的tts的子项目中?
但是根目录中 没有找到project.properties
只有
local.properties
然后加进去:
sdk.dir=/Users/xxx/Library/Android/sdk
android.useAndroidX=true
android.enableJetifier=true
但是看起来也是灰色的
鼠标移动上去后,显示是 无用的:
换成
gradle/wrapper/gradle-wrapper.properties
中,好像是有效的?
去sync,问题依旧。
重新编译,问题依旧。
不过先去
build.gradle
根据提示:
Dependencies using groupId com.android.support and androidx.* can not be combined but found IdeMavenCoordinates{myGroupId='com.android.support', myArtifactId='support-compat', myVersion='25.0.1', myPacking='aar', myClassifier='null'} and IdeMavenCoordinates{myGroupId='androidx.legacy', myArtifactId='legacy-support-core-ui', myVersion='1.0.0', myPacking='aar', myClassifier='null'} incompatible dependencies 
改为:
dependencies {
    implementation project(':api')
//    implementation 'com.android.support:support-v4:25.0.1'


    def preference_version = "1.1.1"
    implementation "androidx.preference:preference:$preference_version"
}
结果:
问题依旧。
参考
Build Environment
去找gradle.properties
算了,现在子项目tts的目录中新建一个gradle.properties
/RCS/rcsjta/samples/api/tts/gradle.properties
结果:
好像至少没了这个报错了。
【总结】
此处,当rcsjta的子项目tts中的
build.gradle
增加了androidx的配置后
dependencies {
    implementation project(':api')
    implementation 'com.android.support:support-v4:25.0.1'


    def preference_version = "1.1.1"
    implementation "androidx.preference:preference:$preference_version"
}
编译报错:
This project uses AndroidX dependencies, but the 'android.useAndroidX' property is not enabled. Set this property to true in the gradle.properties file and retry.
原因:
没有开启androidX支持。
解决办法:
加上androidX的支持
具体配置是:
android.useAndroidX=true
另外,往往顺带再加上:
android.enableJetifier=true
好像是自动帮忙转换普通的support的库,以支持androidX。
放在那里?
项目的gradle.properties中。
此处没有,所以去
给rcsjta的子项目tts的目录中新建一个
/RCS/rcsjta/samples/api/tts/gradle.properties
android.useAndroidX=true
android.enableJetifier=true
即可。

转载请注明:在路上 » 【已解决】Android中gradle编译报错:This project uses AndroidX dependencies, but the android.useAndroidX property is not enabled

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
93 queries in 0.189 seconds, using 23.38MB memory