Errror: cannot find symbol: variable reactNativeCodePush_androidDeploymentKey
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);
}
}
@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?
I came across the same issue today. Seems like from docs here. Though it is configured in JS we cannot skip the part where it needs to be added to strings.xml for android and Info.plist for IOS since it will be overridden by the key provided in JS. As the docs clearly mention below:
If you need to dynamically use a different deployment, you can also override your deployment key in JS code using Code-Push options*
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>
Thanks a lot, you saved me several hours of debugging. Blessings