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

Error when building #6

Closed RailtonMatthew closed 7 years ago

RailtonMatthew commented 7 years ago

Hi, I've ran through the install instructions but get the following errors when running:

C:\Railton\Android\PT\android\app\src\main\java\com\pt\MainActivity.java:7: error: cannot find symbol
public class MainActivity extends Activity implements DefaultHardwareBackBtnHandler {
                                  ^
  symbol: class Activity
C:\Railton\Android\PT\android\app\src\main\java\com\pt\MainActivity.java:7: error: cannot find symbol
public class MainActivity extends Activity implements DefaultHardwareBackBtnHandler {
                                                      ^
  symbol: class DefaultHardwareBackBtnHandler
C:\Railton\Android\PT\android\app\src\main\java\com\pt\MainActivity.java:9: error: cannot find symbol
    protected void onCreate(Bundle savedInstanceState) {
                            ^
  symbol:   class Bundle
  location: class MainActivity
C:\Railton\Android\PT\android\app\src\main\java\com\pt\MainActivity.java:8: error: method does not override or implement a method
from a supertype
    @Override
    ^
C:\Railton\Android\PT\android\app\src\main\java\com\pt\MainActivity.java:10: error: cannot find symbol
        super.onCreate(savedInstanceState);
        ^
  symbol:   variable super
  location: class MainActivity
C:\Railton\Android\PT\android\app\src\main\java\com\pt\MainActivity.java:11: error: cannot find symbol
        mReactRootView = new ReactRootView(this);
        ^
  symbol:   variable mReactRootView
  location: class MainActivity
C:\Railton\Android\PT\android\app\src\main\java\com\pt\MainActivity.java:11: error: cannot find symbol
        mReactRootView = new ReactRootView(this);
                             ^
  symbol:   class ReactRootView
  location: class MainActivity
C:\Railton\Android\PT\android\app\src\main\java\com\pt\MainActivity.java:13: error: cannot find symbol
        mReactInstanceManager = ReactInstanceManager.builder()
        ^
  symbol:   variable mReactInstanceManager
  location: class MainActivity
C:\Railton\Android\PT\android\app\src\main\java\com\pt\MainActivity.java:20: error: cannot find symbol
                .setInitialLifecycleState(LifecycleState.RESUMED)
                                          ^
  symbol:   variable LifecycleState
  location: class MainActivity
C:\Railton\Android\PT\android\app\src\main\java\com\pt\MainActivity.java:17: error: cannot find symbol
                .addPackage(new MainReactPackage())
                                ^
  symbol:   class MainReactPackage
  location: class MainActivity
C:\Railton\Android\PT\android\app\src\main\java\com\pt\MainActivity.java:14: error: cannot find symbol
                .setApplication(getApplication())
                                ^
  symbol:   method getApplication()
  location: class MainActivity
C:\Railton\Android\PT\android\app\src\main\java\com\pt\MainActivity.java:13: error: cannot find symbol
        mReactInstanceManager = ReactInstanceManager.builder()
                                ^
  symbol:   variable ReactInstanceManager
  location: class MainActivity
C:\Railton\Android\PT\android\app\src\main\java\com\pt\MainActivity.java:23: error: cannot find symbol
        mReactRootView.startReactApplication(mReactInstanceManager, "PT", null);
                                             ^
  symbol:   variable mReactInstanceManager
  location: class MainActivity
C:\Railton\Android\PT\android\app\src\main\java\com\pt\MainActivity.java:23: error: cannot find symbol
        mReactRootView.startReactApplication(mReactInstanceManager, "PT", null);
        ^
  symbol:   variable mReactRootView
  location: class MainActivity
C:\Railton\Android\PT\android\app\src\main\java\com\pt\MainActivity.java:25: error: cannot find symbol
        setContentView(mReactRootView);
                       ^
  symbol:   variable mReactRootView
  location: class MainActivity
C:\Railton\Android\PT\android\app\src\main\java\com\pt\MainActivity.java:31: error: method does not override or implement a method
 from a supertype
    @Override
    ^
16 errors
:app:compileDebugJavaWithJavac FAILED

The contents of MainActivity.java is as follows:

package com.pt;

import com.facebook.react.ReactActivity;
import com.mihir.react.tts.*;

//public class MainActivity extends ReactActivity {
public class MainActivity extends Activity implements DefaultHardwareBackBtnHandler {
    @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())           
                .setUseDeveloperSupport(BuildConfig.DEBUG)
                .setInitialLifecycleState(LifecycleState.RESUMED)
                .build();

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

        setContentView(mReactRootView);
    }
    /**
     * Returns the name of the main component registered from JavaScript.
     * This is used to schedule rendering of the component.
     */
    @Override
    protected String getMainComponentName() {
        return "PT";
    }
}
mihirsoni commented 7 years ago

@RailtonMatthew It seems error is in your MainActivity.java could you double check ?

RailtonMatthew commented 7 years ago

Hi, thanks for the reply. Yes, the errors are in MainActivity.java but why? I have copied your code as per the instructions.

pewh commented 7 years ago

@RailtonMatthew what RN version do you use? @mihirsoni I think the docs only support old RN version, because newer RN version use different code to register module

pewh commented 7 years ago

@RailtonMatthew I can build it on RN latest version (> 0.38). But of course the code is a little different with the docs. Just tell me RN version you use and I'll tell you later

mihirsoni commented 7 years ago

@pewh Thank you for reply, would you let me know which code is diff in document, or would you mind sending PR ?

pewh commented 7 years ago

I'm at outside right now, so will reply it later. Although I can build, but it's not working when calling function. Get same issue on https://github.com/mihirsoni/react-native-android-speech/issues/3 :/

pewh commented 7 years ago

For RN >= 0.29, read the migration guide on Android http://www.reactnative.com/react-native-v0-29-rc-released/

Then, on MainApplication.java, update getPackages to:

...
@Override
    protected List<ReactPackage> getPackages() {
      return Arrays.<ReactPackage>asList(
        new MainReactPackage(),
        new RCTTextToSpeechModule()
    );
}
...

Please note that version before 0.29, we usually register package to MainActivity.java, but on 0.29 and later, register package to MainApplication.java. So this repo docs is valid for RN < 0.29

mihirsoni commented 7 years ago

@pewh Doy still get problem after changing as per RN dos ?

mihirsoni commented 7 years ago

Closing this.