2 Build Errors in MainActivity.java SDK41 A short story about override and symbol

Hello guys

Context :
Bare
Expo SDK 41

At build time i got those two buddies :

/build/workingdir/build/android/app/src/main/java/com/satyamdorville/discover/MainActivity.java:34: error: method does not override or implement a method from a supertype

And :

/build/workingdir/build/android/app/src/main/java/com/satyamdorville/discover/MainActivity.java:36: error: cannot find symbol   
...
  symbol:   method getMainComponentName())

And here is my mainActivity.java :
Any tips ?

package com.satyamdorville.discover;
import android.content.res.Configuration;
import android.content.Intent;
import android.os.Bundle;
import com.reactnativenavigation.NavigationActivity;
import com.facebook.react.ReactActivityDelegate;
import com.facebook.react.ReactRootView;
import com.swmansion.gesturehandler.react.RNGestureHandlerEnabledRootView;
import expo.modules.splashscreen.singletons.SplashScreen;
import expo.modules.splashscreen.SplashScreenImageResizeMode;


public class MainActivity extends NavigationActivity {

    // Added automatically by Expo Config
    @Override
    public void onConfigurationChanged(Configuration newConfig) {
        super.onConfigurationChanged(newConfig);
        Intent intent = new Intent("onConfigurationChanged");
        intent.putExtra("newConfig", newConfig);
        sendBroadcast(intent);
    }



  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(null);
    // SplashScreen.show(...) has to be called after super.onCreate(...)
    // Below line is handled by '@expo/configure-splash-screen' command and it's discouraged to modify it manually
    SplashScreen.show(this, SplashScreenImageResizeMode.CONTAIN, ReactRootView.class, false);
  }

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

And package.json :

{
  "scripts": {
    "start": "react-native start",
    "android": "react-native run-android",
    "ios": "react-native run-ios",
    "web": "expo start --web",
    "eject": "expo eject",
    "test": "jest --watchAll"
  },
  "jest": {
    "preset": "jest-expo"
  },
  "dependencies": {
    "@expo/vector-icons": "^12.0.0",
    "@react-native-async-storage/async-storage": "^1.13.0",
    "@react-native-community/cli-platform-ios": "^5.0.1-alpha.2",
    "@react-native-community/masked-view": "^0.1.11",
    "@react-navigation/bottom-tabs": "5.11.2",
    "@react-navigation/native": "^5.9.4",
    "@react-navigation/stack": "~5.12.8",
    "@reduxjs/toolkit": "^1.5.1",
    "@sentry/react-native": "^2.4.3",
    "@stripe/stripe-react-native": "^0.1.2",
    "@types/react-native-snap-carousel": "^3.8.3",
    "email-validator": "^2.0.4",
    "expo": "^41.0.0",
    "expo-asset": "~8.3.1",
    "expo-constants": "~10.1.3",
    "expo-font": "^9.1.0",
    "expo-linking": "^2.2.3",
    "expo-location": "^12.0.4",
    "expo-permissions": "^12.0.1",
    "expo-splash-screen": "~0.10.2",
    "expo-status-bar": "^1.0.4",
    "expo-updates": "~0.5.4",
    "expo-web-browser": "~9.1.0",
    "moment-timezone": "^0.5.33",
    "parse": "^3.1.0",
    "react": "16.13.1",
    "react-dom": "16.13.1",
    "react-native": "~0.63.4",
    "react-native-animatable": "^1.3.3",
    "react-native-appearance": "~0.3.3",
    "react-native-dropdown-picker": "^5.1.15",
    "react-native-elements": "^3.3.2",
    "react-native-gesture-handler": "^1.10.3",
    "react-native-modal": "^11.10.0",
    "react-native-navigation": "^7.12.0",
    "react-native-numeric-input": "^1.9.0",
    "react-native-paper": "^4.8.1",
    "react-native-reanimated": "^2.1.0",
    "react-native-render-html": "^5.1.0",
    "react-native-safe-area-context": "^3.2.0",
    "react-native-screens": "^3.3.0",
    "react-native-snap-carousel": "^3.9.1",
    "react-native-stripe-checkout-webview": "0.0.13",
    "react-native-ui-lib": "^5.22.0",
    "react-native-unimodules": "~0.13.3",
    "react-native-vector-icons": "^8.1.0",
    "react-native-web": "~0.13.12",
    "react-native-webview": "^11.2.3",
    "react-navigation": "^4.4.4",
    "react-redux": "^7.2.3",
    "react-ridge-state": "^4.2.1",
    "redux": "^4.0.5",
    "sentry-expo": "^3.1.0"
  },
  "devDependencies": {
    "@babel/core": "^7.9.6",
    "@types/lodash": "^4.14.168",
    "@types/react": "~16.9.35",
    "@types/react-native": "~0.63.2",
    "@types/react-redux": "^7.1.16",
    "jest-expo": "^41.0.0",
    "redux-tools": "^3.2.0",
    "typescript": "~4.0.0"
  },
  "private": true,
  "name": "discover",
  "version": "1.0.0"
}

