React-native-code-push: Errror: cannot find symbol: variable reactNativeCodePush_androidDeploymentKey

Created on 22 Sep 2019  路  24Comments  路  Source: microsoft/react-native-code-push

Attempting to install codepush on Android for ReactNative.

  • react-native-code-push version: "^5.7.0"
  • react-native version: "0.60.4"

I'm receiving this error:

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.4.1/userguide/command_line_interface.html#sec:command_line_warnings
70 actionable tasks: 7 executed, 63 up-to-date
/Users/lukeschoenberger/Documents/Programming/news-arg/test7/android/app/build/generated/rncli/src/main/java/com/facebook/react/PackageList.java:59: error: cannot find symbol
      new CodePush(getResources().getString(R.string.reactNativeCodePush_androidDeploymentKey), getApplicationContext(), BuildConfig.DEBUG),
                                                    ^
  symbol:   variable reactNativeCodePush_androidDeploymentKey
  location: class string
1 error

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

This is my MainApplication.java:

package com.test7;


import com.microsoft.codepush.react.CodePush;

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.oblador.vectoricons.VectorIconsPackage;
import com.amazonaws.RNAWSCognitoPackage;
import com.facebook.react.ReactNativeHost;
import com.facebook.react.ReactPackage;
import com.facebook.soloader.SoLoader;
import com.facebook.react.shell.MainReactPackage;

import java.util.Arrays;
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 String getJSBundleFile() {
        return CodePush.getJSBundleFile();
    }

    @Override
    protected List<ReactPackage> getPackages() {
        return Arrays.<ReactPackage>asList(
            new MainReactPackage(),
            new CodePush("XXXTHISISMYKEYXXXX", MainApplication.this, BuildConfig.DEBUG)
        );
    }

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

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

  @Override
  public void onCreate() {
    super.onCreate();
    SoLoader.init(this, /* native exopackage */ false);
  }
}

Most helpful comment

After upgrading to 6.0.0 from 5.6.1 change the strings.xml as:

<string name="CodePushDeploymentKey" moduleConfig="true" translatable="false">YOUR_DEPLOYEMENT_KEY</string>

All 24 comments

same problem

  • react-native-code-push version: "^5.7.0"
  • react-native version: "0.61.1"

Try to put this line in your file android/app/src/main/res/values/strings.xml

<string name="reactNativeCodePush_androidDeploymentKey" moduleConfig="true" translatable="false">YOU_ANDROID_CODEPUSH_KEY</string>

But what about if I want to put that key from buildTypes (android/app/build.gradle)?

I just started getting this too after upgrading to RN 0.60.

Originally in MainApplication I had:

return Arrays.asList(
           ...,
                 new CodePush(getResources().getString(BuildConfig.DEBUG
                     ? R.string.reactNativeCodePush_androidDeploymentKey_dev
                     : R.string.reactNativeCodePush_androidDeploymentKey_production
                 ), getApplicationContext(), BuildConfig.DEBUG),
           ...
);

So that I could get codepush bundles for different buildConfigs. But I'm not sure how to do similar with autolinking. It seems like it will always just get R.string.reactNativeCodePush_androidDeploymentKey.

same issue.
every time when i build the project ,it will create a PackageList.java with "new CodePush(getResources().getString(R.string.reactNativeCodePush_androidDeploymentKey), getApplicationContext(), BuildConfig.DEBUG)",what ever i config what at MainApplication

ok guys, you can disable Autolinking and linking manually to fix this:

  • react-native.config.js
module.exports = {
  dependencies: {
    'react-native-code-push': {
      platforms: {
        android: null // disable Android platform, other platforms will still autolink if provided
      }
    }
  }
}

For more details check here: https://github.com/react-native-community/cli/blob/master/docs/autolinking.md#how-can-i-disable-autolinking-for-unsupported-library

I came across this PR https://github.com/MicrosoftDocs/appcenter-docs/pull/767 which helped solve it for me and allow me to use keys from the buildTypes with RN 0.60+. Follow the commits for all the details, but here is a quick summary:

  • Keep the import in MainApplication.java
    import com.microsoft.codepush.react.CodePush;
  • Keep the override getJSBundleFile method.
  • Remove buildConfigFields and update to this format
    resValue "string", "reactNativeCodePush_androidDeploymentKey", '"<INSERT_PRODUCTION_KEY>"'
  • Remove the key from strings.xml if it's been added there.

