Search code examples
javaandroidandroid-studioandroid-gradle-pluginstorage-access-framework

Storage Access Framework - Some methods of DocumentsContract not compiled when included in my Android app


I would like to add Storage Access Framework support to my app.

I created an utility Java class for some SAF operations.

I added it to a sample project with

compileSdkVersion 29
buildToolsVersion "29.0.0"
minSdkVersion 25
targetSdkVersion 29

and

import androidx.documentfile.provider.DocumentFile;

is inclued.

It is successfully compiled.

My app has

compileSdkVersion 21
buildToolsVersion '28.0.3'
minSdkVersion 21
targetSdkVersion 26

But I see that the method names in

DocumentContracts.copyDocument()

and

DocumentContracts.removeDocument()

are in red (but they belong to API level 19).

If I include

import androidx.documentfile.provider.DocumentFile;

I see that

documentfile

is in red.

Note that auto-completion works on

DocumentsContract

and shows me many methods from SAF.

Furthermore I see that some exceptions are not required anymore like when

renameDocument()

or

createDocument()

are used.

What is wrong? What is the fix?


Solution

  • your app has minSdkVersion 21 (= the app promises to run on android-21 and newer) while your lib has minSdkVersion 25 (=the lib tells that it can not run on android-24 or older)

    so your 21-app cannot use your 25-lib