Skip to content

[Android] Undefined is not an object (evaluating 'RNOpenSettings.generalSettings') #10

@avencat

Description

@avencat

Hi, I've got an issue using this library, I followed the manual installation section and when I want to open the settings:

import DeviceSettings from 'react-native-device-settings';

class Toto extends React.Component {
  openSettings = () => {
    DeviceSettings.open();
  };

  render() {
    <Button onClick={this.openSettings}>
      Open settings
    </Button>
  }
}

I get a red screen error saying:
undefined is not an object (evaluating 'RNOpenSettings.generalSettings')

My MainActivity.java:

package com.MyApp.app;

import com.facebook.react.ReactActivity;
import com.rjblopes.opensettings.OpenSettingsPackage;

public class MainActivity extends ReactActivity {

    /**
     * Returns the name of the main component registered from JavaScript.
     * This is used to schedule rendering of the component.
     */
    @Override
    protected String getMainComponentName() {
        return "MyApp";
    }
}

I've got these lines on my settings.graddle:

[...]
include ':react-native-device-settings'
project(':react-native-device-settings').projectDir = new File(settingsDir, '../node_modules/react-native-device-settings/android')
[...]

And in my project-level build.gradle:

dependencies {
  [...]
  compile project(':react-native-device-settings')
  [...]
}

RN: 0.55.3
Library npm version: 1.2.0
Android device: Xiaomi Redmi Note 4X
Android simulator: API 27

[EDIT]
I fixed it, instead of doing what Readme.md is saying, I put:

import com.rjblopes.opensettings.OpenSettingsPackage; // Add this import

[...]

public class MainApplication extends Application implements ReactApplication {

  private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) {
    @Override
    public boolean getUseDeveloperSupport() {
      return BuildConfig.DEBUG;
    }

    @Override
    protected List<ReactPackage> getPackages() {
      return Arrays.<ReactPackage>asList(
          new MainReactPackage(),
            new OpenSettingsPackage(), // Add this line
            [...]
      );
    }
[...]

on MainApplication.java and removed:

import com.rjblopes.opensettings.OpenSettingsPackage;

from MainActivity.java

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions