Android Error: Cannot resolve symbol 'PackageList'

Viewed 1625

Cannot resolve symbol 'PackageList'

I am getting this error once I open the android folder in my newly generated react-native project.

The steps to recreate it for me is to make the expo project: expo init my-app

Then eject the project: Expo eject

And then I go into the android folder and open android\app\src\main\java\Android\Screen\MainActivity.java

and I get the bug.

any help would be much appreciated.Image of error in the android studio

2 Answers

You can solve this by creating a new package (right click on your java folder and select new -> package), give it any name. Within the package create a java class called PackageList within PackageList paste the following code:

package com<NameOfYourProject>;

import android.app.Application;
import android.content.Context;
import android.content.res.Resources;

import com.facebook.react.ReactPackage;
import com.facebook.react.shell.MainPackageConfig;
import com.facebook.react.shell.MainReactPackage;
import java.util.Arrays;
import java.util.ArrayList;



public class PackageList {
  private Application application;
  private ReactNativeHost reactNativeHost;
  private MainPackageConfig mConfig;

  public PackageList(ReactNativeHost reactNativeHost) {
    this(reactNativeHost, null);
  }

  public PackageList(Application application) {
    this(application, null);
  }

  public PackageList(ReactNativeHost reactNativeHost, MainPackageConfig config) {
    this.reactNativeHost = reactNativeHost;
    mConfig = config;
  }

  public PackageList(Application application, MainPackageConfig config) {
    this.reactNativeHost = null;
    this.application = application;
    mConfig = config;
  }

  private ReactNativeHost getReactNativeHost() {
    return this.reactNativeHost;
  }

  private Resources getResources() {
    return this.getApplication().getResources();
  }

  private Application getApplication() {
    if (this.reactNativeHost == null) return this.application;
    return this.reactNativeHost.getApplication();
  }

  private Context getApplicationContext() {
    return this.getApplication().getApplicationContext();
  }

  public ArrayList<ReactPackage> getPackages() {
    return new ArrayList<>(Arrays.<ReactPackage>asList(
      new MainReactPackage(mConfig)
    ));
  }
}

You need to do a gradle sync (and build) first - the build will fail, but create PackageList for you (in e.g. android/app/build/generated/rncli/src/main/java/com/facebook/react/PackageList.java

Similarly, it creates a BuildConfig.java

Related