react-native-code-push icon indicating copy to clipboard operation
react-native-code-push copied to clipboard

Errror: cannot find symbol: variable reactNativeCodePush_androidDeploymentKey

Open schoenbl opened this issue 7 years ago • 26 comments

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);
  }
}

schoenbl avatar Sep 22 '19 20:09 schoenbl

same problem

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

ivanguimam avatar Sep 26 '19 20:09 ivanguimam

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>

ivanguimam avatar Sep 27 '19 14:09 ivanguimam

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

jdnichollsc avatar Oct 07 '19 16:10 jdnichollsc

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.

Aequitas737 avatar Oct 10 '19 05:10 Aequitas737

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

callcter avatar Oct 10 '19 07:10 callcter

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

jdnichollsc avatar Oct 10 '19 13:10 jdnichollsc

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!

nathanvoller avatar Oct 24 '19 09:10 nathanvoller

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

AlcantaraRW avatar Oct 29 '19 02:10 AlcantaraRW

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

schoenbl avatar Oct 29 '19 18:10 schoenbl

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

AdrianoBiolchi avatar Nov 05 '19 17:11 AdrianoBiolchi

@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 avatar Nov 18 '19 20:11 luskin

@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

Aequitas737 avatar Nov 18 '19 22:11 Aequitas737

@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 👍

nathanvoller avatar Nov 19 '19 10:11 nathanvoller

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 avatar Nov 23 '19 16:11 zanechua

@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 avatar Nov 25 '19 04:11 luskin

@luskin

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

zanechua avatar Nov 25 '19 04:11 zanechua

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.

mieszko4 avatar Dec 09 '19 18:12 mieszko4

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

temchannat avatar Dec 12 '19 07:12 temchannat

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>

kiranjd avatar Dec 24 '19 06:12 kiranjd

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.

andreidubov avatar Feb 12 '20 11:02 andreidubov