package ActivityResultContracts does not exist in Android Studio despite importing the proper depdendencies

588 Views Asked by At

I'm working on updating an older app to be compatible with SDK version 31 from SDK version 30, though the code has been untouched for many years. One of the app's primary functions revolves around location data, which does not work in newer Android versions due to the changes related to location permissions (coarse and fine permissions, 'always allow', etc). I've looked into updating location requests with this Android documentation, but I'm running into an issue with the ActivityResultContracts package. When building the app, I'm met with a 'package does not exist' error, even though I've imported the seemingly correct depdendencies.

I have the following dependencies included (among others) in the build.gradle file for the app, which seem to be the correct ones.

implementation "androidx.appcompat:appcompat:1.5.1"
implementation "androidx.appcompat:appcompat-resources:1.5.1"
implementation "androidx.activity:activity:1.6.1"
implementation "androidx.fragment:fragment:1.5.4"

Despite including these, the build still fails with the error:

error: package ActivityResultContracts does not exist
                registerForActivityResult(new ActivityResultContracts.RequestMultiplePermissions()

I'm not sure if it's just the placement of the code in my app, or if I misconfigured the manifest, but the build is failing when I'd otherwise expect it not to. I've considered migrating the project to AndroidX, but decided against it since there are some very old functions that may or may not just break entirely if I do migrate the project.

Additionally, I was previously having a similar issue with an unresolved reference to registerForActivityResult, but changing the class to inherit ComponentActivity seemed to solve that issue. I'm not sure if this is related to the issue I'm having now.

It's also worth noting that a lot of configuration with this app is outdated, some of which I've updated with no luck. Does anyone know what might be the cause of this issue?

0

There are 0 best solutions below