This topic describes how to integrate the mPaaS Hotpatch feature into your Android app.
Hotpatch supports two integration methods: native AAR and component-based.
Initialize hotpatch (Required for the native AAR integration method only)
Prerequisites
If you use the native AAR integration method, add mPaaS to your project.
If you use the component-based integration method, complete the component-based integration procedure.
Add the SDK
Native AAR integration method
Use Component Management (AAR) to install the Hotpatch (HOTFIX) component in your project. For more information, see Manage component dependencies.
Component-based integration method
In the Portal and Bundle projects, use Component Management to install the Hotpatch (HOTFIX) component. For more information, see Manage component dependencies.
Initialize hotpatch
Native AAR integration
To use the hotpatch feature, you must complete the following steps.
Your
Applicationobject must inherit fromQuinoxlessApplicationLike. Prevent this class from being obfuscated. The following example uses `MyApplication`.@Keep public class MyApplication extends QuinoxlessApplicationLike implements Application.ActivityLifecycleCallbacks { private static final String TAG = "MyApplication"; @Override protected void attachBaseContext(Context base) { super.attachBaseContext(base); Log.i(TAG, "attachBaseContext"); } @Override public void onCreate() { super.onCreate(); Log.i(TAG, "onCreate"); registerActivityLifecycleCallbacks(this); } @Override public void onMPaaSFrameworkInitFinished() { MPHotpatch.init(); LoggerFactory.getTraceLogger().info(TAG, getProcessName()); } @Override public void onActivityCreated(Activity activity, Bundle savedInstanceState) { Log.i(TAG, "onActivityCreated"); } @Override public void onActivityStarted(Activity activity) { } @Override public void onActivityResumed(Activity activity) { } @Override public void onActivityPaused(Activity activity) { } @Override public void onActivityStopped(Activity activity) { } @Override public void onActivitySaveInstanceState(Activity activity, Bundle outState) { } @Override public void onActivityDestroyed(Activity activity) { } }In the
AndroidManifest.xmlfile, set theApplicationobject to the one provided by mPaaS. Add theMyApplicationclass that you created to themeta-datatag that has the keympaas.quinoxless.extern.application. The following code shows an example:<application android:name="com.alipay.mobile.framework.quinoxless.QuinoxlessApplication" > <meta-data android:name="mpaas.quinoxless.extern.application" android:value="com.mpaas.demo.MyApplication" /> </application>com.mpaas.demo.MyApplicationis your custom application agent class that inherits fromQuinoxlessApplicationLike.
Component-based integration
No changes are needed for this integration method because the required content is already integrated.
Generate a hotpatch
For more information, see Generate a hotpatch package.
Publish the hotpatch
For more information, see Release a hotpatch package.
Trigger the hotpatch
This section uses the Hotpatch example in the code sample to describe the hotpatch procedure.
In this code sample, the content to be fixed is the text in a Toast message.
Before you apply the fix, click the Impersonate the click event to be hotpatched button. A Toast message appears.
To apply the fix, click the Trigger hotpatch deployment detection button to trigger the hotpatch download. After the download is complete, restart the demo application.
After the fix is applied, click the Impersonate the click event to be hotpatched button. A Toast message appears with the text 'The current click event has been hotpatched'.
Troubleshooting
Do not import `apache-httpclient` or `apache-commons` through unofficial methods. For more information, see the official documentation on the Android developer platform.
Do not import SDKs related to the NFC system through unofficial methods.
Make sure that you do not inherit from any `Application`-related classes. Use `ApplicationLike` instead.
To view hotpatch logs, filter by the tag `DynamicRelease`.
Download phase: Filter by `RPCException`. If an `RPCException` occurs, the download has failed.
NoteIf an RPC-related exception occurs, troubleshoot it based on the error code. For more information, see RPC calls.
Patch merging phase: Filter by
immediately=true. A log entry that matches this filter indicates that the patch was successfully merged. After the patch is merged, you must restart the app for the patch to take effect.