NathanaelA / nativescript-permissions

Wraps up the entire Android 6 permissions system in a easy to use plugin.
MIT License
46 stars 22 forks source link

Webpack: Android is not defined #40

Closed jeremypele closed 5 years ago

jeremypele commented 5 years ago

Hi,

on the latest version, I'm facing the issue android is not defined when I want to bundle a release version that I've trailed down to this specific line

https://github.com/NathanaelA/nativescript-permissions/blob/8cb1507a7bfb3dcf1e9b735b7b9bd444d765744e/src/permissions.android.js#L165

Tried to add guard clause on android property, but not working either if (!android || !android.support || !android.support.v4

I've search for a couple of days to fix that, any idea why it's happening?

NathanaelA commented 5 years ago

Yep, the reason it is happening is because android isn't defined under NS 6. This actually should be a pretty simple fix to support it properly...

NathanaelA commented 5 years ago

@jeremypele - Try version 1.3.7 and see if that fixes it for you.

jeremypele commented 5 years ago

@NathanaelA Yes it did! I succeeded to build with the same modification (put global before any android accessor) but only into hasSupportVersion4, so builded but issues during runtime. Guess all instances needed to be prefixed :)

Many thanks 🙏 🎉

Edit: Just a missing guard clause to test global.android is defined before trying to access support => https://github.com/NathanaelA/nativescript-permissions/pull/41

NathanaelA commented 5 years ago

@jeremypele - global.android should be defined, android technically should also be defined -- but I suspect the issue is that the script that creates the snapshot has a bug in it that thinks android is no longer defined.

DariosKrimsKrams commented 4 years ago

Typescript Example-Code based on @jeremypele's solution:

permissions.requestPermission(
  (global as any).android.Manifest.permission.READ_EXTERNAL_STORAGE,
  'I need these permissions because I\'m cool')
  .then...