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。
不幸的是,当我进行构建时,它会抱怨 "build" 下的文件中使用了支持库引用,但这些是生成的并且无法编辑。
我现在该怎么办?
这是错误的层次结构:
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 文件中的所有引用也是正确的!
我正在将我的 Android 迁移到目标 28 并使用 Android X 而不是 Android 支持库。我已经将我项目中的大部分引用更改为使用 Android X。
不幸的是,当我进行构建时,它会抱怨 "build" 下的文件中使用了支持库引用,但这些是生成的并且无法编辑。
我现在该怎么办?
这是错误的层次结构:
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 文件中的所有引用也是正确的!