简体   繁体   English

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

[英]Android 33 - issues in manifest and layout files in Android Studio

Currently in my Android app I have targetSdkVersion 32 and in my AndroidManifest.xml file I have:目前在我的 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">

Everything is fine and working well.一切都很好,运行良好。

However now when I am updating my app, Android Studio (Chipmunk | 2021.2.1) suggests to use targetSdkVersion 33 .但是现在当我更新我的应用程序时,Android Studio (Chipmunk | 2021.2.1) 建议使用targetSdkVersion 33 After I do that, there are issues in AndroidManifest.xml:在我这样做之后,AndroidManifest.xml 中存在问题:

unknown attribute android:supportsRtl
unknown attribute android:screenOrientation
unknown attribute android:windowSoftInputMode 

and also multiple issues in XML layout files.以及 XML 布局文件中的多个问题。 eg:例如:

unknown android:contentDescription
unknown android:layout_toEndOf

and much more...以及更多...

I already tried to invalidate caches, rebuild the project, nothing helps.我已经尝试使缓存无效,重建项目,没有任何帮助。 Only switching back to target version 32 helps.只有切换回目标版本 32 才有帮助。 Are those attributes really deprecated or is there any issue?这些属性真的被弃用了还是有什么问题? It doesn't say deprecated, just unknown.它没有说已弃用,只是未知。

I also deleted physically the files from cache folders, I also reinstalled the API 33 SDK, nothing helped.我还从缓存文件夹中物理删除了文件,我还重新安装了 API 33 SDK,没有任何帮助。

I even reinstalled Android Studio, with no luck.我什至重新安装了 Android Studio,但没有运气。 Seems something is wrong with API 33 vs Android Studio. API 33 与 Android Studio 似乎有问题。

I recently rolled back a project from version 33 to 32 of the SDK tools because of multiple erroneous issues with XML files, including lack of autocomplete of valid attributes.我最近将一个项目从 SDK 工具的版本33回滚到32 ,因为 XML 文件存在多个错误问题,包括缺少有效属性的自动完成。

Although rolling back goes against general best practice, the project I'm maintaining uses Lint warnings as a secondary code quality metric, so all of the erroneous Unknown attribute warnings was polluting our reports, making it look like code quality had dipped when in reality it hadn't changed;尽管回滚违背了一般的最佳实践,但我正在维护的项目使用 Lint 警告作为辅助代码质量指标,因此所有错误的Unknown attribute警告都在污染我们的报告,看起来代码质量实际上已经下降了没有改变; at this time version 33 of the build-tools really do appear to be broken and quite buggy.此时版本33build-tools确实看起来很糟糕并且有很多错误。

To temporarily fix the issue, I made the following changes to <app module>/build.gradle , and the code completion, and Lint warning count are functioning as they were before the "upgrade" to 33 .为了暂时解决这个问题,我对<app module>/build.gradle进行了以下更改,并且代码完成和 Lint 警告计数的功能与“升级”到33之前一样。

  1. Revert to 32 from 33 for compileSdkVersion and targetSdkVersion fields. compileSdkVersiontargetSdkVersion字段从33恢复到32
  2. Add //noinspection OldTargetApi comment.添加//noinspection OldTargetApi注释。
android {

    compileSdkVersion 32

    defaultConfig {

        //noinspection OldTargetApi
        targetSdkVersion 32

    }
}

Optional Step可选步骤

Whenever using //noinspection comments or annotations to temporarily disable code inspection for a known reason, it's good practice to add a ticket to your issue tracking system to ensure that it's checked and removed once the root cause has been fixed.每当使用//noinspection注释或注解来暂时禁用已知原因的代码检查时,最好在问题跟踪系统中添加一张票,以确保在修复根本原因后检查并删除它。

In my case because I don't want this to ship to production with //noinspection tag in place, I added a ticket to the issue tracker, and added a StopShip comment right above it.在我的例子中,因为我不希望它在带有//noinspection标签的情况下交付生产,所以我向问题跟踪器添加了一张票,并在其上方添加了一个StopShip评论。 If you have Lint configured to failOnError , this will prevent a release from being built and shipped to production, but won't block development or debug builds in the meantime.如果您将 Lint 配置为failOnError ,这将阻止构建版本并将其交付到生产环境,但同时不会阻止开发或调试构建。

Here's what that looks like:看起来是这样的:

android {

    compileSdkVersion 32

    defaultConfig {

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

    }

    lint {
        abortOnError true
        fatal 'StopShip'
    }
}

That will result in an error if you try to create a release build, which looks something like this:如果您尝试创建发布版本,这将导致错误,如下所示:

> 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.

This last step is only necessary if you don't want to ship until SDK Tools for 33 are fixed.仅当您不想在 SDK 33 工具修复之前发货时,才需要最后一步。

Have the same issue, xml attribute such as padding, textColor, etc is missing in Android 33 SDK.遇到同样的问题,Android 33 SDK 中缺少 xml 属性,例如 padding、textColor 等。 You have to hardcode the attributes.您必须对属性进行硬编码。 I have switch back to 32. Think it is a bug of Android studio.我已经切换回 32。认为这是 Android 工作室的错误。

I found out, that under SDK The Android 33 API is missing Sources for Android 33, while Android 32 and lower each has this component there. I found out, that under SDK The Android 33 API is missing Sources for Android 33, while Android 32 and lower each has this component there. Not sure, but this may be the cause of the issue.不确定,但这可能是问题的原因。

For now I will stay with 32 API.现在我将继续使用 32 API。 Seems the Android Studio Lint is in a hurry to use 33 version.似乎 Android Studio Lint 急于使用 33 版本。 在此处输入图像描述

According to this issue tracker bug , Android Studio Chipmunk before Patch 2 does not support Android 13. Patch 2 did seemingly add support.根据此问题跟踪器错误,补丁 2 之前的 Android Studio Chipmunk 不支持 Android 13。 补丁 2似乎确实增加了支持。 However, Android Studio Chipmunk does not have support for Android Gradle Plugin 7.3.0-beta05, which is also required for Android 13 support. However, Android Studio Chipmunk does not have support for Android Gradle Plugin 7.3.0-beta05, which is also required for Android 13 support.

On my end, I've found doing this will work:就我而言,我发现这样做会奏效:

  1. Switch to Android Studio Electric Eel (Yes, the Canary version).切换到 Android Studio Electric Eel(是的,金丝雀版)。 I would say to switch to Dolphin, but that has apparently not been patched to have Android 13 support yet.我会说切换到 Dolphin,但显然尚未修补以支持 Android 13。
  2. Upgrade the AGP version to 7.4.0-alpha09, which supports Android 13. I would upgrade to 7.3.0-beta05, but Electric Eel does not support that version.将AGP版本升级到7.4.0-alpha09,支持Android 13。我会升级到7.3.0-beta05,但是电鳗不支持那个版本。

This probably isn't the best solution for most people, but if you are willing to tolerate unstable versions of development tools it should be fine.对于大多数人来说,这可能不是最好的解决方案,但是如果您愿意容忍开发工具的不稳定版本,那应该没问题。

I have the same issue, with targetSdkVersion 33 .我有同样的问题, targetSdkVersion 33 Then I update Android Studio to (Android Studio Dolphin | 2021.3.1).然后我将 Android Studio 更新为(Android Studio Dolphin | 2021.3.1)。

Issue is solved.问题解决了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM