Appcenter-sdk-react-native: error : cannot find symbol while building react native app

Created on 11 Jul 2019  路  46Comments  路  Source: microsoft/appcenter-sdk-react-native

Description

I tried to integrate app center into one of sample react native application of mine. I tried from A to Z, to resolve the issue but I cannot be able to do that.

here are the errors which I am getting:

Task :app:compileDebugJavaWithJavac FAILED

Deprecated Gradle features were used in this build, making it incompatible with Gradle 6.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/5.1.1/userguide/command_line_interface.html#sec:command_line_warnings
43 actionable tasks: 2 executed, 41 up-to-date
C:\projects\Own\reactNative\appCenter_Analytics\POCAnalytics\android\app\build\generated\rncli\src\main\java\com\facebook\react\PackageList.java:55: error: cannot find symbol
new AppCenterReactNativePackage(MainApplication.this),
^
symbol: class MainApplication
location: class PackageList
C:\projects\Own\reactNative\appCenter_Analytics\POCAnalytics\android\app\build\generated\rncli\src\main\java\com\facebook\react\PackageList.java:56: error: cannot find symbol
new AppCenterReactNativeAnalyticsPackage(MainApplication.this, getResources().getString(R.string.appCenterAnalytics_whenToEnableAnalytics)),
^
symbol: class MainApplication
location: class PackageList
C:\projects\Own\reactNative\appCenter_Analytics\POCAnalytics\android\app\build\generated\rncli\src\main\java\com\facebook\react\PackageList.java:56: error: cannot find symbol
new AppCenterReactNativeAnalyticsPackage(MainApplication.this, getResources().getString(R.string.appCenterAnalytics_whenToEnableAnalytics)),
^
symbol: variable appCenterAnalytics_whenToEnableAnalytics
location: class string
C:\projects\Own\reactNative\appCenter_Analytics\POCAnalytics\android\app\build\generated\rncli\src\main\java\com\facebook\react\PackageList.java:57: error: cannot find symbol
new AppCenterReactNativeCrashesPackage(MainApplication.this, getResources().getString(R.string.appCenterCrashes_whenToSendCrashes))
^
symbol: class MainApplication
location: class PackageList
C:\projects\Own\reactNative\appCenter_Analytics\POCAnalytics\android\app\build\generated\rncli\src\main\java\com\facebook\react\PackageList.java:57: error: cannot find symbol
new AppCenterReactNativeCrashesPackage(MainApplication.this, getResources().getString(R.string.appCenterCrashes_whenToSendCrashes))
^
symbol: variable appCenterCrashes_whenToSendCrashes
location: class string
5 errors

Repro Steps

to reproduce issue

  1. go to https://github.com/Donjay2101/reactnative and download code.
  2. run "npm install".
  3. run "react-native run-android"

Details

  1. Which version of the App Center SDK are you using?
    2.1.0
  2. Which OS version did you experience the issue on?
    Android 9.0
  3. What device version did you see this error on? Were you using an emulator or a physical device?
    -Honor 10
  4. What third party libraries are you using?

    • example

  5. Run the following command and paste the output below: react-native info

System:
OS: Windows 10
CPU: (4) x64 Intel(R) Core(TM) i5-6300U CPU @ 2.40GHz
Memory: 900.19 MB / 7.88 GB
Binaries:
Node: 10.16.0 - C:\Program Files\nodejs\node.EXE
npm: 6.9.0 - C:\Users\deepak.singhmehta\AppData\Roaming\npm\npm.CMD
IDEs:
Android Studio: Version 3.4.0.0 AI-183.6156.11.34.5522156

  1. Please enable verbose logging for your app using [MSAppCenter setLogLevel: MSLogLevelVerbose]; before your call to [AppCenterReactNative register]; (or any other SDK registration). For Android, use AppCenter.setLogLevel(android.util.Log.VERBOSE); before your SoLoader.init call. Include the logs here:
bug

Most helpful comment

Is there any temp solution for this?

In react-native > 0.60

Create react-native.config.js in your project's root directory.

module.exports = {
  dependencies: {
    'appcenter': {
      platforms: {
        android: null, // disable Android platform, other platforms will still autolink if provided
      },
    },
    'appcenter-analytics': {
      platforms: {
        android: null, // disable Android platform, other platforms will still autolink if provided
      },
    },
    'appcenter-crashes': {
      platforms: {
        android: null, // disable Android platform, other platforms will still autolink if provided
      },
    },
  },
};

and link them manually in MainApplication.java like this:

import com.microsoft.appcenter.reactnative.crashes.AppCenterReactNativeCrashesPackage;
import com.microsoft.appcenter.reactnative.analytics.AppCenterReactNativeAnalyticsPackage;
import com.microsoft.appcenter.reactnative.appcenter.AppCenterReactNativePackage;

//****

@Override
    protected List<ReactPackage> getPackages() {
      @SuppressWarnings("UnnecessaryLocalVariable")
      List<ReactPackage> packages = new PackageList(this).getPackages();
      packages.add(new AppCenterReactNativeCrashesPackage(MainApplication.this, getResources().getString(R.string.appCenterCrashes_whenToSendCrashes)));
      packages.add(new AppCenterReactNativeAnalyticsPackage(MainApplication.this, getResources().getString(R.string.appCenterAnalytics_whenToEnableAnalytics)));
      packages.add(new AppCenterReactNativePackage(MainApplication.this));
      return packages;
    }

All 46 comments

Is your react-native version >= 0.60? I am also getting the same error.
It was working with react-native 0.59 though

Yes my version is 0.60. I am trying with this version only, did not try with any other version.
In most of issues similar to this they are saying 0.57 version.

Hey, @Donjay2101! It looks more like a problem with the toolchain.
Can you please verify you are able to run clean app without any dependencies with following steps:
1) react-native init demo
2) cd demo
3) react-native run-android

@jamminroot i have done that, it is working fine. This problem is coming after adding app center modules.

Same here

has this project been migrated to AndroidX yet and made ready for all the breaking changes that occurred in 0.60?

I am using the latest version of react native cli(2.x.x). And then created project from cli.
@victoriafrench would you please tell me how to convert this to androidX, as I read about androidX, it is the replacement of android support.

When I was trying this program it gave me some warnings.
The following packages use deprecated "rnpm" config that will stop working from next release:

I looked into it and tried to remove warnings. To remove this I followed this article: https://github.com/react-native-community/cli/blob/master/docs/configuration.md#migration-guide
after updating package.json file I am not getting warnings , but error is different now I think there should some change we need to do inside these modules.
here is the error which I am getting after updating package.json file to modules:
location of the error: \android\app\build\generated\rncli\src\main\java\com\facebook\react\PackageList.java:
error: constructor AppCenterReactNativePackage in class AppCenterReactNativePackage cannot be applied to given types;
new AppCenterReactNativePackage(),
^
required: Application
found: no arguments
reason: actual and formal argument lists differ in length

I think this issue is coming because of warnings.

I forked appcenter project into my local and build it and replace files to node_modules folder. it is working fine now.
steps to resolve issue:

  1. go to Url: https://github.com/microsoft/appcenter-sdk-react-native/
  2. fork or clone or download to your local account or system.
  3. open app center "appcenter" package.json file and remove "rnpm" section from file.
  4. add react-native.config.js file into it.
  5. add this code to react-native.config.js.
module.exports = {
  project: {
    android: {
      packageInstance: "new AppCenterReactNativePackage(MainApplication.this)"
    } // grouped into "project"
  },
  commands: {
    postlink: "node node_modules/appcenter/scripts/postlink"
  }
};
  1. repeat number 3 to 5 again for project appcenter-analytics and appcenter-crashes also.
  2. build project.
  3. copy files from those projects to node_module folder of your application into respective folders.

Note: I am not sure how give command in above code, the way I have given command above,it is giving warning that it should be array.

I am not sure it is correct or not, but if it is not right way then we need to wait for team resolve these warnings.

Thanks.

Thank's for your feedback!
We are working on this issue. There is no ETA I can provide yet, but it will be fixed.

@Jamminroot thank you the prompt response. I would like to contribute in this if you need anything from myside let me know. I will be happy to help.

Is this issue not because the location of the package importing has moved in the android project?

Previously this was in the MainApplication.java/class.

These are now being automatically added to PackageList.java/class:

public class PackageList {
  private Application application;
  private ReactNativeHost reactNativeHost;
  public PackageList(ReactNativeHost reactNativeHost) {
    this.reactNativeHost = reactNativeHost;
  }
  ...
  private Application getApplication() {
    if (this.reactNativeHost == null) return this.application;
    return this.reactNativeHost.getApplication();
  }
...
  public ArrayList<ReactPackage> getPackages() {
    return new ArrayList<>(Arrays.<ReactPackage>asList(
      new MainReactPackage(),
      new AppCenterReactNativePackage(**MainApplication.this**),
      new AppCenterReactNativeAnalyticsPackage(**MainApplication.this**, getResources().getString(R.string.appCenterAnalytics_whenToEnableAnalytics)),
      new AppCenterReactNativeCrashesPackage(**MainApplication.this**, getResources().getString(R.string.appCenterCrashes_whenToSendCrashes)),
      new RNGestureHandlerPackage()
    ));
  }
}

So the MainApplication is no longer accessible thus the Cannot find symbol error

I solved this by changing "MainApplication.this" for "this.application" in the packageInstance from appcenter, appcenter-analytics and appcenter-crashes:

// appcenter/package.json
...
packageInstance: "new AppCenterReactNativePackage(MainApplication.this)"
...

to

// appcenter/package.json
...
packageInstance: "new AppCenterReactNativePackage(this.application)"
...

But i dont know if its the right way to do this

@feliperrf I did something similar but used this.getApplication() instead as it does some extra bits.

Any idea how we can fix this going forward without breaking anything?

@Adam-STaC-Solutions here i had some errors with the "appCenterAnalytics_whenToEnableAnalytics" and "appCenterCrashes whenToSend Crashes" cause they weren't in the strings.xml file. You had the same error?

I had <string name="appCenterAnalytics_whenToEnableAnalytics" moduleConfig="true" translatable="false">ALWAYS_SEND</string> <string name="appCenterCrashes_whenToSendCrashes" moduleConfig="true" translatable="false">ALWAYS_SEND</string>

I did the linking a few times (adding and removing) before I realised the issue was unrelated, so might have been that.

@Adam-STaC-Solutions hmm, i had to put manually but i'll try that, thanks

Is there any temp solution for this?

Is there any temp solution for this?

team is working on it., in the meanwhile if you can use the old version.

if you are using react-native CLI to generate application code you can use this command.
react-native init --version="[email protected]" MyNewApp

if you include app-center with this version it works perfectly fine.

Is there any temp solution for this?

In react-native > 0.60

Create react-native.config.js in your project's root directory.

module.exports = {
  dependencies: {
    'appcenter': {
      platforms: {
        android: null, // disable Android platform, other platforms will still autolink if provided
      },
    },
    'appcenter-analytics': {
      platforms: {
        android: null, // disable Android platform, other platforms will still autolink if provided
      },
    },
    'appcenter-crashes': {
      platforms: {
        android: null, // disable Android platform, other platforms will still autolink if provided
      },
    },
  },
};

and link them manually in MainApplication.java like this:

import com.microsoft.appcenter.reactnative.crashes.AppCenterReactNativeCrashesPackage;
import com.microsoft.appcenter.reactnative.analytics.AppCenterReactNativeAnalyticsPackage;
import com.microsoft.appcenter.reactnative.appcenter.AppCenterReactNativePackage;

//****

@Override
    protected List<ReactPackage> getPackages() {
      @SuppressWarnings("UnnecessaryLocalVariable")
      List<ReactPackage> packages = new PackageList(this).getPackages();
      packages.add(new AppCenterReactNativeCrashesPackage(MainApplication.this, getResources().getString(R.string.appCenterCrashes_whenToSendCrashes)));
      packages.add(new AppCenterReactNativeAnalyticsPackage(MainApplication.this, getResources().getString(R.string.appCenterAnalytics_whenToEnableAnalytics)));
      packages.add(new AppCenterReactNativePackage(MainApplication.this));
      return packages;
    }

