azhon / AppUpdate

Android App update library. Android版本更新库,简单、轻量、可随意定制
Apache License 2.0
2.32k stars 337 forks source link

报错:java.lang.RuntimeException #44

Closed c4jeff closed 5 years ago

c4jeff commented 5 years ago

错误日志: java.lang.RuntimeException:Unable to start service com.azhon.appupdate.service.DownloadService@8e37359 with Intent { hwFlg=0x100 cmp=com.xx.xx/com.azhon.appupdate.service.DownloadService }: java.lang.RuntimeException: 请先调用 getInstance(Context context) !

未在依赖库外调用getInstance()方法

azhon commented 5 years ago

这是怎么出现的?DownloadManager 没有初始化

c4jeff commented 5 years ago

异常设备:

  1. 三星 SM-N9208 - 可用存储空间 | 3.15 GB ( 12.66% ) - 可用内存大小 | 1.56 GB ROM详情 | samsung/dream2ltexx/dream2lte:7.0/NRD90M/G955FXXU1AQL5:user/release-keys/fail
  2. 华为 ALP L29 - 可用存储空间 | 19.69 GB ( 37.96% ) - 可用内存大小 | 1.21 GB ( 33.65% ) ROM详情 | HuaWei/EMOTION/EmotionUI_9.0.0

    这是我的调用方法:

    
    if (bean == null) return;
    int code = bean.getVersionNumber();

if (code <= AppUtils.getAppVersionCode()) { if (showNewerToast) ToastUtils.showLong(BaseApp.get().getResources().getString(R.string.latest_version)); return; }

String name = bean.getVersion(); String desc = bean.getUpdateContext(); int is_force = bean.getForce(); String downloadUrl = bean.getAndroidDownloadUrl();

AlertDialog.Builder builder = new AlertDialog.Builder(context, R.style.AutoSize_AlertDialog) .setTitle(BaseApp.get().getResources().getString(R.string.new_version)) .setMessage(desc) .setCancelable(false) .setPositiveButton(BaseApp.get().getResources().getString(R.string.updatenow), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { try { DownloadManager.getInstance().release(); } catch (Exception e) { e.printStackTrace(); } DownloadManager manager = DownloadManager.getInstance(context); manager.setApkName(name + ".apk") .setApkUrl(downloadUrl.startsWith("http") ? downloadUrl : BaseApp.get().getResources().getString(R.string.baseUrl) + downloadUrl) .setDownloadPath(AppConfig.FILE_PATH) .setSmallIcon(R.mipmap.ic_launcher) .setConfiguration(new UpdateConfiguration().setOnDownloadListener(new OnDownloadListener() { @Override public void start() { ToastUtils.showLong(BaseApp.get().getResources().getString(R.string.download_start)); }

                        @Override
                        public void downloading(int max, int progress) {
                        }

                        @Override
                        public void done(File apk) {
                            ToastUtils.showLong(BaseApp.get().getResources().getString(R.string.download_completed));
                        }

                        @Override
                        public void cancel() {
                            ToastUtils.showLong(BaseApp.get().getResources().getString(R.string.download_cancel));
                        }

                        @Override
                        public void error(Exception e) {
                            ApiException exception = ExceptionManager.handleException(e);
                            String error = exception.toString();
                            ToastUtils.showLong(BaseApp.get().getResources().getString(R.string.download_error) + error);
                        }
                    }))
                    .setAuthorities(AppUtils.getAppPackageName() + ".fileProvider")//必须与Manifest中的provider的authorities一致
                    .download();
        }
    });

if (is_force != 1) { builder.setNegativeButton(BaseApp.get().getResources().getString(R.string.update_cancel), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { try { DownloadManager.getInstance().release(); dialog.cancel(); } catch (Exception e) { e.printStackTrace(); } } }); } builder.create().show();

azhon commented 5 years ago

这样调用没错啊,你这个bug是必现的吗?

c4jeff commented 5 years ago

偶现的 ,我这边定位不到异常点... 三星那款设备好像是模拟器多开出来的

azhon commented 5 years ago

那就奇怪了

------------------ 原始邮件 ------------------ 发件人: "Jeff Lin"notifications@github.com; 发送时间: 2019年7月11日(星期四) 下午4:14 收件人: "azhon/AppUpdate"AppUpdate@noreply.github.com; 抄送: "阿钟"958460248@qq.com; "Comment"comment@noreply.github.com; 主题: Re: [azhon/AppUpdate] 报错:java.lang.RuntimeException (#44)

偶现的 ,我这边定位不到异常点... 三星那款设备好像是模拟器多开出来的

— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or mute the thread.

ichapter commented 5 years ago

小米8 也出现这问题

java.lang.RuntimeException:Unable to start service com.azhon.appupdate.service.DownloadService@83cd133 with Intent { cmp=com.mdd.platform/com.azhon.appupdate.service.DownloadService }: java.lang.RuntimeException: 请先调用 getInstance(Context context) !

2 android.app.ActivityThread.handleServiceArgs(ActivityThread.java:3529) 3 ...... 4 Caused by: 5 java.lang.RuntimeException:请先调用 getInstance(Context context) ! 6 com.azhon.appupdate.manager.DownloadManager.a(TbsSdkJava:113) 7 com.azhon.appupdate.service.DownloadService.init(TbsSdkJava:66) 8 com.azhon.appupdate.service.DownloadService.onStartCommand(TbsSdkJava:60) 9 android.app.ActivityThread.handleServiceArgs(ActivityThread.java:3509) 10 android.app.ActivityThread.-wrap20(Unknown Source:0) 11 android.app.ActivityThread$H.handleMessage(ActivityThread.java:1717) 12 android.os.Handler.dispatchMessage(Handler.java:106) 13 android.os.Looper.loop(Looper.java:164) 14 android.app.ActivityThread.main(ActivityThread.java:6648) 15 java.lang.reflect.Method.invoke(Native Method) 16 com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:547) 17 com.android.internal.os.ZygoteInit.main(ZygoteInit.java:818)

azhon commented 5 years ago

正常使用的情况吗。还是怎么操作的?