{"action":"opened","issue":{"url":"https://api.github.com/repos/Tencent/tinker/issues/37","repository_url":"https://api.github.com/repos/Tencent/tinker","labels_url":"https://api.github.com/repos/Tencent/tinker/issues/37/labels{/name}","comments_url":"https://api.github.com/repos/Tencent/tinker/issues/37/comments","events_url":"https://api.github.com/repos/Tencent/tinker/issues/37/events","html_url":"https://github.com/Tencent/tinker/issues/37","id":179198389,"number":37,"title":"默认方式启动install","user":{"login":"liuxang","id":17467300,"avatar_url":"https://avatars.githubusercontent.com/u/17467300?v=3","gravatar_id":"","url":"https://api.github.com/users/liuxang","html_url":"https://github.com/liuxang","followers_url":"https://api.github.com/users/liuxang/followers","following_url":"https://api.github.com/users/liuxang/following{/other_user}","gists_url":"https://api.github.com/users/liuxang/gists{/gist_id}","starred_url":"https://api.github.com/users/liuxang/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/liuxang/subscriptions","organizations_url":"https://api.github.com/users/liuxang/orgs","repos_url":"https://api.github.com/users/liuxang/repos","events_url":"https://api.github.com/users/liuxang/events{/privacy}","received_events_url":"https://api.github.com/users/liuxang/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2016-09-26T11:00:42Z","updated_at":"2016-09-26T11:00:42Z","closed_at":null,"body":"如下两方法\r\n```java\r\n public static void install(ApplicationLike applicationLike) {\r\n        Tinker tinker = new Tinker.Builder(applicationLike.getApplication()).build();\r\n        tinker.install(applicationLike.getTinkerResultIntent());\r\n    }\r\npublic static void install(ApplicationLike applicationLike, LoadReporter loadReporter, PatchReporter patchReporter,\r\n                               PatchListener listener, Class<? extends AbstractResultService> resultServiceClass,\r\n                               AbstractPatch upgradePatchProcessor, AbstractPatch repairPatchProcessor) {\r\n\r\n        Tinker tinker = new Tinker.Builder(applicationLike.getApplication())\r\n            .tinkerFlags(applicationLike.getTinkerFlags())\r\n            .loadReport(loadReporter)\r\n            .listener(listener)\r\n            .patchReporter(patchReporter)\r\n            .tinkerLoadVerifyFlag(applicationLike.getTinkerLoadVerifyFlag()).build();\r\n\r\n        Tinker.create(tinker);\r\n        tinker.install(applicationLike.getTinkerResultIntent(), resultServiceClass, upgradePatchProcessor, repairPatchProcessor);\r\n    }\r\n```\r\n\r\n使用默认的install方法有问题；少了个 : **Tinker.create(tinker);**\r\n\r\n```java\r\npublic static void create(Tinker tinker) {\r\n        if (sInstance != null) {\r\n            throw new TinkerRuntimeException(\"Tinker instance is already set.\");\r\n        }\r\n        sInstance = tinker;\r\n    }\r\n```\r\n使用install(ApplicationLike applicationLike)这样会造成Tinker中 sInstance 无值\r\n那么在某些地方调用\r\n```java\r\npublic static Tinker with(Context context) {\r\n        if (!installed) {\r\n            throw new TinkerRuntimeException(\"you must install tinker before get tinker sInstance\");\r\n        }\r\n        if (sInstance == null) {\r\n            synchronized (Tinker.class) {\r\n                if (sInstance == null) {\r\n                    sInstance = new Builder(context).build();\r\n                }\r\n            }\r\n        }\r\n        return sInstance;\r\n    }\r\n```\r\n会重新创建，而这个新的对象没有调用过install方法。\r\n比如在:\r\n**UpgradePatch#tryPatch** 类中的:\r\n```java\r\n  SharePatchInfo oldInfo = manager.getTinkerLoadResultIfPresent().patchInfo;\r\n```\r\n出现空指针，因为getTinkerLoadResultIfPresent是需要调用了install方法后才存在的:\r\n```java\r\ntinkerLoadResult = new TinkerLoadResult();\r\ntinkerLoadResult.parseTinkerResult(getContext(), intentResult);\r\n```\r\n\r\n错误如下\r\n```java\r\n09-26 18:37:28.178 4464-4490/com.test:patch E/Tinker.DefaultPatchReporter: tinker patch exception  java.lang.NullPointerException: Attempt to read from field 'com.tencent.tinker.loader.shareutil.SharePatchInfo com.tencent.tinker.lib.tinker.TinkerLoadResult.patchInfo' on a null object reference\r\n                                                                               at com.tencent.tinker.lib.patch.UpgradePatch.tryPatch(UpgradePatch.java:70)\r\n                                                                               at com.tencent.tinker.lib.service.TinkerPatchService.onHandleIntent(TinkerPatchService.java:122)\r\n                                                                               at android.app.IntentService$ServiceHandler.handleMessage(IntentService.java:65)\r\n                                                                               at android.os.Handler.dispatchMessage(Handler.java:102)\r\n                                                                               at android.os.Looper.loop(Looper.java:135)\r\n                                                                               at android.os.HandlerThread.run(HandlerThread.java:61)\r\n\r\n\r\n\r\n09-26 18:37:28.226 19352-4495/com.test I/Tinker.DefaultTinkerResultService: DefaultTinkerResultService received a result:\r\nPatchResult: \r\nisUpgradePatch:true\r\nisSuccess:false\r\nrawPatchFilePath:/storage/emulated/0/patch_signed_7zip.apk\r\ncostTime:61\r\npatchVersion:null\r\npatchTinkerID:mytinkerId\r\nbaseTinkerID:mytinkerId\r\nThrowable:Attempt to read from field 'com.tencent.tinker.loader.shareutil.SharePatchInfo com.tencent.tinker.lib.tinker.TinkerLoadResult.patchInfo' on a null object reference\r\n```\r\n"}}
{"actor":{"display_login":"liuxang"}}