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">
到这已经完成阿里云热修复的百分之八十,后面就是下载工具实现发布补丁
到此这篇关于android接入阿里云热修复介绍的文章就介绍到这了,更多相关android阿里云热修复内容请搜索www.887551.com以前的文章或继续浏览下面的相关文章希望大家以后多多支持www.887551.com!