I have followed the installations steps from https://docs.microsoft.com/en-us/appcenter/sdk/getting-started/react-native#31-integrate-the-sdk-automatically-for-react-native-060
react-native init code_push_testyarn add react-native-code-pushInstall appcenter sdk by
yarn add appcenter appcenter-analytics appcenter-crashes --exact
Create app on appcenter.
Add deployment environments i.e. Production and Staging on appcenter.
android/app/src/main/assets/appcenter-config.json:{
"app_secret": "{APP_SECRET_VALUE}"
}
res/values/strings.xml:<string moduleConfig="true" name="reactNativeCodePush_androidDeploymentKey">{deployment-key-here}</string>
<string name="appCenterCrashes_whenToSendCrashes" moduleConfig="true" translatable="false">ASK_JAVASCRIPT</string>
<string name="appCenterAnalytics_whenToEnableAnalytics" moduleConfig="true" translatable="false">ALWAYS_SEND</string>
App.js as following:import codePush from "react-native-code-push";
class MyApp extends Component {
}
MyApp = codePush(MyApp);
appcenter by the command: appcenter codepush release-react -a <ownerName>/code_push_example -d StagingThe app should be update via CodePush after pushing bundle to the appcenter.
App is not getting updates from AppCenter.
This is the Github repofor my example project: https://github.com/ajaykumar97/code_push_example
Hi! We had the same problem but finally solved it!! We managed to have codepush working on React Native 0.60.5 and Hermes ✌️🙌
It seems that auto-linking from the new RN wasn't working for us.
We did the following:
On MainApplication.java we manually added the package referencing the CODEPUSH_KEY:
protected List<ReactPackage> getPackages() {
@SuppressWarnings("UnnecessaryLocalVariable")
List<ReactPackage> packages = new PackageList(this).getPackages();
//add this line
packages.add(new CodePush(BuildConfig.CODEPUSH_KEY, MainApplication.this, BuildConfig.DEBUG));
return packages;
}
then we made sure to tell react native to not link this library via the auto-linking:
Create a react-native-config.js at the root of your project (if you don't have it yet) and add this:
module.exports = {
dependencies: {
"react-native-code-push": {
platforms: {
android: null // disable Android platform, other platforms will still autolink if provided
}
}
}
};
Make a new staging/release build and codepush should start installing updates again! 🎊
Thanks @GonzaloRecioG. Your solution resolved the issue. I would keep this issue open so as to make it noticeable for the react-native-code-push team as they have mentioned in the doc that react-native-code-push is now compatible with the autolinking.
Hello guys... What about the IOS version? Still doesn't work here, as far as i know...
Any solutions?
Thanks!
For Android
If you want to use autolink for the time being until codepush is updated to support multiple buildtypes automatically you just need to overwrite the deployment key in the getPackages section in MainApplicaiotn.java
List
// Packages that cannot be autolinked yet can be added manually here, for example:
// packages.add(new MyReactNativePackage());
for(ReactPackage reactPackage: packages) {
if (reactPackage instanceof CodePush) {
((CodePush)reactPackage).setDeploymentKey(BuildConfig.CODEPUSH_KEY);
}
}
return packages;
you just need to add an empty deploymentkey in the strings.xml (if you only have one release build type you can ignore the above step and just enter your actual production key below)
name="reactNativeCodePush_androidDeploymentKey" moduleConfig="true"
Good luck!
Hi! We had the same problem but finally solved it!! We managed to have codepush working on React Native 0.60.5 and Hermes ✌️🙌
It seems that auto-linking from the new RN wasn't working for us.We did the following:
On
MainApplication.javawe manually added the package referencing the CODEPUSH_KEY:protected List<ReactPackage> getPackages() { @SuppressWarnings("UnnecessaryLocalVariable") List<ReactPackage> packages = new PackageList(this).getPackages(); //add this line packages.add(new CodePush(BuildConfig.CODEPUSH_KEY, MainApplication.this, BuildConfig.DEBUG)); return packages; }then we made sure to tell react native to not link this library via the auto-linking:
Create areact-native-config.jsat the root of your project (if you don't have it yet) and add this:module.exports = { dependencies: { "react-native-code-push": { platforms: { android: null // disable Android platform, other platforms will still autolink if provided } } } };Make a new staging/release build and codepush should start installing updates again! 🎊
File name to handle manual react native link should be: react-native.config.js
ANDROID
Instead of disabling autolinking, you all should put this line at the end of android/app/build.gradle:
apply from: file("../../node_modules/react-native-code-push/android/codepush.gradle");
apply from stuff are not autolinked by default, this happens in any library.
Also make sure you have reactNativeCodePush_androidDeploymentKey at android/app/src/main/res/values/strings.xml, this is how autolink will work, and not by using BuildConfig.CODEPUSH_KEY, like I've seen in some comments.
Sample file:
<resources>
<string name="app_name">My App</string>
<string name="appCenterAnalytics_whenToEnableAnalytics" moduleConfig="true" translatable="false">ALWAYS_SEND</string>
<string name="appCenterCrashes_whenToSendCrashes" moduleConfig="true" translatable="false">ALWAYS_SEND</string>
<string name="reactNativeCodePush_androidDeploymentKey" moduleConfig="true">deployment-key</string>
</resources>
IOS
Make sure your Info.plist contains deployment key for iOS
<key>CodePushDeploymentKey</key>
<string>deployment-key</string>
Add bundleURL to AppDelegate.m:
...
#import <CodePush/CodePush.h>
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
...
}
- (NSURL *)sourceURLForBridge:(RCTBridge *)bridge
{
#if DEBUG
return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index" fallbackResource:nil];
#else
return [CodePush bundleURL];
#endif
}
@leonardofalk
I ran react-native link react-native-code-push and then applied your line tobuild.gradle. How should I set up CodePush in MainApplication.java? It seems like it's already set up from link, but when I run/build it, all I get is a blank screen.
@leonardofalk
I ran
react-native link react-native-code-pushand then applied your line tobuild.gradle. How should I set up CodePush inMainApplication.java? It seems like it's already set up from link, but when I run/build it, all I get is a blank screen.
You don't need to run link or change MainActivity.java with RN 0.60.+, the only changes needed are in my previous post.
If you did run link by now you should run unlink to undo native changes, then follow my steps again, otherwise you'll get a duplicated link error, also remove any entry with 'react-native-code-push' to your react-native.config.js.
If after that you are still facing issues, run on an android device/emulator and try checking the logs with adb logcat, it's not linked properly if you see something like:
The CodePush module doesn't appear to be properly installed. Please double-check that everything is setup correctly.
大家好...... IOS版本怎么样?据我所知,仍然无法在这里工作......
任何解决方案?谢谢!
did you solve it
@leonardofalk
You don't need to run link or change MainActivity.java with RN 0.60.+, the only changes needed are in my previous post.
I copied your post exactly and now I'm getting this:
Error: Command failed: ./gradlew app:installDebug -PreactNativeDevServerPort=8081
FAILURE: Build failed with an exception.
* What went wrong:
Could not determine the dependencies of task ':app:preDebugBuild'.
> Could not resolve all task dependencies for configuration ':app:debugRuntimeClasspath'.
> Could not resolve project :react-native-code-push.
Required by:
project :app
> Unable to find a matching configuration of project :react-native-code-push:
- None of the consumable configurations have attributes.
* 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.
It runs fine on iOS, any idea why this error is popping up?
@jeffmon You need to run with --stacktrace option to get more insight.
cd android
./gradlew assembleDebug --stacktrace
@leonardofalk Thanks for your response! I'm getting this:
* What went wrong:
Could not determine the dependencies of task ':app:compileDebugJavaWithJavac'.
> Could not resolve all task dependencies for configuration ':app:debugCompileClasspath'.
> Could not resolve project :react-native-code-push.
Required by:
project :app
> Unable to find a matching configuration of project :react-native-code-push:
- None of the consumable configurations have attributes.
* Try:
Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Exception is:
org.gradle.api.internal.tasks.TaskDependencyResolveException: Could not determine the dependencies of task ':app:compileDebugJavaWithJavac'.
at org.gradle.api.internal.tasks.CachingTaskDependencyResolveContext.getDependencies(CachingTaskDependencyResolveContext.java:68)
at org.gradle.execution.plan.TaskDependencyResolver.resolveDependenciesFor(TaskDependencyResolver.java:46)
at org.gradle.execution.plan.LocalTaskNode.getDependencies(LocalTaskNode.java:111)
at org.gradle.execution.plan.LocalTaskNode.resolveDependencies(LocalTaskNode.java:79)
at org.gradle.execution.plan.DefaultExecutionPlan.addEntryTasks(DefaultExecutionPlan.java:177)
at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph.addEntryTasks(DefaultTaskExecutionGraph.java:139)
at org.gradle.execution.TaskNameResolvingBuildConfigurationAction.configure(TaskNameResolvingBuildConfigurationAction.java:48)
at org.gradle.execution.DefaultBuildConfigurationActionExecuter.configure(DefaultBuildConfigurationActionExecuter.java:57)
at org.gradle.execution.DefaultBuildConfigurationActionExecuter.access$200(DefaultBuildConfigurationActionExecuter.java:26)
at org.gradle.execution.DefaultBuildConfigurationActionExecuter$2.proceed(DefaultBuildConfigurationActionExecuter.java:63)
at org.gradle.execution.DefaultTasksBuildExecutionAction.configure(DefaultTasksBuildExecutionAction.java:44)
at org.gradle.execution.DefaultBuildConfigurationActionExecuter.configure(DefaultBuildConfigurationActionExecuter.java:57)
at org.gradle.execution.DefaultBuildConfigurationActionExecuter.access$200(DefaultBuildConfigurationActionExecuter.java:26)
at org.gradle.execution.DefaultBuildConfigurationActionExecuter$2.proceed(DefaultBuildConfigurationActionExecuter.java:63)
at org.gradle.execution.ExcludedTaskFilteringBuildConfigurationAction.configure(ExcludedTaskFilteringBuildConfigurationAction.java:47)
at org.gradle.execution.DefaultBuildConfigurationActionExecuter.configure(DefaultBuildConfigurationActionExecuter.java:57)
at org.gradle.execution.DefaultBuildConfigurationActionExecuter.access$200(DefaultBuildConfigurationActionExecuter.java:26)
at org.gradle.execution.DefaultBuildConfigurationActionExecuter$1.run(DefaultBuildConfigurationActionExecuter.java:43)
at org.gradle.internal.Factories$1.create(Factories.java:25)
Do I have to modify anything in MainApplication.java?
@jeffmon either you are not using react-native 0.60+, or you have disabled auto link for this package in react-native.config.js.
As a workaround, you can try doing steps 1 and 2 of this guide: https://github.com/microsoft/react-native-code-push/blob/master/docs/setup-android.md#plugin-installation-android---manual
@jeffmon either you are not using react-native 0.60+, or you have disabled auto link for this package in react-native.config.js.
@leonardofalk I'm using react-native 0.60.5 and I don't have that file react-native.config.js at all.
Those steps aren't working for me either, a similar error pops up. Thanks for your help anyway!
@jeffmon did you find a solution ?
@abrantes01 It was related to this: https://docs.microsoft.com/en-us/appcenter/distribution/codepush/react-native#plugin-installation-android---manual. I didn't have the proper file path in android/settings.gradle.
Hi all,
We opened PR for updating docs with setup CodePush for [email protected] and above.
For more info please check here: https://github.com/microsoft/react-native-code-push/issues/1625#issuecomment-560489061
I'm going to close this issue as duplicate. Please feel free to ask any questions.
Thanks,
Alexander
@thanhcuong1990 Thank you!
@GonzaloRecioG Could you please edit your comment?
File name must be: react-native.config.js
- react-native-config.js <= Wrong !!!!
+ react-native.config.js
I am getting exactly the same error as @jeffmon . I have RN 0.62.0 and react-native-code-push 6.2.1. The link @jeffmon mentioned is no longer available (: https://docs.microsoft.com/en-us/appcenter/distribution/codepush/react-native#plugin-installation-android---manual). I followed the 0.60+ steps for Android in https://github.com/microsoft/react-native-code-push/blob/master/docs/setup-android.md#plugin-installation-android---manual with no luck. Any ideas how I can resolve this?
`> Configure project :app
WARNING: Configuration 'compile' is obsolete and has been replaced with 'implementation' and 'api'.
It will be removed in version 5.0 of the Android Gradle plugin.
For more information, see http://d.android.com/r/tools/update-dependency-configurations.html.
registerResGeneratingTask is deprecated, use registerGeneratedResFolders(FileCollection)
registerResGeneratingTask is deprecated, use registerGeneratedResFolders(FileCollection)
Configure project :react-native-firebase
react-native-firebase: using React Native prebuilt binary from
/Dev/node_modules/react-native/android
WARNING: The specified Android SDK Build Tools version (28.0.3) is ignored, as it is below the minimum supported version (29.0.2) for Android Gradle Plugin 4.0.0.
Android SDK Build Tools 29.0.2 will be used.
To suppress this warning, remove "buildToolsVersion '28.0.3'" from your build.gradle file, as each version of the Android Gradle Plugin now has a default version of the build tools.
FAILURE: Build failed with an exception.
What went wrong:
Could not determine the dependencies of task ':app:compileDebugJavaWithJavac'.
Could not resolve all task dependencies for configuration ':app:debugCompileClasspath'.
Could not resolve project :react-native-code-push.
Required by:
project :app
Unable to find a matching configuration of project :react-native-code-push:
- None of the consumable configurations have attributes.
Try:
Run with --info or --debug option to get more log output. Run with --scan to get full insights.
Exception is:
org.gradle.api.internal.tasks.TaskDependencyResolveException: Could not determine the dependencies of task ':app:compileDebugJavaWithJavac'.
at org.gradle.api.internal.tasks.CachingTaskDependencyResolveContext.getDependencies(CachingTaskDependencyResolveContext.java:68)
at org.gradle.execution.plan.TaskDependencyResolver.resolveDependenciesFor(TaskDependencyResolver.java:46)
at org.gradle.execution.plan.LocalTaskNode.getDependencies(LocalTaskNode.java:161)
at org.gradle.execution.plan.LocalTaskNode.resolveDependencies(LocalTaskNode.java:129)
...
Most helpful comment
Hi! We had the same problem but finally solved it!! We managed to have codepush working on React Native 0.60.5 and Hermes ✌️🙌
It seems that auto-linking from the new RN wasn't working for us.
We did the following:
On
MainApplication.javawe manually added the package referencing the CODEPUSH_KEY:then we made sure to tell react native to not link this library via the auto-linking:
Create a
react-native-config.jsat the root of your project (if you don't have it yet) and add this:Make a new staging/release build and codepush should start installing updates again! 🎊