Consuming Mobile SDK for Android through Gradle

Late-Breaking Feature Addition! Beginning with Salesforce Mobile SDK 5.0, we’re providing native Android libraries on Bintray’s jCenter Maven repository. As a result, you can now consume any Mobile SDK library by adding a single line to the dependencies section of your app’s build.gradle file.

What’s the value of this change? Upgrade ease! To upgrade a library, you simply change its version number in your build.gradle file to the updated version, and then resync your libraries.

The Details

Here’s how you do it. A typical dependencies section looks like this:

dependencies {
classpath 'com.android.tools.build:gradle:2.2.3'
}

To import libraries, you add a Gradle compile statement in this section. A compile statement takes the form

compile 'groupID:artifactID:version'

For Mobile SDK libraries:

  • Group ID is “com.salesforce.mobilesdk”
  • Artifact ID is “SalesforceSDK”, “SmartStore”, or “SmartSync”
  • Version is currently “5.0.0”

The compile statement imports not only the specified library, but also all its dependencies. This means that you never have to explicitly compile SalesforceAnalytics, for example, because every other library depends on it. It also means that you can get everything you need with just one statement.

To import Mobile SDK 5.0.0 libraries, add one of the following lines:

  • For the SalesforceSDK library:
compile 'com.salesforce.mobilesdk:SalesforceSDK:5.0.0'
  • For the SmartStore library (also imports the SalesforceSDK library):
compile 'com.salesforce.mobilesdk:SmartStore:5.0.0'
  • For the SmartSync library (also imports the SalesforceSDK and SmartStore libraries):
compile 'com.salesforce.mobilesdk:SmartSync:5.0.0'

Note: SalesforceHybrid and SalesforceReact libraries are not currently available through Maven.

If You’re New to Salesforce Mobile SDK Development…

Mobile SDK enforces a few coding requirements for proper initialization and configuration. To get started, see https://developer.salesforce.com/docs/atlas.en-us.mobile_sdk.meta/mobile_sdk/android_application_structure.htm.

Resources

For more details on the Salesforce Mobile SDK packages on Maven, visit our repository at bintray.com/forcedotcom/salesforcemobilesdk.

Mobile SDK Development Guide http://www.salesforce.com/docs/en/mobile_sdk/

Mobile SDK Trail https://developer.salesforce.com/trailhead/trail/mobile_sdk_intro