I have a react native running perfectly on iOS but does not compile in Android studio due to import issues in MainApplication and MainActivity. I followed the React Native FBSDK guidelines.
In MainApplication I get "Cannot resolve symbol" on import statements:
import com.facebook.react.ReactApplication; import com.facebook.react.ReactNativeHost;
And the following errors:
Error:(7, 8) error: MainActivity is not abstract and does not override abstract method getPackages() in ReactActivity Error:Execution failed for task ':app:compileDebugJavaWithJavac'.
Compilation failed; see the compiler error output for details.
My MainApplication looks like:
package com.ExampleApp;
import android.app.Application;
import com.facebook.react.ReactApplication;
import com.tradle.react.UdpSocketsModule;
import com.peel.react.TcpSocketsModule;
import com.peel.react.rnos.RNOSModule;
import com.masteratul.exceptionhandler.ReactNativeExceptionHandlerPackage;
import com.oblador.vectoricons.VectorIconsPackage;
import com.facebook.react.ReactNativeHost;
import com.facebook.react.ReactPackage;
import com.facebook.react.shell.MainReactPackage;
import com.facebook.soloader.SoLoader;
import com.facebook.CallbackManager;
import com.facebook.FacebookSdk;
import com.facebook.reactnative.androidsdk.FBSDKPackage;
import com.facebook.appevents.AppEventsLogger;
import java.util.Arrays;
import java.util.List;
public class MainApplication extends Application implements ReactApplication {
private static CallbackManager mCallbackManager = CallbackManager.Factory.create();
protected static CallbackManager getCallbackManager() {
return mCallbackManager;
}
@Override
public void onCreate() {
super.onCreate();
// Use AppEventsLogger to log custom events.
AppEventsLogger.activateApp(this);
}
private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) {
@Override
public boolean getUseDeveloperSupport() {
return BuildConfig.DEBUG;
}
@Override
protected List<ReactPackage> getPackages() {
return Arrays.<ReactPackage>asList(
new MainReactPackage(),
new UdpSocketsModule(),
new TcpSocketsModule(),
new RNOSModule(),
new ReactNativeExceptionHandlerPackage(),
new VectorIconsPackage(),
new FBSDKPackage(mCallbackManager)
);
}
};
@Override
public ReactNativeHost getReactNativeHost() {
return mReactNativeHost;
}
}
And my MainActivity:
import android.content.Intent;
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
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
MainApplication.getCallbackManager().onActivityResult(requestCode, resultCode, data);
}
@Override
protected String getMainComponentName() {
return "ExampleApp";
}
}
It happened to me too after detach my react-native project from Expo.
In MainApplication I had "error Cannot resolve symbol" for these imports:
import com.facebook.react.ReactApplication;
import com.facebook.react.ReactNativeHost;
in my package.json file I used:
"react-native": "https://github.com/expo/react-native/archive/sdk-29.0.0.tar.gz",
the problem was that the android can't find the directory for node_modules like that.
in order to fix the issue I had to:
change it to :
"react-native": "^0.57.8",
delete node_modules file
That's what solved the problem for me. Hope I helped.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With