Thanks @Donjay2101 , but we need to build Android 64bit, so we have to use 0.60

Thanks @akhavein, your solution is working for me.

Hi everyone @jessejiang0214 @Donjay2101 @feliperrf @Adam-STaC-Solutions. We are actively working on RN 0.60 support and we plan to support in in the July release. Thank you and my sincere apologies for the long response.

Thank you @akhavein your solution is working for me too.

The @akhavein solution is not working for me. I am getting the following error:

Error: Command failed: ./gradlew app:installDebug -PreactNativeDevServerPort=8081
Note: /Users/danale/Projects/NFIBEngage/node_modules/react-native-sentry/android/src/main/java/io/sentry/RNSentryModule.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
/Users/danale/Projects/NFIBEngage/android/app/src/main/java/com/nfibengage/MainApplication.java:16: error: package com.microsoft.appcenter.reactnative.crashes does not exist
import com.microsoft.appcenter.reactnative.crashes.AppCenterReactNativeCrashesPackage;
                                                  ^
/Users/danale/Projects/NFIBEngage/android/app/src/main/java/com/nfibengage/MainApplication.java:17: error: package com.microsoft.appcenter.reactnative.analytics does not exist
import com.microsoft.appcenter.reactnative.analytics.AppCenterReactNativeAnalyticsPackage;
                                                    ^
/Users/danale/Projects/NFIBEngage/android/app/src/main/java/com/nfibengage/MainApplication.java:18: error: package com.microsoft.appcenter.reactnative.appcenter does not exist
import com.microsoft.appcenter.reactnative.appcenter.AppCenterReactNativePackage;
                                                    ^
3 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.

It's already the middle of July, is there a fix for this yet?

@ldco2016 I am still getting the MainApplication.this error as well. Even after adding the react-native-config.js file and setting the appcenter packages to not auto link.

@bobber205 , how do you get the appcenter packages to not auto link?

@ldco2016 Check this out https://github.com/react-native-community/cli/pull/444/files#diff-e170f7cfd11ce7d2abb04a47b02a4caa

@ldco2016 Looking closer at your error -- do you have the proper imports at the top of your file? Did you complete the normal linking process?

@ldco2016
Please make sure that you have done this part:
https://facebook.github.io/react-native/docs/getting-started#3-configure-the-android_home-environment-variable

and also you are using Jetifire.


Your android/settings.gradle should be something like this:

rootProject.name = 'reactNativeSample'
apply from: file("../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesSettingsGradle(settings)
include ':appcenter-crashes'
project(':appcenter-crashes').projectDir = new File(rootProject.projectDir, '../node_modules/appcenter-crashes/android')
include ':appcenter-analytics'
project(':appcenter-analytics').projectDir = new File(rootProject.projectDir, '../node_modules/appcenter-analytics/android')
include ':appcenter'
project(':appcenter').projectDir = new File(rootProject.projectDir, '../node_modules/appcenter/android')
include ':app'

Your android/app/build.gradle -> dependencies section should contain this:

    implementation project(':appcenter-crashes')
    implementation project(':appcenter-analytics')
    implementation project(':appcenter')

Your android/app/src/main/java/.../MainApplication.java should be something like this:

package com.reactNativeSample;

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.microsoft.appcenter.reactnative.crashes.AppCenterReactNativeCrashesPackage;
import com.microsoft.appcenter.reactnative.analytics.AppCenterReactNativeAnalyticsPackage;
import com.microsoft.appcenter.reactnative.appcenter.AppCenterReactNativePackage;

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.add(new AppCenterReactNativeCrashesPackage(MainApplication.this, getResources().getString(R.string.appCenterCrashes_whenToSendCrashes)));
      packages.add(new AppCenterReactNativeAnalyticsPackage(MainApplication.this, getResources().getString(R.string.appCenterAnalytics_whenToEnableAnalytics)));
      packages.add(new AppCenterReactNativePackage(MainApplication.this));
      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);
  }
}

@akhavein FWIW I could never get MainApplication.this to ever compile.

this.getApplication() is working ok though.

