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

M sensor manager not loading #12

Closed
lessthan1 opened this issue Jul 20, 2016 · 13 comments
Closed

M sensor manager not loading #12

lessthan1 opened this issue Jul 20, 2016 · 13 comments

Comments

@lessthan1
Copy link

Apparently, I've followed your installation steps using rnpm and after pasting sensor manager + accelerometer code to my blank new project an error was caused because require('NativeModules').SensorManager; did not load anything. Any reason why?

'undefined is not an object(evaluating mSensorManager.startAccelerometer)'

@marktolson
Copy link

I also received this issue after using the npm installer. I have not worked out how to get it going yet.

@lessthan1
Copy link
Author

I have looked at the whole require('NativeModules') object and it seems like the module is not there. You said that you received this issue when using npm... Is there a different way of installing it? Thx.

@lessthan1
Copy link
Author

And if you managed to make it work (even without nativeModules) could you please upload and send me your project? I might be able to do something with it....

@abdelmalekkkkk
Copy link

Hey, I'm having the same problem. Can someone help please

@kprimice
Copy link
Owner

I will look into it as soon as I have time. It's probably due to an update or so...

@abdelmalekkkkk
Copy link

abdelmalekkkkk commented Jul 22, 2016

I just found a solution. If you installed it using 'rnpm link' you should do one more thing, and that is to register the modules in the MainApplication.java file under android/src/main/java/com/...
You can do that by adding these lines:

import com.sensormanager.SensorManagerPackage; // <------ add package

public class MainActivity extends ReactActivity {
   // ...
    @Override
    protected List<ReactPackage> getPackages() {
      return Arrays.<ReactPackage>asList(
        new MainReactPackage(), // <---- add comma
        new SensorManagerPackage() // <---------- add package
      );
    }

@kprimice
Copy link
Owner

rnpm used to take care about that...
Thank you for sharing!

@abdelmalekkkkk
Copy link

It still does I think, but it changes the wrong file.
I found this line in my MainActivity file
import com.sensormanager.SensorManagerPackage;

@marktolson
Copy link

I had to use rnpm to get this to work however the suggested fix does not work with npm (at least last time I tried).

@mileung
Copy link

mileung commented Aug 4, 2016

This solution doesn't work for me. This is what my MainActivity.java file looks like (moonphase is my app's name)

package com.moonphase;

import java.util.Arrays;
import java.util.List;
import com.facebook.react.ReactPackage;
import com.facebook.react.shell.MainReactPackage;

import com.facebook.react.ReactActivity;
import com.sensormanager.SensorManagerPackage;

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 "MoonPhase";
    }

    protected List<ReactPackage> getPackages() {
      return Arrays.<ReactPackage>asList(
        new MainReactPackage(), // <---- add comma
        new SensorManagerPackage() // <---------- add package
      );
    }
}

I'm not using @Override for getPackages because if I do, my terminal will throw an error saying I'm not overriding anything.

@cristianszwarc
Copy link

similar issues here, followed the manual instructions and getting the "error: method does not override or implement a method from a supertype", and not working if I remove the override

hope some one find what's the issue 👍

android/settings.gradle

...
include ':react-native-sensor-manager'
project(':react-native-sensor-manager').projectDir = new File(settingsDir, '../node_modules/react-native-sensor-manager/android')

android/app/build.gradle

...
dependencies {
    ...
    compile project(':react-native-sensor-manager')
}
...

MainActivity.jaja

package com.androidsen;

import com.facebook.react.ReactActivity;
import com.facebook.react.ReactPackage;
import com.facebook.react.shell.MainReactPackage;
import com.sensormanager.SensorManagerPackage; // <------ add package

import java.util.Arrays;
import java.util.List;

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 "androidSen";
    }

    @Override // <----- error: method does not override or implement a method from a supertype
    protected List<ReactPackage> getPackages() {
       return Arrays.<ReactPackage>asList(
         new MainReactPackage(), // <---- add comma
         new SensorManagerPackage() // <---------- add package
       );
     }

}

index.android.js

...
import { SensorManager } from 'NativeModules';
...
componentDidMount() {
    SensorManager.startGyroscope(100);
    DeviceEventEmitter.addListener('Gyroscope', function (data) {
      console.log(data);
    });
  }
....

@dzcpy
Copy link
Contributor

dzcpy commented Sep 9, 2016

@mileung @cristianszwarc The manual modification should be in MainApplication.java rather than in MainActivity.java

ohtangza added a commit to ohtangza/react-native-sensor-manager that referenced this issue Dec 13, 2016
kprimice added a commit that referenced this issue Dec 22, 2016
@WaqasMumtaz
Copy link

After manual setup does not create build why ?

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

8 participants