-
-
Notifications
You must be signed in to change notification settings - Fork 411
如何引用
xuexiangjys edited this page Sep 8, 2019
·
30 revisions
1.先在项目根目录的 build.gradle 的 repositories 添加:
allprojects {
repositories {
...
maven { url "https://jitpack.io" }
}
}
2.然后在dependencies添加:
dependencies {
...
implementation 'com.github.xuexiangjys:XUpdate:1.1.1'
}
3.在Application进行初始化配置:
【注意】这里需要注意的是,IUpdateHttpService
必须设置,否则框架将无法正常使用!IUpdateHttpService
的实现可参照Demo中的实现
XUpdate.get()
.debug(true)
.isWifiOnly(true) //默认设置只在wifi下检查版本更新
.isGet(true) //默认设置使用get请求检查版本
.isAutoMode(false) //默认设置非自动模式,可根据具体使用配置
.param("versionCode", UpdateUtils.getVersionCode(this)) //设置默认公共请求参数
.param("appKey", getPackageName())
.setOnUpdateFailureListener(new OnUpdateFailureListener() { //设置版本更新出错的监听
@Override
public void onFailure(UpdateError error) {
if (error.getCode() != CHECK_NO_NEW_VERSION) { //对不同错误进行处理
ToastUtils.toast(error.toString());
}
}
})
.supportSilentInstall(true) //设置是否支持静默安装,默认是true
.setIUpdateHttpService(new OKHttpUpdateHttpService()) //这个必须设置!实现网络请求功能。
.init(this);
【注意】:如果出现任何问题,可开启debug模式来追踪问题。如果你还需要将日志记录在磁盘上,可实现以下接口
XUpdate.get().setILogger(new ILogger() {
@Override
public void log(int priority, String tag, String message, Throwable t) {
//实现日志记录功能
}
});
-keep class com.xuexiang.xupdate.entity.** { *; }