crazycodeboy / react-native-splash-screen

A splash screen for react-native, hide when application loaded ,it works on iOS and Android.
MIT License
5.62k stars 1.1k forks source link

React Native 0.60.5 plugin configuration android #418

Open XEmAX32 opened 5 years ago

XEmAX32 commented 5 years ago

Hi, while I was doing the setup of the library I found that in MainActivity.java there's no more the onCreate method. MainActivity.java

package com.testApp;

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

So I tried to do the setup in the getMainComponentName method: MainActivity.java

package com.testApp;

import com.facebook.react.ReactActivity;
import org.devio.rn.splashscreen.SplashScreen;

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() {
        SplashScreen.show(this);
        return "testApp";
    }
}

but when I try to compile it gives me this error: error: cannot find symbol variable SplashScreen

Anyone knows how to do it?

jedashford commented 5 years ago

Ours is working with this on 0.60.5:


import org.devio.rn.splashscreen.SplashScreen;

public class MainActivity extends GoogleCastActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        SoLoader.init(this, false);
        SplashScreen.show(this, R.style.SplashTheme);  // here
        super.onCreate(savedInstanceState);
    }
}```
hussainhspl commented 5 years ago

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 void onCreate(Bundle savedInstanceState) {
    SplashScreen.show(this);  // here 
    super.onCreate(savedInstanceState);
}
protected String getMainComponentName() {
    SplashScreen.show(this);  // here 
    return "splash";
}

}

i wrote this was still not working

duytq94 commented 5 years ago

My package.json: "react-native": "^0.60.5" "react-native-splash-screen": "^3.2.0"

Then I follow exactly the latest docs (don't change or add/remove extra anything) and the library works fine on both iOS and Android

Maybe you try to unlink, uninstall this library, remove cache, build... and do it again.

MITDD6338 commented 5 years ago

53 actionable tasks: 2 executed, 51 up-to-date

.../android/app/src/main/java/com/receiptsnap/MainActivity.java:9: error: cannot find symbol SoLoader.init(this, false); ^ symbol: variable SoLoader location: class MainActivity .../android/app/src/main/java/com/receiptsnap/MainActivity.java:10: error: cannot find symbol SplashScreen.show(this, R.style.SplashTheme); // here ^ symbol: variable SplashTheme location: class style 2 errors

FAILURE: Build failed with an exception.

@jedashford Still In android is not Working I get this error

tusharmutreja commented 5 years ago

I have the same Issue , how did you resolve it @hussainhspl

jedashford commented 5 years ago

53 actionable tasks: 2 executed, 51 up-to-date

.../android/app/src/main/java/com/receiptsnap/MainActivity.java:9: error: cannot find symbol SoLoader.init(this, false); ^ symbol: variable SoLoader location: class MainActivity .../android/app/src/main/java/com/receiptsnap/MainActivity.java:10: error: cannot find symbol SplashScreen.show(this, R.style.SplashTheme); // here ^ symbol: variable SplashTheme location: class style 2 errors

FAILURE: Build failed with an exception.

@jedashford Still In android is not Working I get this error

You may need to add the import statement at the top of the file:

import org.devio.rn.splashscreen.SplashScreen;
import com.facebook.soloader.SoLoader;
MITDD6338 commented 5 years ago

@jedashford Thank you now working 👍🏻😍

charmtiger commented 5 years ago

贴一个完整的供参考

MainActivity.java

package com.app;

import android.os.Bundle;

import com.facebook.react.ReactActivity;
// react navigation
import com.facebook.react.ReactActivityDelegate;
import com.facebook.react.ReactRootView;
import com.swmansion.gesturehandler.react.RNGestureHandlerEnabledRootView;

// react-native-splash-screen
import org.devio.rn.splashscreen.SplashScreen;
import com.facebook.soloader.SoLoader;

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

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

    /**
     * react navigation add
     */
    @Override
    protected ReactActivityDelegate createReactActivityDelegate() {
        return new ReactActivityDelegate(this, getMainComponentName()) {
            @Override
            protected ReactRootView createRootView() {
                return new RNGestureHandlerEnabledRootView(MainActivity.this);
            }
        };
    }

}
GunnarAK commented 5 years ago

@hussainhspl Remove SplashScreen.show(this); from protected String getMainComponentName()

AareFabrik commented 4 years ago

To fix this Error add this import to the top:

import android.os.Bundle;