升级targetSdkVersion至33(以及迁移至Androidx)

1.设置 android.useAndroidX=true 和 android.enableJetifier=true
2.一键迁移至androidx:Refactor -> Migrate to Androidx
3.手动修改未能自动迁移到androidx的部分:

android.support.v4.view.ViewPager.PageTransformer -> androidx.viewpager.widget.ViewPager.PageTransformer

android.support.annotation.NonNull -> androidx.annotation.NonNull

android.support.annotation.Nullable -> androidx.annotation.Nullable

android.support.v4.content.ContextCompat -> androidx.core.content.ContextCompat

android.support.v7.widget.DividerItemDecoration -> androidx.recyclerview.widget.DividerItemDecoration

android.support.v7.widget.RecyclerView -> androidx.recyclerview.widget.RecyclerView

android.arch.lifecycle.MutableLiveData -> androidx.lifecycle.MutableLiveData

android.arch.lifecycle.ViewModel -> androidx.lifecycle.ViewModel

android.support.v7.widget.LinearLayoutManager -> androidx.recyclerview.widget.LinearLayoutManager

android.support.constraint.ConstraintLayout -> androidx.constraintlayout.widget.ConstraintLayout

android.support.constraint.Group -> androidx.constraintlayout.widget.Group

android.support.v4.widget.NestedScrollView -> androidx.core.widget.NestedScrollView

android.support.v4.widget.SwipeRefreshLayout -> androidx.swiperefreshlayout.widget.SwipeRefreshLayout

android.support.constraint.Guideline -> androidx.constraintlayout.widget.Guideline

android.support.design.widget.CoordinatorLayout -> androidx.coordinatorlayout.widget.CoordinatorLayout

android.support.design.widget.AppBarLayout -> com.google.android.material.appbar.AppBarLayout

android.support.design.widget.CollapsingToolbarLayout -> com.google.android.material.appbar.CollapsingToolbarLayout

android.support.v7.widget.Toolbar -> androidx.appcompat.widget.Toolbar

android.support.v4.view.ViewPager -> androidx.viewpager.widget.ViewPager

android.support.multidex.MultiDexApplication -> androidx.multidex.MultiDexApplication

android.support.v4.view.PagerAdapter -> androidx.viewpager.widget.PagerAdapter

android.support.v7.util.DiffUtil -> androidx.recyclerview.widget.DiffUtil

android.support.v4.app.Fragment -> androidx.fragment.app.Fragment

android.support.v4.app.FragmentActivity -> androidx.fragment.app.FragmentActivity
android.support.annotation.IntDef -> androidx.annotation.IntDef

android.support.annotation.RequiresApi -> androidx.annotation.RequiresApi

android.support.v4.app.ActivityCompat -> androidx.core.app.ActivityCompat

android.support.v4.widget.Space -> androidx.legacy.widget.Space(为使用space,还需要implementation 'androidx.legacy:legacy-support-v4:1.0.0)

android.support.annotation.ColorRes -> androidx.annotation.ColorRes

android.support.annotation.StringRes -> androidx.annotation.StringRes

android.support.v7.widget.GridLayoutManager -> androidx.recyclerview.widget.GridLayoutManager

android.support.annotation.LayoutRes -> androidx.annotation.LayoutRes

android.support.v4.util.ArrayMap -> androidx.collection.ArrayMap

android.support.design.internal.BottomNavigationMenuView -> com.google.android.material.bottomnavigation.BottomNavigationMenuView

android.support.design.widget.BottomNavigationView -> com.google.android.material.bottomnavigation.BottomNavigationView

android.support.v7.widget.SimpleItemAnimator -> androidx.recyclerview.widget.SimpleItemAnimator

android.support.v8.renderscript. -> androidx.renderscript.

android.support.design.widget.FloatingActionButton -> com.google.android.material.floatingactionbutton.FloatingActionButton

android.support.v7.widget.PagerSnapHelper -> androidx.recyclerview.widget.PagerSnapHelper


4.更新 ButterKnife 和 ShadowLayout 库到androidx兼容版本

implementation 'com.jakewharton:butterknife:8.8.1' -> implementation 'com.jakewharton:butterknife:10.2.1'

annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1' -> annotationProcessor 'com.jakewharton:butterknife-compiler:10.2.1' 

5.升级gradle

com.android.tools.build:gradle:3.4.1 -> com.android.tools.build:gradle:7.1.2

distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip -> distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-all.zip

6.根目录的build.gradle文件中的依赖路径全部改为https的

7.注销build.gradle文件中的自定义路径(gradle tool插件7.x版本好像不支持自定义路径)

variant.outputs.all {
            // 自定义输出路径
            if (variant.buildType.name == "release") {
                variant.getPackageApplication().outputDirectory = new File(project.rootDir.absolutePath + File.separator + "app/build/outputs/apk/release")
            } else {
                variant.getPackageApplication().outputDirectory = new File(project.rootDir.absolutePath + File.separator + "app/build/outputs/apk/debug")
            }
        }

8.适配webView

mWebSettings.setAppCachePath(appCachePath);

webView.getSettings().setAppCacheEnabled(false); -> webView.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);

mWebSettings.setAppCacheEnabled(true) -> mWebSettings.setCacheMode(WebSettings.LOAD_DEFAULT);

9.适配截屏服务:

在manifest.xml文件中添加权限和service


            android:name=".xxxService"
            android:foregroundServiceType="mediaProjection"
            tools:node="replace"
            android:exported="false"/>

10.其他改动待补充


 

你可能感兴趣的:(android,android)