Android 33 - Android Studio 中的清单和布局文件中的问题

Dar*_*ony 34 android android-manifest

目前在我的 Android 应用程序中,targetSdkVersion 32在我的 AndroidManifest.xml 文件中,我有:

<application
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_nameshort"
    android:supportsRtl="false"
    android:theme="@style/AppTheme">
    
    <activity android:name=".MainActivity"
        android:screenOrientation="portrait"
        tools:ignore="LockedOrientationActivity"
        android:windowSoftInputMode="adjustPan"
        android:exported="true">
Run Code Online (Sandbox Code Playgroud)

一切都很好并且运行良好。

然而现在当我更新我的应用程序时,Android Studio (Chipmunk | 2021.2.1) 建议使用targetSdkVersion 33. 执行此操作后,AndroidManifest.xml 中存在问题:

unknown attribute android:supportsRtl
unknown attribute android:screenOrientation
unknown attribute android:windowSoftInputMode 
Run Code Online (Sandbox Code Playgroud)

以及 XML 布局文件中的多个问题。例如:

unknown android:contentDescription
unknown android:layout_toEndOf
Run Code Online (Sandbox Code Playgroud)

以及更多...

我已经尝试过使缓存无效,重建项目,但没有任何帮助。只有切换回目标版本 32 才有帮助。这些属性真的已被弃用还是有任何问题?它并没有说已弃用,只是说未知。

我还从缓存文件夹中物理删除了文件,还重新安装了 API 33 SDK,但没有任何帮助。

我什至重新安装了 Android Studio,但没有成功。API 33 与 Android Studio 似乎有问题。

nto*_*tio 11

根据此问题跟踪器错误,补丁 2 之前的 Android Studio Chipmunk 不支持 Android 13。补丁 2似乎确实添加了支持。但是,Android Studio Chipmunk 不支持 Android Gradle Plugin 7.3.0-beta05,而 Android 13 支持也需要该插件。

就我而言,我发现这样做会起作用:

  1. 切换到 Android Studio Electric Eel(是的,金丝雀版本)。我想说的是切换到 Dolphin,但显然尚未修补以支持 Android 13。
  2. 将AGP版本升级到7.4.0-alpha09,支持Android 13。我想升级到7.3.0-beta05,但电鳗不支持该版本。

对于大多数人来说,这可能不是最好的解决方案,但如果您愿意容忍开发工具的不稳定版本,那应该没问题。

编辑:Android Studio Dolphin 现在应该可以工作了。用那个。


Mat*_*att 7

最近,由于 XML 文件存在多个错误问题(包括缺乏有效属性的自动完成),我将一个项目从 SDK 工具的33版本回滚到了该版本。32

尽管回滚违背了一般的最佳实践,但我正在维护的项目使用 Lint 警告作为辅助代码质量指标,因此所有错误警告Unknown attribute都会污染我们的报告,使其看起来代码质量已经下降,而实际上并没有下降。 t 改变了;此时33的版本build-tools确实似乎已损坏并且有很多错误。

为了暂时解决该问题,我对 进行了以下更改<app module>/build.gradle,代码完成和 Lint 警告计数的功能与“升级”到33.

  1. 恢复到32for和字段33compileSdkVersiontargetSdkVersion
  2. 添加//noinspection OldTargetApi评论。
android {

    compileSdkVersion 32

    defaultConfig {

        //noinspection OldTargetApi
        targetSdkVersion 32

    }
}
Run Code Online (Sandbox Code Playgroud)

可选步骤

每当使用//noinspection注释或注释因已知原因暂时禁用代码检查时,最好向问题跟踪系统添加票证,以确保在修复根本原因后对其进行检查和删除。

就我而言,因为我不希望在带有//noinspection标签的情况下将其运送到生产环境,所以我向问题跟踪器添加了一张票证,并StopShip在其上方添加了一条评论。如果您将 Lint 配置为failOnError,这将阻止构建版本并将其交付到生产环境,但同时不会阻止开发或调试构建。

看起来是这样的:

android {

    compileSdkVersion 32

    defaultConfig {

        //STOPSHIP
        // See issue #378 in Jira for details
        //noinspection OldTargetApi
        targetSdkVersion 32

    }

    lint {
        abortOnError true
        fatal 'StopShip'
    }
}
Run Code Online (Sandbox Code Playgroud)

如果您尝试创建发布版本,这将导致错误,如下所示:

> Task :app:lintRelease FAILED
Lint found 1 errors. First failure:
/src/app/build.gradle:25: Error: STOPSHIP comment found; points to code which must be fixed prior to release [StopShip]
        //STOPSHIP
          ~~~~~~~~
   Explanation for issues of type "StopShip":
   Using the comment // STOPSHIP can be used to flag code that is incomplete
   but checked in. This comment marker can be used to indicate that the code
   should not be shipped until the issue is addressed, and lint will look for
   these. In Gradle projects, this is only checked for non-debug (release)
   builds.
   In Kotlin, the TODO() method is also treated as a stop ship marker; you can
   use it to make incomplete code compile, but it will throw an exception at
   runtime and therefore should be fixed before shipping releases.
Run Code Online (Sandbox Code Playgroud)

仅当您不想在 SDK Tools for 33 修复之前发布时,才需要执行最后一步。


Ami*_*iya 5

我也有同样的问题,与targetSdkVersion 33. 然后我将 Android Studio 更新为 (Android Studio Dolphin | 2021.3.1)。

问题解决了。