AAPT: error: attribute android:requestLegacyExternalStorage not found

AAPT: error: attribute android:requestLegacyExternalStorage not found

AndroidManifest.xml

中的收集错误

AAPT:错误:未找到属性 android:requestLegacyExternalStorage。

虽然有属性但是写错了

我的AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>

<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="android.apps">

<uses-feature android:name="android.hardware.wifi" android:required="false" />

<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES" />
<uses-permission android:name="android.permission.WAKE_LOCK" />

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

<application
    android:allowBackup="true"
    android:fullBackupContent="true"
    android:icon="@mipmap/launcher_icon"
    android:label="@string/app_name"
    android:requestLegacyExternalStorage="true"
    android:roundIcon="@mipmap/launcher_icon"
    android:supportsRtl="true"
    android:theme="@style/Theme.MaterialFiles"
    tools:ignore="GoogleAppIndexingWarning,UnusedAttribute">

    <activity
        android:name="android.apps.filelist.FileListActivity"
        android:label="@string/file_list_title"
        android:theme="@style/Theme.MaterialFiles.TransparentStatusBar"
        android:visibleToInstantApps="true"
        tools:ignore="UnusedAttribute">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
        <intent-filter tools:ignore="AppLinkUrlError">
            <action android:name="android.intent.action.VIEW" />
            <category android:name="android.intent.category.DEFAULT" />
            <data android:mimeType="inode/directory" />
            <data android:mimeType="resource/folder" />
            <data android:mimeType="vnd.android.document/directory" />
        </intent-filter>
        <!-- @see android.apps.file.MimeTypes#isSupportedArchive(String) -->
        <!--
          ~ We don't really support content URI archives.
          ~ TODO: Figure out a good way to allow choosing this activity only in our app, or
          ~ support content URI archives.
        <intent-filter tools:ignore="AppLinkUrlError">
            <action android:name="android.intent.action.VIEW" />
            <category android:name="android.intent.category.DEFAULT" />
            <data android:mimeType="application/gzip" />
            <data android:mimeType="application/java-archive" />
            <data android:mimeType="application/rar" />
            <data android:mimeType="application/zip" />
            <data android:mimeType="application/vnd.android.package-archive" />
            <data android:mimeType="application/vnd.debian.binary-package" />
            <data android:mimeType="application/x-7z-compressed" />
            <data android:mimeType="application/x-bzip2" />
            <data android:mimeType="application/x-compress" />
            <data android:mimeType="application/x-cpio" />
            <data android:mimeType="application/x-deb" />
            <data android:mimeType="application/x-debian-package" />
            <data android:mimeType="application/x-gtar" />
            <data android:mimeType="application/x-gtar-compressed" />
            <data android:mimeType="application/x-java-archive" />
            <data android:mimeType="application/x-lzma" />
            <data android:mimeType="application/x-tar" />
            <data android:mimeType="application/x-xz" />
        </intent-filter>
        -->
        <!-- @see https://android.googlesource.com/platform/packages/apps/DocumentsUI/+/master/AndroidManifest.xml -->
        <intent-filter>
            <action android:name="android.intent.action.OPEN_DOCUMENT" />
            <category android:name="android.intent.category.DEFAULT" />
            <category android:name="android.intent.category.OPENABLE" />
            <data android:mimeType="*/*" />
        </intent-filter>
        <!--
          ~ Unusable until we implement DocumentsProvider.
        <intent-filter>
            <action android:name="android.intent.action.CREATE_DOCUMENT" />
            <category android:name="android.intent.category.DEFAULT" />
            <category android:name="android.intent.category.OPENABLE" />
            <data android:mimeType="*/*" />
        </intent-filter>
        -->
        <intent-filter>
            <action android:name="android.intent.action.GET_CONTENT" />
            <category android:name="android.intent.category.DEFAULT" />
            <category android:name="android.intent.category.OPENABLE" />
            <data android:mimeType="*/*" />
        </intent-filter>
        <!--
          ~ Unusable until we implement DocumentsProvider.
        <intent-filter>
            <action android:name="android.intent.action.OPEN_DOCUMENT_TREE" />
            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
        -->
        <intent-filter>
            <action android:name="android.apps.intent.action.VIEW_DOWNLOADS" />
            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
        <meta-data
            android:name="android.app.shortcuts"
            android:resource="@xml/shortcuts" />
    </activity>

    <activity
        android:name="android.apps.filelist.OpenFileAsDialogActivity"
        android:autoRemoveFromRecents="true"
        android:icon="@drawable/open_as_icon"
        android:label="@string/file_open_as_title"
        android:theme="@style/Theme.MaterialFiles.Translucent" />

    <activity
        android:name="android.apps.ftpserver.FtpServerActivity"
        android:label="@string/ftp_server_title"
        android:launchMode="singleTop"
        android:theme="@style/Theme.MaterialFiles">
        <intent-filter>
            <action android:name="android.apps.intent.action.MANAGE_FTP_SERVER" />
            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
        <meta-data
            android:name="android.support.PARENT_ACTIVITY"
            android:value="android.apps.filelist.FileListActivity" />
    </activity>

    <activity
        android:name="apps.settings.SettingsActivity"
        android:label="@string/settings_title"
        android:launchMode="singleTop"
        android:theme="@style/Theme.MaterialFiles">
        <intent-filter>
            <action android:name="android.intent.action.APPLICATION_PREFERENCES" />
            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
        <meta-data
            android:name="android.support.PARENT_ACTIVITY"
            android:value="android.apps.filelist.FileListActivity" />
    </activity>

    <activity
        android:name="android.apps.settings.StandardDirectoriesActivity"
        android:label="@string/settings_standard_directories_title"
        android:launchMode="singleTop"
        android:theme="@style/Theme.MaterialFiles">
        <meta-data
            android:name="android.support.PARENT_ACTIVITY"
            android:value="android.apps.settings.SettingsActivity" />
    </activity>

    <activity
        android:name="android.apps.settings.BookmarkDirectoriesActivity"
        android:label="@string/settings_bookmark_directories_title"
        android:launchMode="singleTop"
        android:theme="@style/Theme.MaterialFiles">
        <meta-data
            android:name="android.support.PARENT_ACTIVITY"
            android:value="android.apps.settings.SettingsActivity" />
    </activity>

    <activity
        android:name="android.apps.about.AboutActivity"
        android:label="@string/about_title"
        android:launchMode="singleTop"
        android:theme="@style/Theme.MaterialFiles">
        <meta-data
            android:name="android.support.PARENT_ACTIVITY"
            android:value="com.filemanagere.android.apps.filelist.FileListActivity" />
    </activity>

    <activity
        android:name="android.apps.filejob.FileJobActionDialogActivity"
        android:autoRemoveFromRecents="true"
        android:theme="@style/Theme.MaterialFiles.Translucent" />

    <activity
        android:name="android.apps.filejob.FileJobConflictDialogActivity"
        android:autoRemoveFromRecents="true"
        android:theme="@style/Theme.MaterialFiles.Translucent" />

    <activity
        android:name="android.apps.viewer.text.TextEditorActivity"
        android:label="@string/text_editor_title"
        android:theme="@style/Theme.MaterialFiles">
        <intent-filter tools:ignore="AppLinkUrlError">
            <action android:name="android.intent.action.VIEW" />
            <category android:name="android.intent.category.DEFAULT" />
            <data android:mimeType="application/ecmascript" />
            <data android:mimeType="application/javascript" />
            <data android:mimeType="application/json" />
            <data android:mimeType="application/typescript" />
            <data android:mimeType="application/x-sh" />
            <data android:mimeType="application/x-shellscript" />
            <data android:mimeType="application/xml" />
            <data android:mimeType="text/*" />
        </intent-filter>
    </activity>

    <activity
        android:name="android.apps.viewer.image.ImageViewerActivity"
        android:label="@string/image_viewer_title"
        android:theme="@style/Theme.MaterialFiles.Immersive">
        <intent-filter tools:ignore="AppLinkUrlError">
            <action android:name="android.intent.action.VIEW" />
            <category android:name="android.intent.category.DEFAULT" />
            <data android:mimeType="image/*" />
        </intent-filter>
    </activity>

    <service android:name="android.apps.filejob.FileJobService" />

    <service android:name="android.apps.ftpserver.FtpServerService" />

    <provider
        android:name="android.apps.AppProvider"
        android:authorities="@string/app_provider_authority"
        android:exported="false" />

    <provider
        android:name="android.apps.file.FileProvider"
        android:authorities="@string/file_provider_authority"
        android:exported="false"
        android:grantUriPermissions="true" />

    <receiver android:name="android.apps.filejob.FileJobReceiver" />

    <receiver android:name="android.apps.ftpserver.FtpServerReceiver" />

    <meta-data
        android:name="firebase_crashlytics_collection_enabled"
        android:value="false" />

    <!-- We need to reference a MD2 theme in XML for R8 to keep relevant resources. -->
    <activity
        android:name=".KeepMd2Resources"
        android:theme="@style/Theme.MaterialFiles.Md2" />
