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

Android接入阿里云热修复介绍

34资源网2022-01-27673

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

版权声明:34楼发布

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

分享给朋友:

相关文章

下午出去相了个亲,女方真心挺好看的

下午出去相了个亲,女方真心挺好看的

今天和往常有点不一样,因为今天我出去相亲了,说实话,相亲对我来说,还是挺害怕的,毕竟自己以前相亲每次都碰壁了,而且基本都是女方看不上我。纠结,可能颜值不好看吧,这也没辙,谁叫我长得难看呢。…

30条关于追逐梦想的励志语录分享

30条关于追逐梦想的励志语录分享

1、天行健,君子以自強不息,地勢坤,君子以厚德载物。…

络绎不绝怎么造句?教你用络绎不绝造句

络绎不绝怎么造句?教你用络绎不绝造句

很多人不知道络绎不绝怎么造句?其实用络绎不绝造句有很多的,下面小编整理了29句用络绎不绝造句的句子,希望对大家有借鉴的作用。…

飞行汽车是一种应用层创新

飞行汽车是一种应用层创新

编者按:本文来自A轮财经,创业邦经授权发布。 作者|WX 今天在全球范围内,飞行汽车得到了越来越多的关注。 据摩根士丹利研报预计,2030年飞行汽车行业将形成3000亿美元的市场规模。2040年,该行业规模可能将达到1.5万亿美元。 作为新…

win7开始菜单设置在哪里(win7开始菜单变成经典模式)

win7开始菜单设置在哪里(win7开始菜单变成经典模式)

我们在用win7系统的时候,发现打开了一些程序后,会在开始菜单那里显示这些最近打开的程序。有些人不想把自己最近打开的程序显示在这里,那么怎么可以删除这些程序,或者彻底让这里不会显示最近打开程序呢?下面我来教大家删除或设置不显示最近打开的程序…

ab压力测试命令(在线ddos免费测压平台)

ab压力测试命令(在线ddos免费测压平台)

ab 是apache对 http服务器进行压力测试的工具,它可以测试出服务器每秒可以处理多少请求。本文记录mac版本安装 ab 的步骤以及遇到的坑。 下载 进入 apache ab官网 下载页面。 安装 brew 安装 因为笔者的操作系统…