React-native-splash-screen: undefined is not an object (evaluating '_reactNativeSplashScreen2.default.hide')

Created on 26 Sep 2017  路  18Comments  路  Source: crazycodeboy/react-native-splash-screen

I have already configure my code just like the instruction to use the splash screen but when I compile it using my Redmi Note 3 it returns error like this:

image

in line of code:

class Main extends Component {
  constructor(props) {
    super(props);
    this._onPressLogo = this._onPressLogo.bind(this);

  componentDidMount() {      
    SplashScreen.hide();  //ERROR here
  }
  _onPressLogo() {
    //this
    Actions.about();
  }
  render() {
    return (
      <Image style={{ flex: 1, width: null }} source={bg}>
        {/* <AndroidBackButton /> */}
        <StatusBar backgroundColor="#114D44" />
        <View style={{ flex: 1, padding: 15 }}>
          <View style={{ flex: 2, justifyContent: 'center', alignItems: 'center' }}>
            {/* <TouchableHighlight onPress={this._onPressLogo} > */}
              <Image source={logo} />
            {/* //</TouchableHighlight>*/}
          </View>
        </View>
      </Image>
    );
  }
}

react-native: "0.48.4"
react-native-splash-screen: "^3.0.1"
node: v6.11.2
npm: 5.3.0

please tell me how to handle this case.

Most helpful comment

Make sure you add below lines in MainApplication.java

protected List<ReactPackage> getPackages() {
      return Arrays.<ReactPackage>asList(
            new MainReactPackage(),
            new SvgPackage(),
            new VectorIconsPackage(),
            new SplashScreenReactPackage() //here

      );
    }

This will fix the issue!!!

Also make sure you have imported the below package
import org.devio.rn.splashscreen.SplashScreenReactPackage;

All 18 comments

I also had the exact same problem

+1

Do check the android/app/src/main/java/com/appname/MainActivity.java

package com.testapp;

import android.os.Bundle; // I missed out this line
import com.facebook.react.ReactActivity;
import org.devio.rn.splashscreen.SplashScreen; // According to the instruction, you would just need to use one of the imports, depending on the react-native-splash-screen version.

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

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        SplashScreen.show(this);
        super.onCreate(savedInstanceState);
    }
}

I screwed up the previous project so badly so I recreated a new project, it worked after I sort out the MainActivity.java.

any solution regarding this problem, I also have the same problem.

please take look at this issue #30 you possibly get help from there.

  • Insert #import "SplashScreen.h" to ./ios/<AppName>/AppDelegate.m if not exists
  • Rebuild

Probably, it will be fix.

This did not work on Apple TV 4K.

@Balamir Hello sir,
I have follower the exact same thing mentioned in this Splash Screen Tutorial but I am getting the exact same error mentioned above in my ios devices.
I also cleaned the cache and rebuild the project several times but still it didn't work

You are missing some java code either in MainActivity.java or MainApplication.java.

Make sure you have

new SplashScreenReactPackage()

inside the MainApplication.java otherwise SplashScreen will not be exposed to react code.

I had the same issue adding new SplashScreenReactPackage() fixed it.

Hello @creativeaura I have already fixed the error which I was getting in my application reguarding the splash screen by following some extra steps

1.  I mentioned the LaunchScreen.xib file in Lunch Screen File 
2. Also I added link manually in build setting > Header Search Path > $(SRCROOT)/../node_modules/react-native-splash-screen/ios
3. I dragged react-native-splash-screen/ios/SplashScreen.xcodeproj/ to my project library manually .
4. Dragged libSplashScreen.a from SplashScreen.xcodeproj to Project General Tab > Linked Frameworks and Libraries and dropped it some where with the library 
5. Command + Shift + K and Command +R 

@khadkaPratik The fix I mentioned was for Android.

please help i have the same issue and all my files are correct

If someone give error like this in iOS can fix by the way
When you link manually in build setting > Header Search Path > $(SRCROOT)/../node_modules/react-native-splash-screen/ios set recursive
Hope help you

Make sure you add below lines in MainApplication.java

protected List<ReactPackage> getPackages() {
      return Arrays.<ReactPackage>asList(
            new MainReactPackage(),
            new SvgPackage(),
            new VectorIconsPackage(),
            new SplashScreenReactPackage() //here

      );
    }

This will fix the issue!!!

Also make sure you have imported the below package
import org.devio.rn.splashscreen.SplashScreenReactPackage;

for iOS developer, try to remove libSplashScreen.a from [Project Name -> build Phases -> Link Binary With Libraries ]. Hope it helps

Same issue with iOS 13.1, RN 0.61.5 and this package using 3.2.0. @anhdevit and @someoneNameGrey answers sadly didn't help 馃檨
Is this package still maintains ?

for (ios) Remember to cd ios && pod install

I know this issue is closed, but if someone came here hopelessly I found a simple solution:

In the file ios/<yourAppName>/AppDelegate.m add:

#import "RNSplashScreen.h"
Was this page helpful?
0 / 5 - 0 ratings