Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to 0.60.4 breaks Android (error cannot find symbol) #25787

Closed
karltaylor opened this issue Jul 23, 2019 · 22 comments
Closed

Update to 0.60.4 breaks Android (error cannot find symbol) #25787

karltaylor opened this issue Jul 23, 2019 · 22 comments
Labels
Bug Platform: Android Android applications. Resolution: Locked This issue was locked by the bot.

Comments

@karltaylor
Copy link

karltaylor commented Jul 23, 2019

React Native version:

System:
    OS: macOS 10.14.5
    CPU: (8) x64 Intel(R) Core(TM) i7-3615QM CPU @ 2.30GHz
    Memory: 288.14 MB / 16.00 GB
    Shell: 5.3 - /bin/zsh
  Binaries:
    Node: 12.4.0 - /usr/local/bin/node
    Yarn: 1.17.0 - /usr/local/bin/yarn
    npm: 6.9.0 - /usr/local/bin/npm
    Watchman: 4.9.0 - /usr/local/bin/watchman
  SDKs:
    iOS SDK:
      Platforms: iOS 12.4, macOS 10.14, tvOS 12.4, watchOS 5.3
  IDEs:
    Android Studio: 3.4 AI-183.6156.11.34.5692245
    Xcode: 10.3/10G8 - /usr/bin/xcodebuild
  npmPackages:
    react: 16.8.6 => 16.8.6
    react-native: 0.60.4 => 0.60.4

Steps To Reproduce

  1. Update to 0.60.4
  2. npx react-native run-android

Describe what you expected to happen:

React Native to build

Description

The app compiles and works fine on iOS and xcode. However, when I try and run the new android code I face the following error:

/redacted/MainApplication.java:6: error: cannot find symbol
import com.facebook.react.PackageList;
                         ^
  symbol:   class PackageList
  location: package com.facebook.react
/redacted/MainApplication.java:28: error: cannot find symbol
      List<ReactPackage> packages = new PackageList(this).getPackages();
                                        ^
  symbol: class PackageList
2 errors

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:compileDebugJavaWithJavac'.
> Compilation failed; see the compiler error output for details.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 9s

error Failed to install the app. Make sure you have the Android development environment set up: https://facebook.github.io/react-native/docs/getting-started.html#android-development-environment. Run CLI with --verbose flag for more details.

This is my MainApplication.java

package com.my.app;

import android.app.Application;
import android.util.Log;

import com.facebook.react.PackageList;
import com.facebook.hermes.reactexecutor.HermesExecutorFactory;
import com.facebook.react.bridge.JavaScriptExecutorFactory;
import com.facebook.react.ReactApplication;
import com.facebook.react.ReactNativeHost;
import com.facebook.react.ReactPackage;

import com.facebook.soloader.SoLoader;

import java.util.List;

public class MainApplication extends Application implements ReactApplication {

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

    @Override
    protected List<ReactPackage> getPackages() {
      @SuppressWarnings("UnnecessaryLocalVariable")
      List<ReactPackage> packages = new PackageList(this).getPackages();
      // Packages that cannot be autolinked yet can be added manually here, for example:
      // packages.add(new MyReactNativePackage());
      return packages;
    }

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

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

  @Override
  public void onCreate() {
    super.onCreate();
    SoLoader.init(this, /* native exopackage */ false);
  }
}
@karltaylor karltaylor added the Bug label Jul 23, 2019
@react-native-bot react-native-bot added the Platform: Android Android applications. label Jul 23, 2019
@karltaylor karltaylor changed the title Update to 0.64.0 breaks Android (error cannot find symbol) Update to 0.60.4 breaks Android (error cannot find symbol) Jul 23, 2019
@karltaylor
Copy link
Author

karltaylor commented Jul 23, 2019

Turns out I was missing the new stuff inside android/app/build.gradle when I used https://react-native-community.github.io/upgrade-helper/?from=0.59.8&to=0.60.4

The android/app/build.gradle file was closed and I missed it 🤕

@WoodyWoodsta
Copy link

Lol. I had exactly the same issue. Humans.

@friederbluemle
Copy link
Contributor

friederbluemle commented Oct 15, 2019

With React Native auto-linking, PackageList is now a generated file. Is it is created by including native_modules.gradle into your Gradle build (the last line in android/app/build.gradle).

@Capossito
Copy link

im having the same issue, however, after adding the native_modules.gradle in build.gradle. i get ERROR: Cannot invoke method getErrorStream() on null object.

react: 16.10.2
react-native: 0.61.2
@react-native-community/cli: 3.0.0-alpha.7

i have followed all the upgrade-helpers changes, im coming from react-native: 0.59.8. any thoughts on how to fix it?

@friederbluemle
Copy link
Contributor

@Capossito - Do you happen to have a link to the project?
react should be 16.9.0 btw (just a side note, not the issue here).

@runryan
Copy link

runryan commented Nov 22, 2019

Adding apply from: file("../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesAppBuildGradle(project) at the end of app/build.gradle works for me. You can also try it.

@o-pooja-o
Copy link

Adding apply from: file("../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesAppBuildGradle(project) at the end of app/build.gradle works for me. You can also try it.

Shows error that file does not exist!

@charinduedirisuriya
Copy link

@o-pooja-o same problem here but ti actually does exist

@o-pooja-o
Copy link

@o-pooja-o same problem here but ti actually does exist
Yeah maybe but my error was because of lower react native version.

@zhangleiwant
Copy link

add apply from: file("../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesAppBuildGradle(project)
to to your app/build.gradle

@verybluebot
Copy link

verybluebot commented May 7, 2020

Followed Upgrade helper 0.59.9 to 0.62.2 and made sure to make
@runryan and @karltaylor changes too.

still no joy, PackageList is still missing - Cannot resolve symbol 'PackageList' and getting this error crushing the build:

/Users/myuser/projects/myproject/node_modules/react-native/node_modules/@react-native-community/cli/build/index.js:176  const cmd = _commander().default.command(command.name).action(async function handleAction(...args) { 

^^^^^SyntaxError: missing ) after argument list    
at createScript (vm.js:56:10)    
at Object.runInThisContext (vm.js:97:10)   
 at Module._compile (module.js:542:28)    
at Object.Module._extensions..js (module.js:579:10)    
at Module.load (module.js:487:32)    
at tryModuleLoad (module.js:446:12)    
at Function.Module._load (module.js:438:3)    
at Module.require (module.js:497:17)    
at require (internal/module.js:20:19)    
at Object.<anonymous> (/Users/myuser/projects/myproject/node_modules/react-native/cli.js:13:11)

Any ideas?

@LionelHoudelier
Copy link

LionelHoudelier commented May 14, 2020

Hi verybluebot and all,
add this in settings.gradle : apply from: file("../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesSettingsGradle(settings)

and this in app/build.gradle at the end :
apply from: file("../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesAppBuildGradle(project)

and take a look at https://react-native-community.github.io/upgrade-helper/?from=0.59.0&to=0.61.5 for other changes in files. It worked for me!

@Monte9
Copy link
Contributor

Monte9 commented Aug 1, 2020

@friederbluemle is spot on 💯

With React Native auto-linking, PackageList is now a generated file. Is it is created by including native_modules.gradle into your Gradle build (the last line in android/app/build.gradle).

Since PackageList is now a generated file, you need to run yarn react-native run-android to build the android app. That's what auto links the package and generates that file.

Regardless of if that command builds/fails - if you go back to Android Studio and build the file - PackageList will no longer throw that error!

@verybluebot
Copy link

@LionelHoudelier thanks managed to get it working, but still having build fail on Android studio which makes
all native development very painful as the IDE not highlighting anything.

Build from RN works but this feels such a horrible hack.

@Akhil-EM
Copy link

Hi verybluebot and all,
add this in settings.gradle : apply from: file("../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesSettingsGradle(settings)

and this in app/build.gradle at the end :
apply from: file("../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesAppBuildGradle(project)

and take a look at https://react-native-community.github.io/upgrade-helper/?from=0.59.0&to=0.61.5 for other changes in files. It worked for me!

this really help me thank you :)

@SeanDunford
Copy link

SeanDunford commented Oct 13, 2020

Just want to state the obvious in case anyone else who was stuck like me comes across this post.

Ensure import com.facebook.react.PackageList; is included in your MainApplication.java file

I inherited a project that was manually linking all it's packages and the above line wasn't added during a previous upgrade.

@lukepighetti
Copy link

lukepighetti commented Dec 8, 2020

On react-native-cli version 4.13.1, I generate a project, then open the android folder in Android Studio 4.1.1 and I get the issue above. This is happening straight out of a generated project.

Screen Shot 2020-12-08 at 1 48 55 PM

@lukepighetti
Copy link

lukepighetti commented Dec 8, 2020

Edit: you have to run yarn react-native run-android for it to generate this file and make it available, as noted above.

@gsrathoreniks
Copy link

Using
react-native : 0.61.5-jitsi.2

in Jitsi SDK along with Native Modules.

but Getting Error
Cannot resolve symbol 'PackageList'

@knightcube
Copy link

Getting the same error. Cannot resolve symbol 'PackageList'.
I am using react-native: 0.63.4

@MayoudP
Copy link

MayoudP commented May 3, 2021

@knightcube did you solved it ? On RN 0.63, having this issue too...

@hello-jun
Copy link

@knightcube did you solved it ? On RN 0.63, having this issue too...

Just click "Make Project" in Android Studio,and it will be generated automatically.

@facebook facebook locked as resolved and limited conversation to collaborators Oct 6, 2021
@react-native-bot react-native-bot added the Resolution: Locked This issue was locked by the bot. label Oct 6, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Bug Platform: Android Android applications. Resolution: Locked This issue was locked by the bot.
Projects
None yet
Development

No branches or pull requests