Hey @satyamdorville, can you share the relevant info and version numbers for your Android env? Also, did this happen after a specific change in your environment/code?

Cheers,
Adam

Thanks for support @adamjnav
The only change is that i have just ejected from Managed Workflow to Bare so its my first “run” to production since eject. I have ejected because it seems that Stripe React Native works only on bare workflow. For what its worth… everything did well for the ios version…
Since my first post, i have changed my code and the build is OK and i was able to release on Play Store but now i got another error in production now in the store after downloading the app ! Error from Google Play Console and i think its related because i have change a lot of the versions of the env as you mention so :

The env :
Android Gradle Plugin Version 4.2.1
Gradle Version 6.8.2
I ran gradlew clean

build.gradle file :

buildscript {
    ext {
        RNNKotlinVersion = "1.4.31"
        buildToolsVersion = '30.0.2'
        minSdkVersion = 21
        compileSdkVersion = 30
        targetSdkVersion = 30
    }
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.4.31"
        classpath('com.android.tools.build:gradle:4.2.1')

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        mavenLocal()
        maven {
            // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
            url("$rootDir/../node_modules/react-native/android")
        }
        maven {
            // Android JSC is installed from npm
            url("$rootDir/../node_modules/jsc-android/dist")
        }

        google()
        jcenter()
        maven { url 'https://www.jitpack.io' }
    }
}

The error now in the Google Play Console :

java.lang.RuntimeException: 
  at android.app.ActivityThread.handleBindApplication (ActivityThread.java:6608)
  at android.app.ActivityThread.access$1500 (ActivityThread.java:235)
  at android.app.ActivityThread$H.handleMessage (ActivityThread.java:1916)
  at android.os.Handler.dispatchMessage (Handler.java:107)
  at android.os.Looper.loop (Looper.java:225)
  at android.app.ActivityThread.main (ActivityThread.java:7563)
  at java.lang.reflect.Method.invoke (Native Method)
  at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:539)
  at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:994)
Caused by: java.lang.IllegalStateException: 
  at expo.modules.updates.UpdatesController.getInstance (UpdatesController.java:80)
  at com.satyamdorville.discover.MainApplication$1.getJSBundleFile (MainApplication.java:68)
  at com.reactnativenavigation.react.NavigationReactNativeHost.createReactInstanceManager (NavigationReactNativeHost.java:53)
  at com.facebook.react.ReactNativeHost.getReactInstanceManager (ReactNativeHost.java:39)
  at com.reactnativenavigation.react.ReactGateway.<init> (ReactGateway.java:20)
  at com.reactnativenavigation.NavigationApplication.createReactGateway (NavigationApplication.java:40)
  at com.reactnativenavigation.NavigationApplication.onCreate (NavigationApplication.java:27)
  at com.satyamdorville.discover.MainApplication.onCreate (MainApplication.java:89)
  at android.app.Instrumentation.callApplicationOnCreate (Instrumentation.java:1189)
  at android.app.ActivityThread.handleBindApplication (ActivityThread.java:6603)