Hope this helps someone else!

Your solution worked for me, @nathanvoller!
Thanks a lot!

@ivanguimam sorry for the delayed response, but this solved my issue. thanks a bunch!!!!

Hello @nathanvoller there is how you show me how your MainApplication.java ?

@nathanvoller would you mind expanding a little on your implementation? I think there are several of us out here still stuck with the 0.60+ installation process

@luskin I've set it up like below:

MainApplication.java#getPackages

            List<ReactPackage> packages = new PackageList(this).getPackages();
            packages.add(
                new CodePush(getResources().getString(BuildConfig.DEBUG
                    ? R.string.reactNativeCodePush_androidDeploymentKey_dev
                    : R.string.reactNativeCodePush_androidDeploymentKey_production
                ), getApplicationContext(), BuildConfig.DEBUG)
            );

and then have your keys in strings.xml

@luskin looks like @Aequitas737's comment has resolved it for you, but just in case anyone else is wondering, here is my implementation:

MainApplication.java

import com.microsoft.codepush.react.CodePush;
...

public class MainApplication extends Application implements ReactApplication {
  ...
  private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) {
    ...
    @Override
    protected String getJSBundleFile() {
      return CodePush.getJSBundleFile();
    }
    ...
  }
}

app/build.gradle

apply from: "../../node_modules/react-native/react.gradle"
apply from: "../../node_modules/react-native-code-push/android/codepush.gradle"

android {
  ...
  buildTypes {
    debug {
      // Note: CodePush updates should not be tested in Debug mode as they are overridden by the RN packager.
      // However, because CodePush checks for updates in all modes, we must supply a key.
      resValue "string", "reactNativeCodePush_androidDeploymentKey", '""'
    }
    releaseStaging {
      resValue "string", "reactNativeCodePush_androidDeploymentKey", '"<<INSERT_STAGING_KEY_HERE>>"'
    }
    release {
      resValue "string", "reactNativeCodePush_androidDeploymentKey", '"<<INSERT_PRODUCTION_KEY_HERE>>"'
    }
  }
  ...
}

Remember to remove the keys from strings.xml if you are configuring the deployment keys in the build process like I have above 馃憤

Please don't disable auto-linkage as one of the comment above suggests. It's not the right way around this issue. I've updated the relevant documentation and it's up to the docs team to approve it.

@zanechua please link to your updated documentation. We have disabled auto-linkage and it is working as expected for us but in the spirit of not hacking it I'd love to see how you got it working otherwise.

@luskin

@nathanvoller has linked the PR above. That's my PR.

Either the implementation is not complete or the docs are confusing:
On https://github.com/microsoft/react-native-code-push/blob/master/docs/setup-android.md#plugin-installation-and-configuration-for-react-native-060-version-and-above-android it says

Note: You can also set your deployment key in JS code using Code-Push options

I understood this in the way that I can only set up deploymentKey in codePushOptions as described in https://github.com/microsoft/react-native-code-push#plugin-usage without need for touching strings.xml or Info.plist

const codePushOptions = {
  deploymentKey: '<<INSERT_STAGING_OR_PRODUCTION_KEY_HERE>>'
};
MyApp = codePush(codePushOptions)(MyApp);

Is this an alternative for setting the deployment key?
If I set reactNativeCodePush_androidDeploymentKey in strings.xml to empty string as a workaround and set deploymentKey in js as described above will other codePush functions like codePush.sync() take my configuration from js or the empty string that I've set up?

Update
I've checked it myself and setting empty string in strings.xml works for me, but I additionally have to pass deploymentKey to codePush.sync() since I use manual set up. codePush.getUpdateMetadata works correctly without any further set up.

I faced the same problem and here is how I fix.
I setup manual follow the steps of Android Setup Menu.
At the step of config with MainApplication.java of For React Native >= v0.29 :
Here is their step :

// 1. Import the plugin class.
import com.microsoft.codepush.react.CodePush;
// 2. Override the getJSBundleFile method in order to let the CodePush runtime determine 
// where to get the JS bundle location from on each app start
@Override
        protected String getJSBundleFile() {
            return CodePush.getJSBundleFile();
}

When come to step 3, here is how I fix
Add this

