首页 > 解决方案 > 定位 API 28 更新

问题描述

我有几个带有 target 的应用程序,SDK 26众所周知,自从 google 对 Play 商店SDK要求应用了新规则后,我必须将我的 target 更新SDK为 28,这涉及到很多更新!

我最近几天尝试进行更新,但遇到了很多错误:

因此,我将一切都设置回 targetAPI 26以在应用程序上进行一些更改,然后再明确更新为 target API 28

我的问题是:为了避免此类冲突,我必须使用的最佳方法/预期和最佳 android studio 版本是什么。

标签: androidandroid-api-levels

解决方案


在遇到问题中提到的几个问题后,我成功地将我的项目更新为targetSdkVersion, 在这里我将写下我遵循的所有步骤以及我所做的更改。compileSdkVersion28

  • 我 - 步骤:

1 - 将我的 android studio 更新到最新版本

2 - 更新我的 gradle 插件版本,gradle 版本(5.4.1)

dependencies {
    classpath 'com.android.tools.build:gradle:3.5.1'
    .........
}

3 - 迁移到androidx图书馆

4 - 将所有 3rd 库(Firebase、google play services、Picasso ......)更新到最新版本

implementation 'com.google.firebase:firebase-appindexing:19.0.0'
implementation 'com.google.android.gms:play-services-places:17.0.0'
implementation 'com.google.android.gms:play-services-maps:17.0.0'
implementation 'com.google.android.gms:play-services-location:17.0.0'
implementation 'com.google.android.gms:play-services-auth:17.0.0'
implementation 'com.squareup.picasso:picasso:2.71828'
implementation 'com.github.f0ris.sweetalert:library:1.5.1'
implementation 'com.google.firebase:firebase-messaging:20.0.1'
..........
..........

5 -google-services将插件版本更新到最新版本

  dependencies {
    ........
    classpath 'com.google.gms:google-services:4.3.3'
}

6 -google()在项目 gradle 中添加存储库

repositories {
    jcenter()
    google()
}

allprojects {
repositories {
    jcenter()
    mavenCentral()
    maven {
        url 'https://maven.google.com'
    }
    google()
 }
}

7 -compileOption在 app gradle 中添加 Java 8

compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
}
  • 二 - 变化:

对于更改,它确实取决于您正在使用的小部件和库,但通常应该提到一些重要的点:

1. 启用对所有类型连接 HTTP 和 HTTPS 的请求

添加usesCleartextTrafficAndroidManifest.xml

<application
...
android:usesCleartextTraffic="true"
...>

指示应用程序是否打算使用明文网络流量,例如明文HTTPAPI面向级别27或更低级别的应用的默认值为"true". 目标API级别28或更高级别的应用默认为"false".

2 - 弃用和方法更改

某些方法将被提及为已弃用甚至找不到,因此请确保检查代码的每一行以更新或重写可疑方法

3 - 小部件属性弃用

如上所述,一些小部件可能与之前完成的更新有关,因此请务必检查您的布局是否有弃用或问题


注意:

如果这里有什么需要注意或添加的,那就太好了。希望它会在未来对其他人有所帮助。


推荐阅读