Reputation: 73
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
Upvotes: 7
Views: 20909
Reputation: 632
If it's not done, you should verify that you correctly have this apply at the end of your android/app/build.gradle
.
apply from: file("../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesAppBuildGradle(project)
If you open ../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle
You can see the beginning of the file speaking about PackageList:
import groovy.json.JsonSlurper
import org.gradle.initialization.DefaultSettings
import org.apache.tools.ant.taskdefs.condition.Os
**def generatedFileName = "PackageList.java"**
def generatedFilePackage = "com.facebook.react"
def generatedFileContentsTemplate = """
package $generatedFilePackage;
import android.app.Application;
import android.content.Context;
import android.content.res.Resources;
It seems that this apply in the gradle was not mandatory before.
If it's still not working, this link help me to verify more the updates to do in my android/app/build.gradle
https://github.com/facebook/react-native/issues/25787#issuecomment-514285556
And more precisely : https://react-native-community.github.io/upgrade-helper/?from=0.68.5&to=0.73.4#RnDiffApp-android-app-build.gradle
And in my case I was missing some stuffs : Removing
project.ext.react = [
enableHermes: true,
]
and also renaming enableHermes to hermesEnabled in the following code :
if (hermesEnabled.toBoolean()) {
implementation("com.facebook.react:hermes-android")
} else {
implementation jscFlavor
}
That solved this error while I was doing migration from 0.68 to 0.73.
Source: https://github.com/MohGovIL/hamagen-react-native/issues/178
Upvotes: 1
Reputation: 589
I was getting this on version 0.3.1 of @react-native-masked-view/masked-view on react-native v0.67.5. Downgrading to v0.2.9 works as a temporary solution.
Upvotes: 0
Reputation: 21
I am Totally agree with above answer.
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.
But in the above code, on the following line
return this.reactNativeHost.getApplication();
I get some error, like
Blockquote error: getApplication() has protected access in ReactNativeHost return this.reactNativeHost.getApplication();
So, to resolve this, this is my modified PackageList Class.
package packagelist;
import android.app.Application;
import android.content.Context;
import android.content.res.Resources;
import com.facebook.react.ReactNativeHost;
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(Application application) {
this(application, null);
}
public PackageList(Application application, MainPackageConfig config) {
this.application = application;
this.reactNativeHost = null;
this.mConfig = config;
}
private Resources getResources() {
return this.application.getResources();
}
private Context getApplicationContext() {
return this.application.getApplicationContext();
}
public ArrayList<ReactPackage> getPackages() {
return new ArrayList<>(Arrays.asList(
new MainReactPackage(mConfig)
));
}
}
Hope, this will help someone. :)
Upvotes: 1
Reputation: 975
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
Upvotes: 8
Reputation: 82
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)
));
}
}
Upvotes: 2