Android接入阿里云熱修復介紹
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
目前集成已經(jīng)完畢了,下面就是代碼的實現(xiàn),新建一個類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保存狀態(tài)。 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">
到這已經(jīng)完成阿里云熱修復的百分之八十,后面就是下載工具實現(xiàn)發(fā)布補丁
到此這篇關于Android接入阿里云熱修復介紹的文章就介紹到這了,更多相關Android阿里云熱修復內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!
相關文章
Kotlin開發(fā)實戰(zhàn)之hello world
這篇文章主要為大家詳細介紹了Kotlin開發(fā)實戰(zhàn)之hello world的相關資料,具有一定的參考價值,感興趣的小伙伴們可以參考一下2017-05-05Android 中menu同時顯示圖標和文字的實現(xiàn)
這篇文章主要介紹了Android 中menu同時顯示圖標和文字的實現(xiàn)的相關資料,希望通過本文能幫助到大家實現(xiàn)這樣的功能,需要的朋友可以參考下2017-10-10Android Path繪制貝塞爾曲線實現(xiàn)QQ拖拽泡泡
本文主要介紹Android Path繪制貝塞爾曲線,這里整理相關資料并運用貝塞爾曲線實現(xiàn)QQ拖拽泡泡的示例,有興趣的小伙伴可以參考下2016-09-09Android開發(fā)使用HttpURLConnection進行網(wǎng)絡編程詳解【附源碼下載】
這篇文章主要介紹了Android開發(fā)使用HttpURLConnection進行網(wǎng)絡編程的方法,結合實例形式分析了Android基于HttpURLConnection實現(xiàn)顯示圖片與文本功能,涉及Android布局、文本解析、數(shù)據(jù)傳輸、權限控制等相關操作技巧,需要的朋友可以參考下2018-01-01