JsonChao/Awesome-WanAndroid

Exception

Closed this issue · 3 comments

java.lang.NoSuchMethodError: No static method startForegroundService(Landroid/content/Context;Landroid/content/Intent;)V in class Landroid/support/v4/content/ContextCompat; or its super classes (declaration of 'android.support.v4.content.ContextCompat' appears in /data/app/json.chao.com.wanandroid-1/base.apk:classes2.dex)
at com.squareup.leakcanary.internal.HeapAnalyzerService.runAnalysis(HeapAnalyzerService.java:49)
at com.squareup.leakcanary.ServiceHeapDumpListener.analyze(ServiceHeapDumpListener.java:37)
at com.squareup.leakcanary.RefWatcher.ensureGone(RefWatcher.java:156)
at com.squareup.leakcanary.RefWatcher$1.run(RefWatcher.java:117)
at com.squareup.leakcanary.AndroidWatchExecutor$3.run(AndroidWatchExecutor.java:80)
at android.os.Handler.handleCallback(Handler.java:754)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:163)
at android.os.HandlerThread.run(HandlerThread.java:61)

Thank your issue,这个是Leakcanary没有兼容android 8.0所致,考虑将它的版本号升为最新即可~

最新也报这个异常

LeakCanary的新版本为了兼容8.0,在HeapDumpAnalysisService的runAnalysis()方法中使用了ContextCompat.StartForegroundService()来启动前台服务,这个ContextCompat使用的是v4包的类,之所以在ContextCompat中找不到这个方法,是因为它是在V4版本在26.1.0的时候才有,项目之前使用的是25.3.0,现已解决~