packages.add(new CodePush(getResources().getString(R.string.CodePushDeploymentKey), getApplicationContext(), BuildConfig.DEBUG));
And then in strings.xml I add something like this

<string name="CodePushDeploymentKey">my-code-push-key</string>

Please make sure that if in your MainApplication.java you put CodePushDeploymentKey, also put it the same in strings.xml

After these steps. You can clean your android project and run again.

I hope this can help your day. :D

After upgrading to 6.0.0 from 5.6.1 change the strings.xml as:

<string name="CodePushDeploymentKey" moduleConfig="true" translatable="false">YOUR_DEPLOYEMENT_KEY</string>

Hi @schoenbl ,
Thank you for reporting!

Not so long ago we released a new version of Code Push which supports react-native v0.60-v0.61.
All steps for installing the latest version of the plugin are described in our documentation: https://github.com/microsoft/react-native-code-push/blob/master/docs/setup-ios.md

I'm going to close this issue for now. Please feel free to reopen it if you have any questions or issues.

@kiranjd does that mean we're checking in our deployment keys? I'm using react-native-config for env vars, so you know how I'd use and env var here?

I faced the same problem and here is how I fix.
I setup manual follow the steps of Android Setup Menu.
At the step of config with MainApplication.java of For React Native >= v0.29 :
Here is their step :

// 1. Import the plugin class.
import com.microsoft.codepush.react.CodePush;
// 2. Override the getJSBundleFile method in order to let the CodePush runtime determine 
// where to get the JS bundle location from on each app start
@Override
        protected String getJSBundleFile() {
            return CodePush.getJSBundleFile();
}

When come to step 3, here is how I fix
Add this

packages.add(new CodePush(getResources().getString(R.string.CodePushDeploymentKey), getApplicationContext(), BuildConfig.DEBUG));
And then in strings.xml I add something like this

<string name="CodePushDeploymentKey">my-code-push-key</string>

Please make sure that if in your MainApplication.java you put CodePushDeploymentKey, also put it the same in strings.xml

After these steps. You can clean your android project and run again.

I hope this can help your day. :D

Thank you so much. That worked for me.

Hey Guys!

In app/build.gradle for this error:

BUILD FAILED in 17s

error Failed to install the app. Make sure you have the Android development environment set up: https://reactnative.dev/docs/getting-started.html#android-development-environment. Run CLI with --verbose flag for more details.
Error: Command failed: ./gradlew app:installDebug -PreactNativeDevServerPort=8081
Note: /Users/emmet/projects/github/pazchurch/node_modules/react-native-code-push/android/app/src/main/java/com/microsoft/codepush/react/CodePushNativeModule.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
Note: /Users/emmet/projects/github/pazchurch/node_modules/react-native-gesture-handler/android/src/main/java/com/swmansion/gesturehandler/react/RNGestureHandlerButtonViewManager.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.
Note: /Users/emmet/projects/github/pazchurch/node_modules/react-native-onesignal/android/src/main/java/com/geektime/rnonesignalandroid/RNOneSignal.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
/Users/emmet/projects/github/pazchurch/android/app/build/generated/rncli/src/main/java/com/facebook/react/PackageList.java:65: error: cannot find symbol
      new CodePush(getResources().getString(com.pazchurch.R.string.CodePushDeploymentKey), getApplicationContext(), com.pazchurch.BuildConfig.DEBUG),
                                                                  ^
  symbol:   variable CodePushDeploymentKey
  location: class string
Note: /Users/emmet/projects/github/pazchurch/android/app/src/debug/java/com/pazchurch/ReactNativeFlipper.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
1 error
buildTypes {
        debug {
            // signingConfig signingConfigs.debug
            resValue "string", "CodePushDeploymentKey", '""'
        }

        releaseStaging {
            resValue "string", "CodePushDeploymentKey", '""'
            matchingFallbacks = ['debug', 'release']
        }

        release {
            resValue "string", "CodePushDeploymentKey", '""'
            // signingConfig signingConfigs.debug
            minifyEnabled enableProguardInReleaseBuilds
            proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
        }
    }

@oeduardoal did you get any solution?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Phredward picture Phredward  路  3Comments

DeDuckProject picture DeDuckProject  路  3Comments

diegocouto picture diegocouto  路  4Comments

panarasi picture panarasi  路  4Comments

quanzaiyu picture quanzaiyu  路  3Comments