mainActivity.java (I have deleted the overrides and added the getMainComponentName function implementation.

package com.satyamdorville.discover;
import android.content.res.Configuration;
import android.content.Intent;
import android.os.Bundle;
import com.reactnativenavigation.NavigationActivity;
import com.facebook.react.ReactActivityDelegate;
import com.facebook.react.ReactRootView;
import com.swmansion.gesturehandler.react.RNGestureHandlerEnabledRootView;
import expo.modules.splashscreen.singletons.SplashScreen;
import expo.modules.splashscreen.SplashScreenImageResizeMode;


public class MainActivity extends NavigationActivity {

    // Added automatically by Expo Config
    @Override
    public void onConfigurationChanged(Configuration newConfig) {
        super.onConfigurationChanged(newConfig);
        Intent intent = new Intent("onConfigurationChanged");
        intent.putExtra("newConfig", newConfig);
        sendBroadcast(intent);
    }

    protected String getMainComponentName() {
        return "App"; // here
    }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(null);
    // SplashScreen.show(...) has to be called after super.onCreate(...)
    // Below line is handled by '@expo/configure-splash-screen' command and it's discouraged to modify it manually
    SplashScreen.show(this, SplashScreenImageResizeMode.CONTAIN, ReactRootView.class, false);
  }


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

mainApplication.java

package com.satyamdorville.discover;

import android.app.Application;
import android.content.Context;
import android.net.Uri;

import com.facebook.react.PackageList;
import com.reactnativenavigation.NavigationApplication;
import com.facebook.react.ReactInstanceManager;
import com.facebook.react.ReactNativeHost;
import com.reactnativenavigation.react.NavigationReactNativeHost;
import com.facebook.react.ReactPackage;
import com.facebook.react.shell.MainReactPackage;
import com.facebook.soloader.SoLoader;
import com.satyamdorville.discover.generated.BasePackageList;

import org.unimodules.adapters.react.ReactAdapterPackage;
import org.unimodules.adapters.react.ModuleRegistryAdapter;
import org.unimodules.adapters.react.ReactModuleRegistryProvider;
import org.unimodules.core.interfaces.Package;
import org.unimodules.core.interfaces.SingletonModule;
import expo.modules.constants.ConstantsPackage;
import expo.modules.permissions.PermissionsPackage;
import expo.modules.filesystem.FileSystemPackage;
import expo.modules.updates.UpdatesController;

import com.facebook.react.bridge.JSIModulePackage;
import com.swmansion.reanimated.ReanimatedJSIModulePackage;

import java.lang.reflect.InvocationTargetException;
import java.util.Arrays;
import java.util.List;
import javax.annotation.Nullable;

public class MainApplication extends NavigationApplication {
  private final ReactModuleRegistryProvider mModuleRegistryProvider = new ReactModuleRegistryProvider(
    new BasePackageList().getPackageList()
  );

  private final ReactNativeHost mReactNativeHost = new NavigationReactNativeHost(this) {
    @Override
    public boolean getUseDeveloperSupport() {
      return BuildConfig.DEBUG;
    }

    @Override
    protected List<ReactPackage> getPackages() {
      List<ReactPackage> packages = new PackageList(this).getPackages();
      packages.add(new ModuleRegistryAdapter(mModuleRegistryProvider));
      return packages;
    }

    @Override
    protected String getJSMainModuleName() {
      return "index";
    }

    @Override
    protected JSIModulePackage getJSIModulePackage() {
      return new ReanimatedJSIModulePackage();
    }

    @Override
    protected @Nullable String getJSBundleFile() {
      if (BuildConfig.DEBUG) {
        return super.getJSBundleFile();
      } else {
        return UpdatesController.getInstance().getLaunchAssetFile();
      }
    }

    @Override
    protected @Nullable String getBundleAssetName() {
      if (BuildConfig.DEBUG) {
        return super.getBundleAssetName();
      } else {
        return UpdatesController.getInstance().getBundleAssetName();
      }
    }
  };

  @Override
  public ReactNativeHost getReactNativeHost() {
    return mReactNativeHost;
  }

  @Override
  public void onCreate() {
    super.onCreate();
    

    if (!BuildConfig.DEBUG) {
      UpdatesController.initialize(this);
    }

    initializeFlipper(this, getReactNativeHost().getReactInstanceManager());
  }

  /**
   * Loads Flipper in React Native templates. Call this in the onCreate method with something like
   * initializeFlipper(this, getReactNativeHost().getReactInstanceManager());
   *
   * @param context
   * @param reactInstanceManager
   */
  private static void initializeFlipper(
      Context context, ReactInstanceManager reactInstanceManager) {
    if (BuildConfig.DEBUG) {
      try {
        /*
         We use reflection here to pick up the class that initializes Flipper,
        since Flipper library is not available in release mode
        */
        Class<?> aClass = Class.forName("com.satyamdorville.discover.ReactNativeFlipper");
        aClass
            .getMethod("initializeFlipper", Context.class, ReactInstanceManager.class)
            .invoke(null, context, reactInstanceManager);
      } catch (ClassNotFoundException e) {
        e.printStackTrace();
      } catch (NoSuchMethodException e) {
        e.printStackTrace();
      } catch (IllegalAccessException e) {
        e.printStackTrace();
      } catch (InvocationTargetException e) {
        e.printStackTrace();
      }
    }
  }
}

```