当前位置:首页 > 谈天说地

Android接入阿里云热修复介绍

34资源网2022-01-27594

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阿里云热修复内容请搜索萬仟网以前的文章或继续浏览下面的相关文章希望大家以后多多支持萬仟网!

看完文章,还可以扫描下面的二维码下载快手极速版领4元红包

快手极速版二维码

快手极速版新人见面礼

除了扫码领红包之外,大家还可以在快手极速版做签到,看视频,做任务,参与抽奖,邀请好友赚钱)。

邀请两个好友奖最高196元,如下图所示:

快手极速版邀请好友奖励

扫描二维码推送至手机访问。

版权声明:本文由34楼发布,如需转载请注明出处。

本文链接:https://www.34l.com/post/6527.html

分享给朋友:

相关文章

50句非常励志的短句,正能量的励志句子

50句非常励志的短句,正能量的励志句子

1、人非要经历一番不同平时的劫难才能脱胎换骨,成为真正能解决问题的人。…

带货直播运营怎么做(直播公司盈利模式)

带货直播运营怎么做(直播公司盈利模式)

直播网红千千万,谁能争当NO.1?随着直播崛起,越来越多的人想要入场分一杯羹,BUT,80%的人都不懂直播运营的内容法则。那么,新手主播怎么玩才能快速脱颖而出呢?掌握这四大直播运营的内容规则,人气轻松翻倍!1. 直播内容多样化…

裁员,爱奇艺穿越生死线

裁员,爱奇艺穿越生死线

图源:摄图网 编者按:本文来自微信公众号霞光社(ID:Globalinsights)),作者:麻吉、郭照川、韩夏,创业邦经授权转载 霞光社从多位爱奇艺员工处了解到,本轮裁员罕见覆盖了爱奇艺所有部门,从影业、IP、游戏、电商部门,甚至到经纪公…

扫地机器人市场的2021:后浪翻涌,前浪头疼

扫地机器人市场的2021:后浪翻涌,前浪头疼

编者按:本文来自锋见,创业邦经授权发布。 转眼2021年已接近尾声,2022年即将来临。回顾过去这一年,注定是不平凡的一年,特别是对于扫地机器人行业来说,2021年发生了不少大事,对行业影响深远。今天我们就来盘点和点评一下。 科技改变生活,…

一场关于元宇宙公司之死的剧本杀

一场关于元宇宙公司之死的剧本杀

编者按:本文来自脑极体,创业邦经授权发布。 2021年,被称作元宇宙元年。这种结合了区块链、虚拟现实、增强现实多种技术的概念,据称能够提供社交、娱乐、电商多种功能。美国彭博社称,元宇宙的市场规模将在2024年将达到8000亿美元。而就在20…