react-native-android-location-enabler
react-native-android-location-enabler copied to clipboard
Error: Undefined an object reactNativeAndroidLocationEnabler2
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",

Can you post the code, that lead you to this error ?
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
Ok, I'll will check this asap.
same issue plz
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
);
}
}
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 .
Same issue here..
Did you follow the installation instruction correctly ?
same issue
Did you follow the installation instruction correctly ?
yes
RNAndroidLocationEnabler is Undefined
@devnasim Did you import the RNAndroidLocationEnabler in your code ?
import RNAndroidLocationEnabler from 'react-native-android-location-enabler';
does it work on expo ?
when I import the module import RNAndroidLocationEnabler from 'react-native-android-location-enabler';
I get in RNAndroidLocationEnabler undefined
value
when I import the module
import RNAndroidLocationEnabler from 'react-native-android-location-enabler';
I get in RNAndroidLocationEnablerundefined
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
}
Same problem here, did anyone find the solution?
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
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 = (