AAPT: error: attribute android:requestLegacyExternalStorage not found
Asked Answered
A

10

61

collection error in AndroidManifest.xml

AAPT: error: attribute android:requestLegacyExternalStorage not found.

Although the attribute is there but it writes an error

My 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 не найден.

For ionic developers please refer to this answer to fix this issue: https://mcmap.net/q/321800/-aapt-error-attribute-android-requestlegacyexternalstorage-not-found

Allout answered 21/11, 2019 at 13:42 Comment(0)
F
103

(Material Files author here)

You need to compile against SDK 29 and maybe use the most recent build tools for aapt to know this attribute, because it's introduced in Android 10.

Freud answered 23/11, 2019 at 1:51 Comment(4)
Could you elaborate? I am using this and it still fails: buildToolsVersion = "29.0.0" minSdkVersion = 21 compileSdkVersion = 28 targetSdkVersion = 28 supportLibVersion = "28.0.0" googlePlayServicesAuthVersion = "16.0.1"Yunyunfei
You also need to compile against 29.Freud
Thanks! Worked with these values: buildToolsVersion = "29.0.0" minSdkVersion = 21 compileSdkVersion = 29 targetSdkVersion = 29 supportLibVersion = "28.0.0" googlePlayServicesAuthVersion = "16.0.1"Yunyunfei
My minSdkVersion 21 compileSdkVersion 31 targetSdkVersion 31 buildToolsVersion '31'. Still I am facing same error. Any alternatives to try?Brainbrainard
H
29

Make these changes in android\app\build.gradle :

compileSdkVersion 29

targetSdkVersion 29

It will work.

Huebner answered 26/10, 2020 at 2:27 Comment(1)
My minSdkVersion 21 compileSdkVersion 31 targetSdkVersion 31 buildToolsVersion '31'. Still I am facing same error. Any alternatives to try?Brainbrainard
U
11

Add this to build.gradle

subprojects {
    afterEvaluate {project ->
        if (project.hasProperty("android")) {
            android {
                compileSdkVersion 29
                buildToolsVersion "29.0.2"
            }
        }
    }
}
Updo answered 9/10, 2020 at 10:53 Comment(4)
Not just Ionic, This also applied to React NativeLymphangitis
It doesn't make any sense which framework are you using. It makes sense which platform are you using. This is applicable to Android platform. Even if you are using Ionic, Flutter or React NativeHuebner
Thanks for the clarification, i made it a general answer for android platformUpdo
My minSdkVersion 21 compileSdkVersion 31 targetSdkVersion 31 buildToolsVersion '31'. Still I am facing same error. Any alternatives to try?Brainbrainard
C
10

For ionic developers, make sure to update the cordova to the latest version: npm i cordova and then add the android platform: ionic cordova platform add [email protected]

Also make sure to add these into the config.mxl:

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

NOTICE:

SDK v22 means that android versions less than 5.1 will not be able to install the app, knowing that companies usually specify the minimum SDK version as 19 to support al devices.

We cannot requestLegacyExternalStorage on SDKs prior to v22.

In order to overcome this issue, we have to add this permission at run time on devices running android 10+.

Use this plugin to get the current device's SDK version: https://ionicframework.com/docs/native/device

If the SDK version is 10 or above, use this plugin to request the permission: https://ionicframework.com/docs/native/android-permissions

Cursed answered 6/1, 2021 at 12:23 Comment(2)
Worked for me. I'm using ionic-v1. Thanks!!!Imamate
@heaxyh You're talking about ionic/capacitor project and not cordova based.Cursed
S
7

Just delete line android:requestLegacyExternalStorage="true". You can use under Api 29.

Snowplow answered 26/8, 2020 at 9:42 Comment(1)
No. You can't get files from external storage without this line in manifest (API >= 29)Scarce
P
4

Might sound silly but, but you need to apply the compileSdkVersion and targetSdkVersion for all projects you have (e.g. dependencies you compile):

android {
    compileSdkVersion 29
    defaultConfig {
        minSdkVersion 21
        targetSdkVersion 29
        ...
}
Poona answered 27/11, 2020 at 21:47 Comment(0)
H
2

If you are trying to delete android:requestLegacyExternalStorage="true", or changing the values of android:minSdkVersion="xx" and android:targetSdkVersion="xx" but AndroidManifest.xml after a build is restored... you should try compile with an argument. In my case (Angular 8),

tns build android --compileSdk <AndroidVersion> --force
Hydropic answered 12/11, 2020 at 4:4 Comment(0)
K
0

For building a Nativescript 7 project my solution was:

  1. Install 28, 29 & 30 API in Android SDK Manager in Android Studio
  2. Modify the app.gradle file in <project>/App_Resources/Android like this: app.gradle file
  3. Run command: ns clean
  4. Run command: ns debug android
Keener answered 18/12, 2020 at 5:0 Comment(0)
J
-1

This was the only way to fix it for me

android {
    compileSdkVersion 30
Jansenism answered 13/11, 2021 at 21:52 Comment(0)
I
-3

For me the fix was:

npm i cordova
Incautious answered 31/5, 2021 at 15:55 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.