简体   繁体   English

由于需要READ_EXTERNAL_STORAGE权限而崩溃,即使它在清单中

[英]Crash due to requiring READ_EXTERNAL_STORAGE permission even though it's in the Manifest

I've got the task of updating an Android application that was previously built with the following settings: 我的任务是更新以前使用以下设置构建的Android应用程序:

compileSdkVersion 19
buildToolsVersion '19.0.1'

defaultConfig {
    minSdkVersion 15
    targetSdkVersion 19
}

I downloaded the latest Android Studio and ended up changing these to the following to get the app to build: 我下载了最新的Android Studio,最终将其更改为以下内容,以构建应用程序:

compileSdkVersion 21
buildToolsVersion '21.1.2'

defaultConfig {
    minSdkVersion 15
    targetSdkVersion 19
}

The previously built app worked perfectly without any crash. 先前构建的应用程序完美运行,没有崩溃。 Unfortunately when I build it now the app crashes with the following exception: 不幸的是,当我现在构建它时,应用程序崩溃,但以下异常:

Caused by: java.lang.SecurityException: Permission Denial: reading com.android.providers.media.MediaProvider uri content://media/external/images/media from pid=2476, uid=10053 requires android.permission.READ_EXTERNAL_STORAGE, or grantUriPermission()

Even though the permission is clearly in the manifest: 即使清单中清楚地显示了许可:

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

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

The crash occurs at the point of loading a cursor for MediaStore.Images.Media.EXTERNAL_CONTENT_URI : 崩溃发生在为MediaStore.Images.Media.EXTERNAL_CONTENT_URI加载游标时:

new CursorLoader(
                this,
                MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
                new String[]{
                        MediaStore.Images.Media._ID,
                        MediaStore.Images.Media.BUCKET_ID,
                        MediaStore.Images.Media.BUCKET_DISPLAY_NAME,
                        MediaStore.Images.Thumbnails._ID
                },
                null,
                null,
                null
        );

I'm a little bit stumped as to what to do beyond ripping the whole component out and reimplementing from scratch -- which I'd prefer to avoid ;) 除了将整个组件拆下来并从头开始重新实现之外,我对如何处理感到有些困惑-我宁愿避免;)

It turns out that a project dependency had a maxSDKVersion attribute in the libraries in AndroidManifest.xml for these permissions: 事实证明,项目依赖项在AndroidManifest.xml的库中具有以下权限的maxSDKVersion属性:

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

During the manifest merge process that attribute would get included and break things on any device running above API version 18. 在清单合并过程中,该属性将被包含在内,并在API版本18以上运行的任何设备上破坏东西。

One approach to fixing this is to add the following applications manifest that will ensure the maxSdkVersion attributes don't make it into the merged AndroidManifest.xml : 解决此问题的一种方法是添加以下应用程序清单,以确保maxSdkVersion属性不会使其进入合并的AndroidManifest.xml

<manifest
    xmlns:tools="http://schemas.android.com/tools"
    ...>

<uses-permission tools:node="replace" android:name="android.permission.WRITE_EXTERNAL_STORAGE" android:maxSdkVersion="18" />
<uses-permission tools:node="replace" android:name="android.permission.READ_EXTERNAL_STORAGE" android:maxSdkVersion="18" />

暂无
暂无

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

相关问题 READ_EXTERNAL_STORAGE权限,尽管清单中有此权限,但应用程序崩溃 - READ_EXTERNAL_STORAGE permission, app crash despite I have this in manifest 即使我在清单中声明,Read_external_storage 权限也不起作用,不在 android 工作室中运行 - Read_external_storage permission is not working even i have declared in manifest,not running in android studio Android READ_EXTERNAL_STORAGE 权限不起作用 - Android READ_EXTERNAL_STORAGE permission not working Android 的 READ_EXTERNAL_STORAGE 权限 - READ_EXTERNAL_STORAGE permission for Android READ_EXTERNAL_STORAGE 是否可以根据情况在 Android 11 中提供不同程度的访问权限? - Is it possible for READ_EXTERNAL_STORAGE to give varying degrees of access, in Android 11 depending on the circumstance? 如何在 android 11 上使用没有 READ_EXTERNAL_STORAGE 的 File("/sdcard/myfile")? - How use File("/sdcard/myfile") without READ_EXTERNAL_STORAGE on android 11? 即使给定了读/写权限,也无法从外部存储读取或创建文件 - Failure to read or create a file from external storage even though given read/write permissions android.Manifest.permission.WRITE_EXTERNAL_STORAGE-应用程序崩溃 - android.Manifest.permission.WRITE_EXTERNAL_STORAGE - application crashes 即使我在清单中定义了权限,在运行时检查权限仍然失败 - Checking for permission at runtime is failing even though I have said permission defined in the manifest 即使在清单类路径中包含了JAR,也不会出现NoClassDefFoundError - NoClassDefFoundError even though the JAR's are included in Manifest Class-Path
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM