AndroidX迁移和方法
迁移到 AndroidX
AndroidX 将原始支持库 API 替换为 androidx
命名空间中的软件包。只有软件包和 Maven 工件名称发生了变化;类名、方法名和字段名没有变化。
注意:我们建议在单独的分支中执行迁移。此外,还应设法避免在执行迁移时重构代码。
前提条件
执行迁移之前,请先将应用更新到最新版本。 我们建议您将项目更新为使用支持库的最终版本:版本 28.0.0。 这是因为,1.0.0 版本的 AndroidX 工件是与支持库 28.0.0 工件等效的二进制文件。
使用 Android Studio 迁移现有项目
使用 Android Studio 3.2 及更高版本,您只需从菜单栏中依次选择 Refactor > Migrate to AndroidX,即可将现有项目迁移到 AndroidX。
重构命令使用两个标记。默认情况下,这两个标记在 [gradle.properties
]
(https://developer.android.google.cn/studio/build#properties-files) 文件中都设为 true
:
android.useAndroidX=true
Android 插件会使用对应的 AndroidX 库而非支持库。
android.enableJetifier=true
Android 插件会通过重写现有第三方库的二进制文件,自动将这些库迁移为使用 AndroidX。
注意:内置的 Android Studio 迁移功能可能并不能完成所有操作。根据您的构建配置,您可能需要手动更新构建脚本和 Proguard 映射。例如,如果您在一个单独的构建文件中维护依赖项配置,请使用下述映射文件来检查依赖项并将其更新为对应的 AndroidX 软件包。
以下是前者是support库,即支持库的中的类映射,后者是对应的androidx下类映射:
(小技巧:在AS中双击shift,输入replace in path ,点击进行全局替换。)
全部替换完成以后,需要注意的是:
(1)清除项目缓存数据:每个module下的build文件夹手动删除;
(2)点击invalidate caches/restart 进行重启AS。
android.support.v4.app.Fragment
androidx.fragment.app.Fragment
android.support.v4.view.ViewPager
androidx.viewpager.widget.ViewPager
android.support.constraint.ConstraintLayout
androidx.constraintlayout.widget.ConstraintLayout
android.support.v4.app.FragmentPagerAdapter
androidx.fragment.app.FragmentPagerAdapter
android.support.v4.app.FragmentStatePagerAdapter
androidx.fragment.app.FragmentStatePagerAdapter
android.support.annotation.DrawableRes
androidx.annotation.DrawableRes
android.support.v4.os.ParcelableCompat
androidx.core.os.ParcelableCompat
android.support.v4.os.ParcelableCompatCreatorCallbacks
androidx.core.os.ParcelableCompatCreatorCallbacks
android.support.v4.view.AccessibilityDelegateCompat
androidx.core.view.AccessibilityDelegateCompat
android.support.v4.view.MotionEventCompat
androidx.core.view.MotionEventCompat
android.support.v4.view.PagerAdapter
androidx.viewpager.widget.PagerAdapter
android.support.v4.view.VelocityTrackerCompat
androidx.core.view.VelocityTrackerCompat
android.support.v4.view.ViewCompat
androidx.core.view.ViewCompat
android.support.v4.view.ViewConfigurationCompat
androidx.core.view.ViewConfigurationCompat
android.support.v4.view.accessibility.AccessibilityEventCompat
androidx.core.view.accessibility.AccessibilityEventCompat
android.support.v4.view.accessibility.AccessibilityNodeInfoCompat
androidx.core.view.accessibility.AccessibilityNodeInfoCompat
android.support.v4.view.accessibility.AccessibilityRecordCompat
androidx.core.view.accessibility.AccessibilityRecordCompat
android.support.v4.widget.EdgeEffectCompat
androidx.core.widget.EdgeEffectCompat
android.support.v4.content.FileProvider
androidx.core.content.FileProvider
android.support.annotation.NonNull
androidx.annotation.NonNull
android.support.annotation.Nullable
androidx.annotation.Nullable
android.databinding.DataBindingUtil
androidx.databinding.DataBindingUtil
android.support.v4.app.AppOpsManagerCompat
androidx.core.app.AppOpsManagerCompat
android.support.annotation.ColorInt
androidx.annotation.ColorInt
android.support.v4.app.ActivityCompat
androidx.core.app.ActivityCompat
android.support.v4.content.ContextCompat
androidx.core.content.ContextCompat
android.support.v7.app.AppCompatActivity
androidx.appcompat.app.AppCompatActivity
android.databinding.BaseObservable
androidx.databinding.BaseObservable
android.support.v4.graphics.drawable.RoundedBitmapDrawable
androidx.core.graphics.drawable.RoundedBitmapDrawable
android.support.v7.widget.AppCompatImageView
androidx.appcompat.widget.AppCompatImageView
android.support.multidex.MultiDexApplication
androidx.multidex.MultiDexApplication
android.support.v7.widget.AppCompatTextView
androidx.appcompat.widget.AppCompatTextView
android.support.annotation.RequiresApi
androidx.annotation.RequiresApi
android.support.v4.content.PermissionChecker
androidx.core.content.PermissionChecker
android.support.v4.view.GestureDetectorCompat
androidx.core.view.GestureDetectorCompat
android.support.v7.widget.RecyclerView
androidx.recyclerview.widget.RecyclerView
android.databinding.Bindable
androidx.databinding.Bindable
android.databinding.ViewDataBinding
androidx.databinding.ViewDataBinding
android.support.v4.app.NotificationCompat
androidx.core.app.NotificationCompat
android.support.v4.content.LocalBroadcastManager
androidx.localbroadcastmanager.content.LocalBroadcastManager
android.support.v4.app.NotificationManagerCompat
androidx.core.app.NotificationManagerCompat
android.support.v4.view.PagerAdapter
androidx.viewpager.widget.PagerAdapter
android.support.v4.view.ViewCompat
androidx.core.view.ViewCompat
android.support.v4.widget.EdgeEffectCompat
androidx.core.widget.EdgeEffectCompat
android.support.v4.view.NestedScrollingParent
androidx.core.view.NestedScrollingParent
android.support.v4.view.MotionEventCompat
androidx.core.view.MotionEventCompat
android.support.v4.widget.NestedScrollView
androidx.core.widget.NestedScrollView
android.support.v7.widget.LinearLayoutManager
androidx.recyclerview.widget.LinearLayoutManager
android.support.v7.widget.StaggeredGridLayoutManager
androidx.recyclerview.widget.StaggeredGridLayoutManager
android.databinding.BindingAdapter
androidx.databinding.BindingAdapter
android.support.v4.widget.ScrollerCompat
androidx.core.widget.ScrollerCompat
android.support.v4.widget.SwipeRefreshLayout
androidx.swiperefreshlayout.widget.SwipeRefreshLayout
android.support.v4.view.animation.FastOutLinearInInterpolator
androidx.interpolator.view.animation.FastOutLinearInInterpolator
android.support.v4.view.animation.FastOutSlowInInterpolator
androidx.interpolator.view.animation.FastOutSlowInInterpolator
android.support.v4.view.animation.LinearOutSlowInInterpolator
androidx.interpolator.view.animation.LinearOutSlowInInterpolator
android.support.annotation.IntDef
androidx.annotation.IntDef
android.support.annotation.LayoutRes
androidx.annotation.LayoutRes
android.support.annotation.StringRes
androidx.annotation.StringRes
android.support.design.widget.TabLayout
com.google.android.material.tabs.TabLayout
android.support.v4.util.Pools
androidx.core.util.Pools
android.support.v4.view.GravityCompat
androidx.core.view.GravityCompat
android.support.v4.widget.TextViewCompat
androidx.core.widget.TextViewCompat
android.support.v7.app.ActionBar
androidx.appcompat.app.ActionBar
android.support.v4.graphics.ColorUtils
androidx.core.graphics.ColorUtils
android.support.v7.widget.OrientationHelper
androidx.recyclerview.widget.OrientationHelper
// UDesk
android.support.v4.text.TextUtilsCompat
androidx.core.text.TextUtilsCompat
android.support.v4.app.LoaderManager
androidx.loader.app.LoaderManager
android.support.v4.content.CursorLoader
androidx.loader.content.CursorLoader
android.support.v4.content.Loader
androidx.loader.content.Loader
android.support.annotation.CheckResult
androidx.annotation.CheckResult
android.arch.lifecycle.MutableLiveData
androidx.lifecycle.MutableLiveData
android.arch.lifecycle.LiveData
android.arch.lifecycle.Observer
android.arch.lifecycle.ViewModelProviders
androidx.lifecycle.ViewModelProviders
android.support.v7.widget.DefaultItemAnimator
androidx.recyclerview.widget.DefaultItemAnimator
android.support.v7.widget.GridLayoutManager
androidx.recyclerview.widget.GridLayoutManager
android.support.v7.widget.AppCompatButton
androidx.appcompat.widget.AppCompatButton
android.support.v7.widget.SimpleItemAnimator
androidx.recyclerview.widget.SimpleItemAnimator
android.support.v7.widget.PagerSnapHelper
androidx.recyclerview.widget.PagerSnapHelper
android.support.design.widget.AppBarLayout
com.google.android.material.appbar.AppBarLayout
android.support.design.widget.CoordinatorLayout
androidx.coordinatorlayout.widget.CoordinatorLayout
android.support.v7.widget.Toolbar
androidx.appcompat.widget.Toolbar
android.support.design.widget.CollapsingToolbarLayout
com.google.android.material.appbar.CollapsingToolbarLayout
android.support.v7.widget.CardView
androidx.cardview.widget.CardView
android.support.annotation.FloatRange
androidx.annotation.FloatRange
android.support.v7.widget.helper.ItemTouchHelper
androidx.recyclerview.widget.ItemTouchHelper
android.support.v7.widget.AppCompatSeekBar
androidx.appcompat.widget.AppCompatSeekBar
android.support.v7.widget.AppCompatEditText
androidx.appcompat.widget.AppCompatEditText
android.support.design.widget.FloatingActionButton
com.google.android.material.floatingactionbutton.FloatingActionButton
android.support.annotation.AnyThread
androidx.annotation.AnyThread
(已同步CSDN:https://blog.csdn.net/u010231454/article/details/113865022)
(已同步掘金:https://juejin.cn/post/6930877189747376136/)