Can't use permissions API in SDK 29

After upgrading to SDK 29, I am getting an error when I try to request location permissions in my detached app:

Error: No visible activity. Must request location when visible.

I have replicated this in a fresh expo app by:
exp init
exp detach

Note: I got errors in android studio until I added expokit as a dependency in package.json

Once I have the default app up and running, I add componentDidMount in the default App.js and request location permission:

Permissions.askAsync(Permissions.LOCATION)

This gives the error:
[11:55:23] [Unhandled promise rejection: Error: No visible activity. Must request location when visible.]

  • node_modules\react-native\Libraries\BatchedBridge\NativeModules.js:121:42 in createErrorFromErrorData
  • node_modules\react-native\Libraries\BatchedBridge\NativeModules.js:78:57 in
  • ā€¦ 5 more stack frames from framework internals

I am using exp version 55.0.5

Any advice or help with this would be appreciated.

1 Like

I Have the same Issue, on detached App

A fix was recently landed, which should fix this Permissions issue.
cc: @tsapeta @sjchmiela

1 Like

Hi all, I confirmed this issue exists, it happens due to a bug in DetachedModuleRegistryAdapter, which doesnā€™t add modules from ReactAdapterPackage to the module registry. Iā€™ll fix this issue upstream and post here a quick workaround for detached applications in a bit.

1 Like

Hi all!

A quick workaround would be to:

  1. create your own subclass of ModuleRegistryAdapter.
  2. create your own subclass of UIManagerModuleWrapper.
  3. point MainActivity to use your ModuleRegistryAdapter subclass.

Classes for 1. and 2. can be found here: https://gist.github.com/sjchmiela/cbe0738171be44feb04f6342a5c352b8

To point to your subclass, override this method in MainActivity:

  @Override
  public ExpoModuleRegistryAdapter getScopedModuleRegistryAdapterForPackages(List<Package> packages) {
    return new MyModuleRegistryAdapter(new ReactModuleRegistryProvider(packages));
  }

Sorry for the inconvenience, weā€™re working on a fix. :slight_smile:

2 Likes

Hi all,
Thank you very much for getting back to me so quickly about this, I do appreciate it.

The workaround did the trick and everything is now working again.

Iā€™ll keep an eye out for the upstream fix as well.

Thanks again for your help!

1 Like

@sjchmiela, this code works on develop mode, when i build a release APK, the Notifications requests stop working again.

    buildTypes {
        debug {
            debuggable true
            ext.enableCrashlytics = false
            signingConfig signingConfigs.configs
        }
        release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
            zipAlignEnabled true
            signingConfig signingConfigs.configs
        }
    }

It Works by Removing ā€˜minifyEnabledā€™ and ā€˜proguardFilesā€™

        release {
            zipAlignEnabled true
            signingConfig signingConfigs.configs
        }

Could you please clarify what do you mean by Notifications requests stop working? :slightly_smiling_face:

1 Like

@sjchmiela
When use Permission.asksync(ā€¦), do nothing!

1 Like

Iā€™m also with the same issue. I created an ā€œissueā€ on github and linked to this post. https://github.com/expo/expo/issues/2087

Hi all, thanks for your patience?

Could you please follow the instructions Iā€™ve put in https://github.com/expo/expo/issues/2087#issuecomment-414996822 and see if it helps to resolve the issue?

1 Like

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.