</application>

有认识的人可以回答吗? AndroidManifest.xml

处的收集错误

AAPT:错误:属性android:未找到 requestLegacyExternalStorage。

离子开发者请参考这个答案来解决这个问题:

(Material 文件作者在这里)

您需要针对 SDK 29 进行编译,并且可能使用 aapt 的最新构建工具才能了解此属性,因为它已在 Android 10.

中引入

只需删除行 android:requestLegacyExternalStorage="true"。 Api 29.

下可以使用

将此添加到 build.gradle

subprojects {
    afterEvaluate {project ->
        if (project.hasProperty("android")) {
            android {
                compileSdkVersion 29
                buildToolsVersion "29.0.2"
            }
        }
    }
}

在 android\app\build 中进行这些更改。gradle :

compileSdkVersion 29

targetSdkVersion 29

它会起作用。

如果您尝试删除 android:requestLegacyExternalStorage="true",或更改 android:minSdkVersion="xx"android:targetSdkVersion="xx" 的值,但 AndroidManifest.xml 之后构建已恢复...您应该尝试使用参数进行编译。就我而言 (Angular 8),

tns build android --compileSdk <AndroidVersion> --force

听起来可能很傻,但是您需要为您拥有的所有项目(例如您编译的依赖项)应用 compileSdkVersion 和 targetSdkVersion:

android {
    compileSdkVersion 29
    defaultConfig {
        minSdkVersion 21
        targetSdkVersion 29
        ...
}

为了构建 Nativescript 7 项目,我的解决方案是:

  1. 在 Android Studio
  2. 的 Android SDK 管理器中安装 28, 29 & 30 API
  3. 像这样修改 <project>/App_Resources/Android 中的 app.gradle 文件: app.gradle file
  4. 运行 命令:ns clean
  5. 运行 命令:ns debug android

对于 ionic 开发者,确保将 cordova 更新到最新版本:npm i cordova 然后添加 android 平台:ionic cordova platform add android@9.0.0

还要确保将这些添加到 config.mxl:

<preference name="android-minSdkVersion" value="22" />
<preference name="android-compileSdkVersion" value="29" />
<preference name="android-targetSdkVersion" value="29" />

注意:

SDK v22是指android小于5.1的版本将无法安装app,要知道一般公司都会指定最低SDK版本为19来支持所有设备。

我们无法在 v22 之前的 SDK 上requestLegacyExternalStorage

为了解决这个问题,我们必须在 运行 时间在 运行ning android 10+ 设备上添加此权限。

使用此插件获取当前设备的SDK版本: https://ionicframework.com/docs/native/device

如果SDK版本为10以上,使用此插件申请权限: https://ionicframework.com/docs/native/android-permissions

对我来说,修复是:

npm i cordova

这是为我修复它的唯一方法

android {
    compileSdkVersion 30