方形泄漏检测工具LeakCanary找不到符号。

24

这是屏幕截图

已按照 Github 的说明配置了 build.gradle。似乎未包含 LeakCanary 类。

 dependencies {
   debugCompile 'com.squareup.leakcanary:leakcanary-android:1.3'
   releaseCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.3'
 }

在此输入图片描述

分析器和监视器包中只有一个单独的类文件。


2
只需导入 "import com.squareup.leakcanary.LeakCanary;",然后查看它是否正常工作。 - Sharjeel
我也在我的一个项目中注意到了这个问题,但还没有解决。我最好的猜测是一些Gradle依赖项或魔法脚本要么排除要么剥离了该依赖项。尝试在一个全新的项目上按照说明操作。你会发现那里没有任何问题。 - KG -
你使用的Gradle、Android Gradle插件和Android Studio版本是什么? - KG -
1
我也有同样的问题,但还没有找到解决方案。有什么想法吗? - Roberto
1
@xDragonZ 我已经尝试过那种方法了,但还是没有成功。在jcenter上托管的jar包中包含了LeakCanary类,但是gradle却无法下载它。 - WenChao
显示剩余7条评论
7个回答

12

对我来说,重建项目解决了它。

有一个被删除的答案(我不知道为什么)由Kaushik Gopal提供了这个解决方案,并指向Github问题


1
所说的解决方案对我参与的一个项目没有起作用 :( 。因此,我认为那个答案不是完全可靠的。 - KG -
尝试从命令行清理,这样可能会有更好的结果。 - KG -
我不得不使缓存失效并重新启动Android Studio。 - JoKr

7

我很惊讶

 dependencies {
   debugCompile 'com.squareup.leakcanary:leakcanary-android:1.3'
   releaseCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.3'
 }

如果对您没有用,请尝试更改构建类型而非产品风味:

这可能与您的构建类型有关,您可以尝试更换构建类型而非产品风味:

dependencies {
   someBuildTypeCompile 'com.squareup.leakcanary:leakcanary-android:1.3'
}

缺少someBuildTypeCompile。 - Jemshit Iskenderov

2
  1. Make sure you add the libraries to your build.gradle

    dependencies {
        debugCompile 'com.squareup.leakcanary:leakcanary-android:1.3.1'
        releaseCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.3.1'
    }
    
  2. add mavenCentral() to your repositories

    buildscript {
        repositories {
            jcenter()
            mavenCentral()
        }
        dependencies {
             classpath 'com.android.tools.build:gradle:1.5.0'
        }
    }
    allprojects {
         repositories {
             jcenter()
             mavenCentral()
         }
    }
    

1
尝试在版本号后面添加@aar以便让gradle专门寻找aar库,而不是jar(我在Maven中遇到了这个问题,添加<type>aar</type>似乎有所帮助)。

1
嗨,将@aar添加到依赖项中似乎不起作用。Gradle完全忽略了这个依赖! - WenChao

0

我遇到了类似的问题。当继承Application时,您不应该使用相同的类名LeakCanary。

我已经更改了以下代码:

public class LeakCanary extends Application { }

public class MainController extends Application { }

让它完成。


0
在我的Gradle项目中,指定<<BUILDTYPE>>Implementation似乎是有效的:
    dependencies {
        mybuildtypeImplementation 'com.squareup.leakcanary:leakcanary-android:1.6.3'
    }

0

在我的Gradle构建类型块中,我有多个构建类型。我为我的构建类型添加了单独的实现,并且它对我起作用了。例如,如果您除了debug和release之外还有其他构建类型,请尝试

dependencies {
    yourCustomBuildTypeImplementation 'com.squareup.leakcanary:leakcanary-android:version'
}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接