I had to linked app-center manually with react-native 0.60.4 and works well.

https://docs.microsoft.com/en-us/appcenter/sdk/getting-started/react-native

Thanks guys, your suggestions finally worked along with what this individual recommended I do:
https://stackoverflow.com/questions/57152499/react-native-error-cannot-find-symbol-new-appcenterreactnativeanalyticspacka/57156235#57156235

Hi everyone! App Center React-Native SDK with 0.60 support is finally released! I'm closing this, feel free to re-open in case any issues.

@akhavein @annakocheshkova , so do we need MainApplication.java file configured as suggested by @akhavein ?

Because even when I completely remove it. Even when I ensure I have not manually linked appcenter to my RN 60.4, I still get the error documented here:
https://github.com/microsoft/appcenter-sdk-react-native/issues/666

Those steps are for React Native App Center SDK pre 0.60 support. Now that the support for it has been introduced, no need to do any of those steps. Autolinking already does them for you.

Still have the same issue with rn 0.60.4 and app-center 2.3.0

@DerekFei If you've followed the steps from this comment, I'd suggest to revert them and do the installation again.

I am getting this same error from the app center plugins:

    "react": "16.9.0",
    "react-dom": "16.9.0",
    "react-native": "0.61.4",
    "appcenter": "3.0.0",
    "appcenter-analytics": "3.0.0",
    "appcenter-crashes": "3.0.0",

error:


> Task :app:compileReleaseJavaWithJavac FAILED
/Users/jeremy/Dropbox/code/SethIndustries/reporthero-app/android/app/build/generated/rncli/src/main/java/com/facebook/react/PackageList.java:67: error: cannot find symbol
      new AppCenterReactNativeAnalyticsPackage(getApplication(), getResources().getString(R.string.appCenterAnalytics_whenToEnableAnalytics)),
                                                                                                  ^
  symbol:   variable appCenterAnalytics_whenToEnableAnalytics
  location: class string
/Users/jeremy/Dropbox/code/SethIndustries/reporthero-app/android/app/build/generated/rncli/src/main/java/com/facebook/react/PackageList.java:68: error: cannot find symbol
      new AppCenterReactNativeCrashesPackage(getApplication(), getResources().getString(R.string.appCenterCrashes_whenToSendCrashes)),
                                                                                                ^
  symbol:   variable appCenterCrashes_whenToSendCrashes
  location: class string
2 errors

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:compileReleaseJavaWithJavac'.

EDIT: See solution below

@JeremyEllingham have u tried above steps given in some of replies. I am sure one of will help you out

@Donjay2101 I'm on React Native >0.60 so I thought autolinking should take care of any additional setup. I've checked that all my files match close enough to the ones @akhavein suggested. MainApplication.this doesn't appear in my app anywhere. I've also tried moving the app center plugins back to version ^2 and React-Native back to 0.60.

No luck with any of that so far.

I have found the solution, somehow I had missed the rest of the Android SDK setup for React-native:

https://docs.microsoft.com/en-us/appcenter/sdk/getting-started/react-native#312-integrate-react-native-android

I had to create android/app/src/main/assets/appcenter-config.json with:

{
    "app_secret": "{APP_SECRET_VALUE}"
}

And also add the following lines inside the tag in android/app/src/main/res/values/strings.xml

<string name="appCenterCrashes_whenToSendCrashes" moduleConfig="true" translatable="false">DO_NOT_ASK_JAVASCRIPT</string>
<string name="appCenterAnalytics_whenToEnableAnalytics" moduleConfig="true" translatable="false">ALWAYS_SEND</string>

@JeremyEllingham 's solution was what I needed to get the app to compile, the documentation needs to be updated that react native should still follow the android install instructions

@82rules can you describe what is unclear about the current RN android instructions?

@dimatretyak this is a link to the code push instructions. Please go through these instructions and report back if anything is unclear.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

henrikra picture henrikra  路  10Comments

aprilmintacpineda picture aprilmintacpineda  路  5Comments

rafaelcorreiapoli picture rafaelcorreiapoli  路  5Comments

KingAmo picture KingAmo  路  8Comments

MrLoh picture MrLoh  路  4Comments