0.2.0
General
RuStore In-app updates SDK supports the current version of the application on the user's device. This helps the user see updates, evaluate performance improvements and the result of bug fixes.
User scenario example
Use RuStore In-app updates SDK to implement various update methods. Currently supported: delayed, silent (without UI from RuStore) and forced update.
Explore example code on Unity >>
Prerequisites
For the RuStore In-app updates SDK to work, the following conditions must be met.
- App uploaded to RuStore Console.
- App passed moderation (you don't have to publish the app).
- Test build signature (for example:
debug) of the app must match the signature of the app build that was uploaded to the console and passed moderation (for example,release).
- Android 8.0 or later.
- RuStore app version on the device is up-to-date.
- User is authorized in RuStore.
- RuStore app is allowed to install applications.
Connecting to the project
To connect, download RuStore AppUpdate SDK and import it into the project (Assets > Import Package > Custom Package). Dependencies are included automatically using the External Dependency Manager (included in the SDK).
Minimum API level must be set to at least 24. Application minification (ProGuard/R8) is not currently supported and must be disabled in the project settings (File > Build Settings > Player Settings > Publishing Settings > Minify).
Create update manager
Before calling library methods, you must create an update manager.
RuStoreAppUpdateManager.Instance.Init();
Check for updates
Before requesting an update, check to see if an update is available for your application. To check for updates, call the methodgetAppUpdateInfo(). When calling this method, the following conditions are checked.
- The current version of RuStore is installed on the user's device.
- The user and the app are not banned in RuStore.
- RuStore app is allowed to install applications.
- User is authorized in RuStore.
AppUpdateInfo object, which will contain information about the need for an update. Request this object in advance and cache it to prompt the user to start downloading the update without delay and at the user's convenience.
RuStoreAppUpdateManager.Instance.GetAppUpdateInfo(
onFailure: (error) => {
// Handling error
},
onSuccess: (info) => {
// Process update info
}
);
AppUpdateInfo contains a set of parameters necessary to determine whether an update is available.
-
updateAvailability— update availability:UNKNOWN (int == 0)— by default;UPDATE_NOT_AVAILABLE (int == 1)— no update needed;UPDATE_AVAILABLE (int == 2)— an update is required to be downloaded or an update has already been downloaded to the user's device;DEVELOPER_TRIGGERED_UPDATE_IN_PROGRESS (int == 3)— the update is already downloading or installation has already started.
-
installStatus— update installation status if the user is already installing the update at the current time:UNKNOWN (int == 0)— by default;DOWNLOADED (int == 1)— downloaded;DOWNLOADING (int == 2)— downloading;FAILED (int == 3)— error;PENDING (int == 5)— in anticipation.
-
availableVersionCode— update version code.
An update download can only be started if the updateAvailability field contains the valueUPDATE_AVAILABLE.
Download and install updates
Using listener
After confirming the availability of the update (AppUpdateInfo), you can request the update download status - to do this, run the update download status listener.
Check update status
Use the methodRegisterListener().
RuStoreAppUpdateManager.Instance.RegisterListener(listener);
listener — an object of a class implementing an interface IInstallStateUpdateListener:
public interface InstallStateUpdateListener {
public void OnStateUpdated(InstallState state);
}
The state object describes the current download status. Below is the contents of the object.
-
installStatus— update installation status if the user is already installing the update at the current time:UNKNOWN (int == 0)— by default;DOWNLOADED (int == 1)— downloaded;DOWNLOADING (int == 2)— downloading;FAILED (int == 3)— error;PENDING (int == 5)— in anticipation;
The update SDK does not have a special status for the situation when the user has canceled the update download. If the user aborted the update during the download phase, installStatus returns the original status UNKNOWN (0) with a Download button.
If the user has already downloaded the update, but canceled the installation, then installStatus will return the value DOWNLOADED (1).
Let's consider the following options.
- The user started downloading the update, but canceled the download - in this case:
updateAvailability-UPDATE_AVAILABLE(2);installStatus-UNKNOWN(0).
- The user downloaded the update file, but did not install it - in this case:
updateAvailability-UPDATE_AVAILABLE(2);installStatus-DOWNLOADED(1).
bytesDownloaded— number of bytes downloaded;totalBytesToDownload— the total number of bytes to download;installErrorCode— error code during download. Error codes are described in the section Error handling.
Delete listener
If the listener is no longer needed, use the unregisterListener() method to remove the listener, passing the previously registered listener to the method.
RuStoreAppUpdateManager.Instance.UnregisterListener(listener);
Start downloading update
Delayed update
Description of deferred update scenario
Update with UI from RuStore
- The user will be shown a dialog with the RuStore UI to confirm the update.
- When you click the Update button, a dialog box will appear to confirm the installation of the update.
- Once the installation is complete, the application will close.
Run update script
To start downloading an application update, call the StartUpdateFlow() method.
The AppUpdateInfo object becomes invalid after a single use. To call the StartUpdateFlow() method again, request AppUpdateInfo using the GetAppUpdateInfo() method again.
RuStoreAppUpdateManager.Instance.StartUpdateFlow(
onFailure: (error) => {
// Handling error
},
onSuccess: (resultCode) => {
// Handle flow result
}
);
If the user confirmed downloading the update, then resultCode = UpdateFlowResult.RESULT_OK, if he refused, then resultCode = UpdateFlowResult.RESULT_CANCELED.
After receiving the InstallStatus.DOWNLOADED status, you can call the update installation method CompleteUpdate().
It is recommended to notify the user that the update is ready for installation.
The method may return an error.
Update installation
Once the update APK download is complete, you can start installing the update. To start installing the update, call the CompleteUpdate() method.
RuStoreAppUpdateManager.Instance.CompleteUpdate(
onFailure: (error) => {
// Handling error
}
);
The update occurs through the native Android tool. If the update is successful, the application will close.
Errors processing
It is not recommended to display the error to the user yourself if you get onFailure in response. It can negatively affect the user experience.
The error structure is shown below.
public class RuStoreError {
public string name;
public string description;
}
Possible errors
RuStoreNotInstalledException— RuStore is not installed on the user's device;RuStoreOutdatedException— RuStore version installed on the user's device does not support this SDK;RuStoreUserUnauthorizedException— user is not authorized in RuStore;RuStoreException— basic RuStore error from which other errors are inherited;RuStoreInstallException(public val code: Int)— download and installation error.ERROR_UNKNOWN(Int = 4001)— unknown error.ERROR_DOWNLOAD(Int = 4002)— error while downloading.ERROR_BLOCKED(Int = 4003)— installation blocked by system.ERROR_INVALID_APK(Int = 4004)— invalid update APK.ERROR_CONFLICT(Int = 4005)— conflict with the current app version.ERROR_STORAGE(Int = 4006)— insufficient device storage.ERROR_INCOMPATIBLE(Int = 4007)— incompatible with device.ERROR_APP_NOT_OWNED(Int = 4008)— application not purchased.ERROR_INTERNAL_ERROR(Int = 4009)— internal error.ERROR_ABORTED(Int = 4010)— user refused to install the update.ERROR_APK_NOT_FOUND(Int = 4011)— APK for installation not found.ERROR_EXTERNAL_SOURCE_DENIED(Int = 4012)— update prohibited. For example, the first method responses that an update is not available, but the user calls the second method.ERROR_ACTIVITY_SEND_INTENT(Int = 9901)— error while sending intent for opening an activity.ERROR_ACTIVITY_UNKNOWN(Int = 9902)— unknown error on activity opening.
List of dependencies for app update
ru.rustore.sdk:core:0.1.10— GNU Lesser General Public License v3.0;ru.rustore.sdk:analytics:0.1.5— GNU Lesser General Public License v3.0;org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.7.20— The Apache Software License, Version 2.0;org.jetbrains.kotlinx:kotlinx-coroutines-android:1.6.4— The Apache Software License, Version 2.0;androidx.core:core-ktx:1.9.0— The Apache Software License, Version 2.0;androidx.appcompat:appcompat:1.5.1— The Apache Software License, Version 2.0;androidx.activity:activity:1.5.1— The Apache Software License, Version 2.0.