mihirsoni / react-native-android-speech

This simple React Native module for Android Text To Speech functionality.
https://www.npmjs.com/package/react-native-android-speech
48 stars 14 forks source link

problem on building react-native project #1

Closed sumanbogati closed 8 years ago

sumanbogati commented 8 years ago

As you suggested I have done following in MainActivity.java

package com.mysound;
import android.os.Bundle;
import com.facebook.react.ReactActivity;
import com.facebook.react.LifecycleState;
import com.facebook.react.ReactInstanceManager;
import com.facebook.react.ReactRootView;
import com.facebook.react.modules.core.DefaultHardwareBackBtnHandler;
import com.facebook.react.shell.MainReactPackage;

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

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mReactRootView = new ReactRootView(this);

        mReactInstanceManager = ReactInstanceManager.builder()
                .setApplication(getApplication())
                .setBundleAssetName("index.android.bundle")
                .setJSMainModuleName("index.android")
                .addPackage(new MainReactPackage())
                .addPackage(new RCTTextToSpeechModule())           // Add any extra modules here
                .setUseDeveloperSupport(BuildConfig.DEBUG)
                .setInitialLifecycleState(LifecycleState.RESUMED)
                .build();

        mReactRootView.startReactApplication(mReactInstanceManager, "YourProject", null);

        setContentView(mReactRootView);
    }  
}

After run the react-native run-android command, I got following error

error3

How to fix this problem?

mihirsoni commented 8 years ago

@sumanbogati It seems you have copied the entire MainActicty from the documentation. You just need to add .addPackage(new RCTTextToSpeechModule()) in your Activity.

Also make sure you have added gradle dependency

sumanbogati commented 8 years ago

@mihirsoni how do I get this RCTTextToSpeechModule module in my main activity Mainactivity.java file as I have done import com.facebook.react.RCTTextToSpeechModule; in file does not work, my activity Mainactivity.java file has something like `

 package com.mysound;
import com.facebook.react.ReactActivity;

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

}`

How do I add this .addPackage(new RCTTextToSpeechModule()) in my activity file.

It will be great if there is any working example you can provide to me.

My react native version react-native-cli: 0.2. react-native: 0.29.1

mihirsoni commented 8 years ago

@sumanbogati , Try to follow the steps mentioned in READ.ME in your project. You don't need to copy paste exactly what is there inside the documentation. Just follow and change accoridng to your project.

First you need to install the dependency from the gradle setup

mihirsoni commented 8 years ago

Closing this, please let me know if face problem again.