初步写个项目
1. 进入阿里云网站,进入移动热修复(也可直接从百度上搜索移动热修复)
然后进入「管理控制台」
2. 在管理控制台中创建应用
下面hotfixdemo是我建立的应用(应该是先建立产品, 然后建立APP热修复项目)
3.通过点击上图的管理进入
其中
AppId
AppSeceret
RSA密钥
都是需要添加到AndroidManifest.xml文件中的application中的
4. 然后就是添加补丁版本
版本号就是跟着APP的版本号, 一个版本号可以有好多个补丁。
5. 测试步骤
「二维码扫描测试」---「灰度测试」-->「全面发布」
6. Android Studio 中引入gradle即可
maven {
url "http://maven.aliyun.com/nexus/content/repositories/releases"
}
compile 'com.aliyun.ams:alicloud-android-hotfix:3.1.5'
7. Application中
@Override
public void onCreate() {
super.onCreate();
initSophix();
}
private void initSophix() {
String appVersion = "0.0.0";
try {
appVersion = this.getPackageManager()
.getPackageInfo(this.getPackageName(), 0)
.versionName;
} catch (Exception e) {
}
// initialize最好放在attachBaseContext最前面,初始化直接在Application类里面,切勿封装到其他类
SophixManager.getInstance().setContext(this)
.setAppVersion(appVersion)
.setAesKey(null)
.setEnableDebug(true)
.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, "CODE_LOAD_SUCCESS");
// 表明补丁加载成功
} else if (code == PatchStatus.CODE_LOAD_RELAUNCH) {
Log.i(TAG, "CODE_LOAD_RELAUNCH");
// 表明新补丁生效需要重启. 开发者可提示用户或者强制重启;
// 建议: 用户可以监听进入后台事件, 然后调用killProcessSafely自杀,以此加快应用补丁,详见1.3.2.3
} else {
Log.i(TAG, "OTHERS info = " + info + " , mode = " + mode + " , code = " + code + " , handlePatchVersion = " + handlePatchVersion);
// 其它错误信息, 查看PatchStatus类说明
}
Log.i(TAG, " info = " + info + " , mode = " + mode + " , code = " + code + " , handlePatchVersion = " + handlePatchVersion);
}
}).initialize();
// queryAndLoadNewPatch不可放在attachBaseContext 中,否则无网络权限,建议放在后面任意时刻,如onCreate中
SophixManager.getInstance().queryAndLoadNewPatch();
}
8. 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" />
<application
android:name=".HotfixApplication"
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/AppTheme">
<meta-data
android:name="com.taobao.android.hotfix.IDSECRET"
android:value="24673031-1" />
<meta-data
android:name="com.taobao.android.hotfix.APPSECRET"
android:value="616eeb3974cbefcf08c48ee589b2e6d2" />
<meta-data
android:name="com.taobao.android.hotfix.RSASECRET"
android:value="MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQCVzcn+MFQsc4DGP2XMDTttAb2jU8I0kBjjzZK8MsFbHHwycp9lnLkOpNM7sDTniAtUWbvgmO6P6QDNFtQ/I44qaBjccoLnsu/jip8EAyWi49Cw4mUk5MpzTkd8sD0OnkUdN9SufOtGxwCBCUuM4JI6BqrfUlSU2LAG2LBfSyCPDYux0yhQXYcU4IsNQHLjXXwoS1DFq277uxJncl4FK1I+BGeOeZzD+Vvs8f1Pg5BEc4jRazbSnqK+Qg0OcMCE8jAqDnJNzs78WZ2rkvgc0IBEhwYwtXBvZdK9iIlt86PviymDJbRNMylL6iwUOPHERkJb/xOqtx94zhLkOVLpEd2LAgMBAAECggEABzYv+jezZaxtz51vtiIQ8U97JKi8mbEyMY1M+hhrbIpzhC42dDrWQdk3fhEeiuLmwLnNLKPQIEd0TWtC7oM0rd/zCnHM0YCwwcCDpTrNjgjvnARaICuPf3uOP3dwiQqfgyeT6o6C+RZNdOjQpUiOYZK+mR+qiLvhxYKbAwt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<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
- 并且需要动态运行时权限
AndPermission.with(MainActivity.this)
.requestCode(100)
.permission(
Manifest.permission.READ_EXTERNAL_STORAGE,
Manifest.permission.WRITE_EXTERNAL_STORAGE
)
.callback(new PermissionListener() {
@Override
public void onSucceed(int requestCode, @NonNull List<String> grantPermissions) {
}
@Override
public void onFailed(int requestCode, @NonNull List<String> deniedPermissions) {
}
})
.rationale(new RationaleListener() {
@Override
public void showRequestPermissionRationale(int requestCode, Rationale rationale) {
}
})
.start();
这也即可完成补丁.