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

<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />

<uses-permission android:name="android.permission.MEDIA_PROJECTION" />

<service

android:name=".xxxService"

android:foregroundServiceType="mediaProjection"

tools:node="replace"

android:exported="false"/>

10.其他改动待补充

相关推荐
小七有话说7 分钟前
DevUI与企业级中后台系统融合:低代码表单构建器实战
android·rxjava·devui
暗碳1 小时前
安卓abx二进制xml文件转换普通xml文件
android·xml
4z331 小时前
Android15 Framework(3):系统服务进程 SystemServer 解析
android·源码阅读
没有了遇见2 小时前
Android 之Google Play bundletool 校验 AAB包
android·google
yuanhello2 小时前
【Android】Android的键值对存储方案对比
android·java·android studio
Ditglu.2 小时前
CentOS7 MySQL5.7 主从复制最终版搭建流程(避坑完整版)
android·adb
恋猫de小郭2 小时前
Android Studio Otter 2 Feature 发布,最值得更新的 Android Studio
android·前端·flutter
走在路上的菜鸟3 小时前
Android学Dart学习笔记第十二节 函数
android·笔记·学习·flutter
没有了遇见3 小时前
Android + Google Play:老项目适配实战指南
android·google
怀君3 小时前
Uniapp——开发Android插件教程
android·uni-app