網站首頁 編程語言 正文
1.AndroidManinifest.xml中加入權限
<uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /> <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
2.AndroidManinifest.xml里application
中加入以下,在AS中打開在第五步下載的文件
App ID:"hotfix.idSecret"
App Secret:"emas.appSecret"
RSA密鑰:"hotfix.rsaSecret"
<meta-data android:name="com.taobao.android.hotfix.IDSECRET" android:value="App ID" /> <meta-data android:name="com.taobao.android.hotfix.APPSECRET" android:value="App Secret" /> <meta-data android:name="com.taobao.android.hotfix.RSASECRET" android:value="RSA密鑰" />
3、在app的build.gradle中加入依賴等
plugins { id 'com.android.application'} //加載文件 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' //阿里云依賴 api 'com.aliyun.ams:alicloud-android-hotfix:3.3.0' }
4、SophixStubApplication
目前集成已經完畢了,下面就是代碼的實現,新建一個類SophixStubApplication
繼承SophixApplication
public class SophixStubApplication extends SophixApplication { private final String TAG = "SophixStubApplication"; // 此處SophixEntry應指定真正的Application,并且保證RealApplicationStub類名不被混淆。 @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); // 如果需要使用MultiDex,需要在此處調用。 // 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) .setSecretMetaData(null, null, null) .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) { // 如果需要在后臺重啟,建議此處用SharePreference保存狀態。 Log.i(TAG, "sophix preload patch success. restart app to make effect."); } } }).initialize(); } }
5、MyRealApplication
public class MyRealApplication extends Application { }
6、AndroidManinifest.xml里加入SophixStubApplication
<application android:name=".SophixStubApplication" //加入此項 android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" android:theme="@style/Theme.HotFixDemo">
到這已經完成阿里云熱修復的百分之八十,后面就是下載工具實現發布補丁
原文鏈接:https://blog.csdn.net/qq_46290634/article/details/122682912
相關推薦
- 2022-03-28 python將天數轉換為日期字符串的方法實例_python
- 2022-02-03 ionic錨點操作
- 2023-10-25 更簡單的方法實現el-calendar日歷組件中點擊上個月、今天、下個月按鈕時的點擊事件
- 2022-08-29 Linux安裝Docker詳細教程_docker
- 2023-10-11 在MyBatisPlus中添加分頁插件
- 2022-05-19 golang?中?channel?的詳細使用、使用注意事項及死鎖問題解析_Golang
- 2023-03-23 Python?eval()與exec()函數使用介紹_python
- 2024-03-17 WSL子系統啟動報錯 Wsl/Service/CreateInstance/CreateVm/HCS
- 最近更新
-
- window11 系統安裝 yarn
- 超詳細win安裝深度學習環境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權
- redisson分布式鎖中waittime的設
- maven:解決release錯誤:Artif
- restTemplate使用總結
- Spring Security之安全異常處理
- MybatisPlus優雅實現加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務發現-Nac
- Spring Security之基于HttpR
- Redis 底層數據結構-簡單動態字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應用詳解
- 聊聊消息隊列,發送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支