繁体   English   中英

Android 支持库不存在但无法编辑“Build”文件夹下的文件以引用 Android X

[英]Android support library doesn't exist but can't edit files under "Build" folder to reference Android X

我正在将我的 Android 迁移到目标 28 并使用 Android X 而不是 Android 支持库。 我已将项目中的大部分引用更改为使用 Android X。

不幸的是,当我进行构建时,它会抱怨“构建”下的文件中使用的支持库引用,但这些引用已生成且无法编辑。

我现在该怎么办?

这是错误的层次结构:

app/build/generated/source/apt/debug > 
com/company/projectname/databinding/FragmentColorItemBinding.java   > 
error: package android.support.v7.widget does not exist 

Obvs,我尝试手动更改它,但出现此错误:

Files under the "build" folder are generated and should not be edited. 

所以我不能将其更改为引用 Android X。

我该怎么做才能编译我的构建?

顺便说一句,它在这条线上抱怨:

public final android.support.v7.widget.CardView colorThumbnail;

在那个文件上。 我想使用新的 CardView 但不确定如何使用?

编辑:

dependencies {
    implementation 'androidx.legacy:legacy-support-v4:1.0.0'

    implementation files('libs/android-binding-v0.6-preview.jar')
    implementation 'com.flurry.android:analytics:8.2.0@aar'
    implementation files('libs/ormlite-android-5.0.jar')
    implementation files('libs/ormlite-core-5.0.jar')
    implementation 'com.google.android.gms:play-services-vision:18.0.0'
    implementation 'com.google.android.material:material:1.0.0-rc01'
    implementation 'androidx.cardview:cardview:1.0.0'

    implementation 'io.reactivex:rxjava:1.1.5'
    implementation 'io.reactivex:rxandroid:1.1.0'
    implementation 'com.squareup.retrofit2:converter-gson:2.1.0'
    implementation 'com.squareup.retrofit2:adapter-rxjava:2.1.0'
    implementation 'com.squareup.retrofit2:retrofit:2.1.0'
    implementation 'com.github.bumptech.glide:glide:4.0.0'
    implementation 'androidx.appcompat:appcompat:1.1.0-alpha04'
    implementation 'androidx.core:core-ktx:1.1.0-alpha05'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'

    def appCenterSdkVersion = '2.0.0'
    implementation "com.microsoft.appcenter:appcenter-analytics:${appCenterSdkVersion}"
    implementation "com.microsoft.appcenter:appcenter-crashes:${appCenterSdkVersion}"

}

它不会那样工作。 您必须更改比所列内容更多的内容才能迁移到 AndroidX。

如果你在 Android Studio 中,完成迁移过程真的很简单。 只需转到Refactor -> Migrate to AndroidX 否则,您必须找到/gradle.properties文件并添加以下两行:

android.useAndroidX=true
android.enableJetifier=true

完成第一部分后,您需要将 CardView 导入语句中对 Java 文件中 CardView 的引用更改为:

import androidx.cardview.widget.CardView;
...
public final CardView colorThumbnail;

还要确保 xml 文件中的所有引用也是正确的!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM