• 升级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

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

    android.arch.lifecycle.ViewModelProviders -> androidx.lifecycle.ViewModelProviders

    android.arch.lifecycle.Observer -> androidx.lifecycle.Observer

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

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

    android.support.v7.app.AppCompatActivity -> androidx.appcompat.app.AppCompatActivity

    android.support.transition.Transition -> androidx.transition.Transition

    android.support.v7.app.ActionBar -> androidx.appcompat.app.ActionBar

    android.support.v7.app.AppCompatDelegate -> androidx.appcompat.app.AppCompatDelegate


    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.其他改动待补充


     

  • 相关阅读:
    试试这些方法,误删文件怎么恢复?
    本地demo服务器搭建计划——(二)服务中心consul安装&防火墙配置
    Stable Diffusion搭建全过程记录,生成自己的专属艺术照
    一篇带你搞定⭐《生产环境JVM日志配置》⭐
    应用层使用select进行检测连接状态
    y7000p 2020h风扇狂转解决办法
    BlockingQueue(阻塞队列)详解
    信息隐藏与探索 中职网络安全
    蓝桥等考Python组别九级004
    iptables总结存档
  • 原文地址:https://blog.csdn.net/ronaldo4511/article/details/133308964