This topic describes how to add the upgrade SDK related to the release management function. After adding the SDK and complete the necessary configurations, you can release a new version of an App in the mPaaS console, and the client can detect the new version through the upgrade API and remind users to download and upgrade.
Currently, Upgrade SDK supports integration through Native AAR and Component-based method.
The process includes the following four steps:
Add SDK
Configure project
Initialize mPaaS (only for native AAR integration)
Check for upgrades
Prerequisites
For native AAR integration, first add mPaaS to your project.
For component-based integration, first complete the component-based integration process.
Add SDK
Native AAR method
In your project, use Component Management (AAR) to install the UPGRADE component. For more information, see Manage component dependencies.
Component-based method
In the Portal and Bundle projects, use Component Management to install the UPGRADE component. For more information, see Add component dependencies.
Configure project
Configure AndroidManifest
Add the following permission to the
AndroidManifest.xmlfile:<uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES" />Add the following configuration to the
AndroidManifest.xmlfile.Replace the wildcard character
${applicationId}with the actual package name. For example, replace${applicationId}.fileproviderwithcom.mpaas.mobiledeliveryservice.fileprovider.<provider android:name="android.support.v4.content.FileProvider" android:authorities="${applicationId}.fileprovider" android:exported="false" android:grantUriPermissions="true"> <meta-data android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/file_paths" /> </provider>NoteFor more information about configuring
AndroidManifest.xml, see App Manifest Overview.In the
src/main/res/xmlfolder of your Portal project's main module, create a file namedfile_paths.xmlwith the following content:<?xml version="1.0" encoding="utf-8"?> <resources> <paths> <external-files-path name="download" path="com.alipay.android.phone.aliupgrade/downloads" /> <external-path name="download_sdcard" path="ExtDataTunnel/files/com.alipay.android.phone.aliupgrade/downloads" /> </paths> </resources>NoteIf your targetSdkVersion is greater than 24, you must add a new configuration. For more information, see Default storage path.
Add resources
If you use the native AAR integration method, you must add the following resources to your application. Otherwise, the Upgrade component will not work correctly. Click here to download the resource files.
Merge the contents of the strings.xml, styles.xml, and colors.xml files with the corresponding files in the values folder.
Initialize mPaaS
If you use the native AAR integration method, you must initialize mPaaS.
Add the following code to the Application object:
public class MyApplication extends Application {
@Override
public void onCreate() {
super.onCreate();
// Initialize mPaaS
MP.init(this);
}
}For more information, see Initialize mPaaS.
Quickly check for upgrades
You can quickly check for a new version. This method only returns the check result:
MPUpgrade mMPUpgrade = new MPUpgrade();
// Synchronous method. Call it in a background thread.
int result = mMPUpgrade.fastCheckHasNewVersion();
if (result == UpgradeConstants.HAS_NEW_VERSION) {
// A new version is available.
} else if (result == UpgradeConstants.HAS_NO_NEW_VERSION) {
// No new version is available.
} else if (result == UpgradeConstants.HAS_SOME_ERROR) {
// An error occurred.
}