Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error: Undefined an object reactNativeAndroidLocationEnabler2 #17

Open
kokorolx opened this issue Dec 1, 2018 · 20 comments
Open

Error: Undefined an object reactNativeAndroidLocationEnabler2 #17

kokorolx opened this issue Dec 1, 2018 · 20 comments

Comments

@kokorolx
Copy link

kokorolx commented Dec 1, 2018

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

@Richou
Copy link
Owner

Richou commented Dec 2, 2018

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

@kokorolx
Copy link
Author

kokorolx commented Dec 3, 2018

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

@Richou
Copy link
Owner

Richou commented Dec 4, 2018

Ok, I'll will check this asap.

@Vigneshshivan-source
Copy link

same issue plz

@Richou
Copy link
Owner

Richou commented Jan 12, 2019

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
      );
    }
}

@Vigneshshivan-source
Copy link

Vigneshshivan-source commented Jan 13, 2019 via email

@fnLog0
Copy link

fnLog0 commented Feb 2, 2019

Same issue here..

@Richou
Copy link
Owner

Richou commented Feb 2, 2019

Did you follow the installation instruction correctly ?

@narek11
Copy link

narek11 commented Feb 6, 2019

same issue

@fnLog0
Copy link

fnLog0 commented Feb 7, 2019

Did you follow the installation instruction correctly ?

yes

@fnLog0
Copy link

fnLog0 commented Feb 7, 2019

RNAndroidLocationEnabler is Undefined

@Richou
Copy link
Owner

Richou commented Feb 12, 2019

@devnasim Did you import the RNAndroidLocationEnabler in your code ?

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

@djguruwap
Copy link

does it work on expo ?

@andrey-shostik
Copy link

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

@louicoder
Copy link

louicoder commented Nov 23, 2019

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
}

@JardelSchaefer
Copy link

Same problem here, did anyone find the solution?

@BrunoTerra97
Copy link

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

@JardelSchaefer
Copy link

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 = (

@meta-utkarsh-ahuja
Copy link

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
      );
    }
}
```same but no thing changed please help me out

@Pankaj2208
Copy link

please anyone proper solution for that?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

13 participants