react-native-android-location-enabler icon indicating copy to clipboard operation
react-native-android-location-enabler copied to clipboard

Error: Undefined an object reactNativeAndroidLocationEnabler2

Open kokorolx opened this issue 6 years ago • 20 comments

I run this package with genymotion -- android 6.0 and have this error Please give me any help. Thanks! package.js:

"react": "16.5.0",
"expo": "^31.0.2",
screen shot 2018-12-01 at 9 26 48 pm

kokorolx avatar Dec 01 '18 14:12 kokorolx

Can you post the code, that lead you to this error ?

Richou avatar Dec 02 '18 19:12 Richou

Here is my code.

import React from 'react';
import { AppRegistry, Text, View, TouchableOpacity, StyleSheet, Alert } from 'react-native';
import RNAndroidLocationEnabler from 'react-native-android-location-enabler';
export default class App extends React.Component {
  constructor(props) {
      super(props);
    }

    componentDidMount() {
      RNAndroidLocationEnabler.promptForEnableLocationIfNeeded({interval: 10000, fastInterval: 5000})
        .then(data => {
          console.log("Location turn on")
        }).catch(err => {
          console.log("Location error: ", err)
        });
    }

    render() {
      return (
        <View style={style.container}>
          <Text style={style.text}>Hello</Text>
        </View>
      );
    }
  }

  const style = StyleSheet.create({
    container: {
      flex: 1,
      alignItems: 'center',
      justifyContent: 'center',
    },
    button: {
      padding: 20,
    },
    text: {
      fontSize: 20,
    },
    textSuccess: {
      fontSize: 20,
      color: 'green',
    },
  });

the image above was checkout. I created new project and have the same error image

kokorolx avatar Dec 03 '18 02:12 kokorolx

Ok, I'll will check this asap.

Richou avatar Dec 04 '18 08:12 Richou

same issue plz

Vigneshshivan-source avatar Jan 12 '19 12:01 Vigneshshivan-source

Did you add the following lines in your android/settings.gradle

include ':react-native-android-location-enabler'
project(':react-native-android-location-enabler').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-android-location-enabler/android')

And this line in dependencies section of your android/app/build.gradle

compile project(':react-native-android-location-enabler')

And finally in your MainApplication.java

import com.heanoria.library.reactnative.locationenabler.RNAndroidLocationEnablerPackage; // Import line

public class MainApplication extends Application implements ReactApplication {

    @Override
    protected List<ReactPackage> getPackages() {
      return Arrays.<ReactPackage>asList(
          new MainReactPackage(),
          new RNAndroidLocationEnablerPackage() // And this one
      );
    }
}

Richou avatar Jan 12 '19 22:01 Richou

I will try and thanks for reply

On Sun, Jan 13, 2019, 03:37 Richard [email protected] wrote:

Did you add the following lines in your android/settings.gradle

include ':react-native-android-location-enabler' project(':react-native-android-location-enabler').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-android-location-enabler/android')

And this line in dependencies section of your android/app/build.gradle

compile project(':react-native-android-location-enabler')

And finally in your MainApplication.java

import com.heanoria.library.reactnative.locationenabler.RNAndroidLocationEnablerPackage; // Import line public class MainApplication extends Application implements ReactApplication {

@Override
protected List<ReactPackage> getPackages() {
  return Arrays.<ReactPackage>asList(
      new MainReactPackage(),
      new RNAndroidLocationEnablerPackage() // And this one
  );
}

}

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/Richou/react-native-android-location-enabler/issues/17#issuecomment-453784592, or mute the thread https://github.com/notifications/unsubscribe-auth/AsMRMbUw9CTU6-aca1BtIJfatxsg90R0ks5vClyqgaJpZM4Y86_e .

Vigneshshivan-source avatar Jan 13 '19 04:01 Vigneshshivan-source

Same issue here..

fnLog0 avatar Feb 02 '19 12:02 fnLog0

Did you follow the installation instruction correctly ?

Richou avatar Feb 02 '19 22:02 Richou

same issue

narek11 avatar Feb 06 '19 12:02 narek11

Did you follow the installation instruction correctly ?

yes

fnLog0 avatar Feb 07 '19 08:02 fnLog0

RNAndroidLocationEnabler is Undefined

fnLog0 avatar Feb 07 '19 08:02 fnLog0

@devnasim Did you import the RNAndroidLocationEnabler in your code ?

import RNAndroidLocationEnabler from 'react-native-android-location-enabler';

Richou avatar Feb 12 '19 12:02 Richou

does it work on expo ?

djguruwap avatar Apr 20 '19 03:04 djguruwap

when I import the module import RNAndroidLocationEnabler from 'react-native-android-location-enabler'; I get in RNAndroidLocationEnabler undefined value

andrey-shostik avatar May 15 '19 17:05 andrey-shostik

when I import the module import RNAndroidLocationEnabler from 'react-native-android-location-enabler'; I get in RNAndroidLocationEnabler undefined value

@andrey-shostik Are you running this on iOS, as far as I'm concerned this will be null or undefined for iOS, wrap this function inside a platform check. I have realised this only works with Android since it's there's a different procedure for toggling location on and off for iOS. Do something like:

if (Platform.OS === 'android') {
  toggleLocation(); // check whether location is enabled or not
} else {
  // block to check ios location enabled or not
}

louicoder avatar Nov 23 '19 04:11 louicoder

Same problem here, did anyone find the solution?

JardelSchaefer avatar Mar 25 '20 21:03 JardelSchaefer

Same problem here, did anyone find the solution?

A had the same problem. To fix this i did: $ npm start -- --reset-cache $ react-native run-android

BrunoTerra97 avatar Apr 06 '20 13:04 BrunoTerra97

Same problem here, did anyone find the solution?

A had the same problem. To fix this i did: $ npm start -- --reset-cache $ react-native run-android

Unfortunately I'm using the expo, but I had looked at a topic here and they said it works = (

JardelSchaefer avatar Apr 06 '20 13:04 JardelSchaefer