Updating Apps (5.0 and Later) Apps (5.0 and Later)
Native and React native apps get an easier path to future Mobile SDK upgrades. Instead
of creating an app and porting your app’s resources to it, you now update a simple configuration
file and then run a script that regenerates your app with the new SDK libraries.
Updating Native and React Native Apps
Each native and React native app directory contains a package.json file
at its root level. This JSON file contains a “dependencies” object that includes a list of
name-value pairs describing Mobile SDK source paths. You
can set these values to any local or network path that points to a valid copy of the platform’s
Mobile SDK. After you’ve
updated this file, perform the update by running:
- install.js for Android native, iOS native, and native Swift apps
- installandroid.js for React native apps on Android
- installios.js for React native apps on iOS
For example, here’s the dependencies section of a native Android
package.json
file:
This path points to the current release branch of the
SalesforceMobileSDK-Android repo.
1"dependencies": {
2 "salesforcemobilesdk-android": "https://github.com/forcedotcom/SalesforceMobileSDK-Android.git"
3}For iOS, it’s the same
idea:
For
React native, you can set targets for both iOS and Android, as well as React native
versions:
1"dependencies": {
2 "salesforcemobilesdk-ios": "https://github.com/forcedotcom/SalesforceMobileSDK-iOS.git"
3}1"sdkDependencies": {
2 "SalesforceMobileSDK-Android": "https://github.com/forcedotcom/SalesforceMobileSDK-Android.git",
3 "SalesforceMobileSDK-iOS": "https://github.com/forcedotcom/SalesforceMobileSDK-iOS.git"
4},
5"dependencies": {
6 "@react-native-community/masked-view": "^0.1.10",
7 "@react-navigation/native": "^6.0.2",
8 "@react-navigation/stack": "^6.0.7",
9 "react": "17.0.2",
10 "react-native-force": "git+https://github.com/forcedotcom/SalesforceMobileSDK-ReactNative.git",
11 "react-native": "0.65.1",
12 "react-native-gesture-handler": "^1.10.3",
13 "react-native-safe-area-context": "^3.3.0",
14 "react-native-screens": "^3.6.0",
15 "create-react-class": "^15.7.0"
16},To point to the development branch of any Mobile SDK repo—that
is, the branch where the upcoming release is being developed—append “#dev” to the URL.
For example:
1"dependencies": {
2 "salesforcemobilesdk-android": "https://github.com/forcedotcom/SalesforceMobileSDK-Android.git#dev"
3 "SalesforceMobileSDK-iOS": "https://github.com/forcedotcom/SalesforceMobileSDK-iOS.git#dev"
4},
5"dependencies": {
6 "@react-native-community/masked-view": "^0.1.10",
7 "@react-navigation/native": "^6.0.2",
8 "@react-navigation/stack": "^6.0.7",
9 "react": "17.0.2",
10 "react-native-force": "git+https://github.com/forcedotcom/SalesforceMobileSDK-ReactNative.git#dev",
11 "react-native": "0.65.1",
12 ...
13}After you’ve changed the package.json file, don’t forget to run the Mobile SDK git installer script as shown in the example.
Example
To upgrade an app to a different version of Mobile SDK for iOS:
- From your app directory, open package.json for editing.
- In the “sdkDependencies” section, change the value for “SalesforceMobileSDK-iOS” to point a different version of the SalesforceMobileSDK-iOS repo. You can point to the development branch or a different tag of the master branch (5.x or later).
- From the repo root directory, run the appropriate installer script for your app:
- For native apps: install.js
- For React Native apps: installios.js
The steps for Android are identical except for the iOS labels:
- From your app directory, open package.json for editing.
- In the “sdkDependencies” section, change the value for “SalesforceMobileSDK-Android” to point a different version of the SalesforceMobileSDK-Android repo. You can point to the development branch or a different tag of the master branch (5.x or later).
- From the repo root directory, run the appropriate installer script for your app:
- For native apps: install.js
- For React Native apps: installandroid.js
Updating Hybrid Apps
For hybrid apps, Mobile SDK libraries are delivered through the Mobile SDK Cordova plug-in. However, with a major release, we recommend that you start with a new template app.
- Run: forcehybrid create
- Create the same type of hybrid project with the same name as your existing project, but in a different folder.
- When the script finishes, cd to your new project folder.
- Add any third-party Cordova plug-ins that your original app used. For example, if your app
uses the Cordova status bar plug-in,
type:
1cordova plugin add cordova-plugin-statusbar - Copy your web app resources—JavaScript, HTML5, and CSS files, and so on—from
the original project into your new project’s www/ folder. For example, on
Mac OS
X:
1cp -RL ~/MyProjects/MyMobileSDK50Project/www/* www/ - Run: cordova prepare