mehcode / rn-splash-screen

A JavaScript-controlled splash-screen for React Native designed to be run directly after the native splash-screen.
MIT License
350 stars 95 forks source link

Execution failed for task ':app:compileDebugJavaWithJavac'. #20

Closed esganzerla closed 7 years ago

esganzerla commented 7 years ago

I'm getting this error when I execute react-native run-android.

:app:compileDebugJavaWithJavac/home/esganzerla/helloredux/android/app/src/main/java/com/helloredux/MainActivity.java:19: error: cannot find symbol
    protected void onCreate(Bundle savedInstanceState) {
                            ^
  symbol:   class Bundle
  location: class MainActivity
/home/esganzerla/helloredux/android/app/src/main/java/com/helloredux/MainActivity.java:24: error: package ReactInstanceManager does not exist
        getReactNativeHost().getReactInstanceManager().addReactInstanceEventListener(new ReactInstanceManager.ReactInstanceEventListener() {
                                                                                                             ^
2 errors
 FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:compileDebugJavaWithJavac'.
> Compilation failed; see the compiler error output for details.

MainActivity.java

package com.helloredux;

import com.facebook.react.ReactActivity;
import com.mehcode.reactnative.splashscreen.SplashScreen;
import com.mehcode.reactnative.splashscreen.SplashScreenPackage;

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

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // Show the js-controlled splash screen
        SplashScreen.show(this);

        // After react is initialized; set our background color (override splash screen theme)
        getReactNativeHost().getReactInstanceManager().addReactInstanceEventListener(new ReactInstanceManager.ReactInstanceEventListener() {
            @Override
            public void onReactContextInitialized(ReactContext context) {

                getWindow().getDecorView().setBackgroundColor(Color.WHITE);
            }
        });

        super.onCreate(savedInstanceState);
    }
}
vonovak commented 7 years ago

you probably forgot an import, I using this successfully on RN 0.35

esganzerla commented 7 years ago

I did the react-native link rn-splash-screen and then followed the instructions as shown in the android.md...

Can you tell me if I should import anything other than import com.mehcode.reactnative.splashscreen.SplashScreen;?

I'm using RN 0.35 as well.

Thanks!

esganzerla commented 7 years ago

I've just checked the example for android MainActivity.java and there are a few more imports than the standart file I had.

I'll try to add those imports tomorrow and update the instructions, if needed.

esganzerla commented 7 years ago

Yep. It did work!

Thanks @vonovak