Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Example Analysis of Android connected to Hot repair

2025-04-03 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

Android is connected to the example analysis of hot fix. In view of this problem, this article introduces the corresponding analysis and solution in detail, hoping to help more partners who want to solve this problem to find a more simple and feasible method.

Add permissions to 1.AndroidManinifest.xml

Add the following to application in 2.AndroidManinifest.xml and open the file downloaded in step 5 in AS

App ID: "hotfix.idSecret"

App Secret: "emas.appSecret"

RSA key: "hotfix.rsaSecret"

3. Add dependencies to the build.gradle of app

Plugins {id 'com.android.application'} / / load the file apply plugin:' com.aliyun.ams.emas-services'android {compileSdkVersion 30 buildToolsVersion '30.0.3' defaultConfig {applicationId "com.wb.hotfixdemo" minSdkVersion 16 targetSdkVersion 30 versionCode 1 versionName "1.0" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"} buildTypes {release { MinifyEnabled false proguardFiles getDefaultProguardFile ('proguard-android-optimize.txt') 'proguard-rules.pro'} debug {minifyEnabled false proguardFiles getDefaultProguardFile (' proguard-android-optimize.txt') 'proguard-rules.pro'}} compileOptions {sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8}} dependencies {implementation' androidx.appcompat:appcompat:1.1.0' implementation 'com.google.android.material:material:1.1.0' implementation' androidx.constraintlayout:constraintlayout:1.1.3' testImplementation 'junit:junit:4.+' androidTestImplementation' androidx.test .ext: junit:1.1.1' androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0' / / Aliyun depends on api' com.aliyun.ams:alicloud-android-hotfix:3.3.0'}

4 、 SophixStubApplication

Now that the integration is complete, here is the implementation of the code. Create a new class SophixStubApplication inheriting SophixApplication

Public class SophixStubApplication extends SophixApplication {private final String TAG = "SophixStubApplication"; / / here the SophixEntry should specify the real Application and make sure that the RealApplicationStub class name is not confused. @ Keep @ SophixEntry (MyRealApplication.class) static class RealApplicationStub {} @ Override public void onCreate () {super.onCreate (); SophixManager.getInstance () .queryAndLoadNewPatch ();} @ Override protected void attachBaseContext (Context base) {super.attachBaseContext (base); / / if you need to use MultiDex, you need to call it here. / / MultiDex.install (this); initSophix ();} private void initSophix () {String appVersion = "0.0.0"; try {appVersion = this.getPackageManager () .getPackageInfo (this.getPackageName (), 0) .versionName;} catch (Exception e) {} final SophixManager instance = SophixManager.getInstance () Instance.setContext (this) .setAppVersion (appVersion) .setEnableDebug (true) .setEnableDebug (true) .setEnableFullLog () .setPatchLoadStatusStub (new PatchLoadStatusListener () {@ Override public void onLoad (final int mode, final int code, final String info) Final int handlePatchVersion) {if (code = = PatchStatus.CODE_LOAD_SUCCESS) {Log.i (TAG, "sophix load patch success!") } else if (code = = PatchStatus.CODE_LOAD_RELAUNCH) {/ / if you need to restart in the background, it is recommended to use SharePreference to save the state here. Log.i (TAG, "sophix preload patch success. Restart app to make effect.");}. Initialize ();}}

5 、 MyRealApplication

Public class MyRealApplication extends Application {}

6. Add SophixStubApplication to AndroidManinifest.xml

This is the answer to the sample analysis question about Android access hotfix. I hope the above content can be of some help to you. If you still have a lot of doubts to be solved, you can follow the industry information channel for more related knowledge.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report