迁移到 AndroidX 后如何更新所有库?
How do I update all libraries, after Migrating to AndroidX?
我最近将我的应用程序盲目地迁移到 AndroidX,不知道来龙去脉。结果每次我 运行 这个项目,它都会给我一大堆错误。
我已将所有 Gradle 依赖项和 targetSDK 更新为最新版本代码。我还在 gradle.properties 中添加了以下内容:
android.useAndroidX=true
android.enableJetifier=true
但这仍然没有任何区别。
以下一些是我遇到的错误示例:
error: package android.support.annotation does not exist
error: package android.support.v7.widget does not exist
error: package RecyclerView does not exist
error: cannot find symbol class FragmentActivity
error: cannot find symbol class CardView
error: cannot find symbol class FragmentPagerAdapter
error: cannot find symbol class DialogFragment
我只想知道我可以消除这些错误,因为它阻止我 运行在我的移动设备上安装项目?
Here you can find the full class mapping.
在您的情况下,您必须更改导入:
error: package android.support.annotation does not exist
error: package android.support.v7.widget does not exist
包:
package androidx.annotation.*;
package androidx.appcompat.widget.*;
类:
android.support.v4.app.FragmentActivity androidx.fragment.app.FragmentActivity
android.support.v7.widget.CardView androidx.cardview.widget.CardView
android.support.v4.app.FragmentPagerAdapter androidx.fragment.app.FragmentPagerAdapter
android.support.v7.app.AppCompatDialogFragment androidx.appcompat.app.AppCompatDialogFragment
android.support.v7.widget.RecyclerView androidx.recyclerview.widget.RecyclerView
您似乎在 gradle 文件中正确设置了所有内容。问题是缺少尚未 converted/migrated 到 AndroidX 的软件包。您可以使用以下小技巧:
- 转到您的 app.gradle 文件并右键单击任意位置。
- Select 在弹出的菜单上重构。
- 在子菜单中,select 迁移到AndroidX
- 坐下来让 Android studio 迁移您的所有文件。
要了解更多信息,请查看 this。
希望对您有所帮助。编码愉快!
在 Android Studio 菜单中转到 Refactor 并 select Migrate to AndroidX。
休息android工作室会自动做。
除此之外,如果您仍然发现错误,则必须手动执行某些任务。
- 在布局中找到所有旧的并替换它
android.support.v7.widget.CardView
和
androidx.cardview.widget.CardView
您可以在这里找到地图相关信息https://developer.android.com/jetpack/androidx/migrate/class-mappings
只需使用 Ctr+F 找到旧文本并复制替换文本
- 在应用构建中
implementation 'com.android.support:cardview-v7:28.0.0'
和
implementation 'androidx.cardview:cardview:1.0.0'
您可以在这里找到地图相关信息https://developer.android.com/jetpack/androidx/migrate/artifact-mappings
我最近将我的应用程序盲目地迁移到 AndroidX,不知道来龙去脉。结果每次我 运行 这个项目,它都会给我一大堆错误。
我已将所有 Gradle 依赖项和 targetSDK 更新为最新版本代码。我还在 gradle.properties 中添加了以下内容:
android.useAndroidX=true
android.enableJetifier=true
但这仍然没有任何区别。
以下一些是我遇到的错误示例:
error: package android.support.annotation does not exist
error: package android.support.v7.widget does not exist
error: package RecyclerView does not exist
error: cannot find symbol class FragmentActivity
error: cannot find symbol class CardView
error: cannot find symbol class FragmentPagerAdapter
error: cannot find symbol class DialogFragment
我只想知道我可以消除这些错误,因为它阻止我 运行在我的移动设备上安装项目?
Here you can find the full class mapping.
在您的情况下,您必须更改导入:
error: package android.support.annotation does not exist
error: package android.support.v7.widget does not exist
包:
package androidx.annotation.*;
package androidx.appcompat.widget.*;
类:
android.support.v4.app.FragmentActivity androidx.fragment.app.FragmentActivity
android.support.v7.widget.CardView androidx.cardview.widget.CardView
android.support.v4.app.FragmentPagerAdapter androidx.fragment.app.FragmentPagerAdapter
android.support.v7.app.AppCompatDialogFragment androidx.appcompat.app.AppCompatDialogFragment
android.support.v7.widget.RecyclerView androidx.recyclerview.widget.RecyclerView
您似乎在 gradle 文件中正确设置了所有内容。问题是缺少尚未 converted/migrated 到 AndroidX 的软件包。您可以使用以下小技巧:
- 转到您的 app.gradle 文件并右键单击任意位置。
- Select 在弹出的菜单上重构。
- 在子菜单中,select 迁移到AndroidX
- 坐下来让 Android studio 迁移您的所有文件。
要了解更多信息,请查看 this。
希望对您有所帮助。编码愉快!
在 Android Studio 菜单中转到 Refactor 并 select Migrate to AndroidX。 休息android工作室会自动做。
除此之外,如果您仍然发现错误,则必须手动执行某些任务。
- 在布局中找到所有旧的并替换它
android.support.v7.widget.CardView
和
androidx.cardview.widget.CardView
您可以在这里找到地图相关信息https://developer.android.com/jetpack/androidx/migrate/class-mappings
只需使用 Ctr+F 找到旧文本并复制替换文本
- 在应用构建中
implementation 'com.android.support:cardview-v7:28.0.0'
和implementation 'androidx.cardview:cardview:1.0.0'
您可以在这里找到地图相关信息https://developer.android.com/jetpack/androidx/migrate/artifact-mappings