android – Square LeakCanary Cannot find symbol-ThrowExceptions

Exception or error:

Here is the screenshot

build.gradle has been configured as per github insturctions.LeakCanary class doesn’t seem to be included.

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

enter image description here

analyzer and watcher packages has just 1 single class file in it.

How to solve:

Rebuilding the project fixed it for me.

There’s a deleted answer (I don’t know why) by Kaushik Gopal that gives this solution and points to a Github issue

###

I am honestly surprised that

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

did not work for you, because it did for me.

Maybe you want to try it with your buildType instead of the productFlavour:

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

###

  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()
         }
    }
    

###

Try adding @aar after the version number for the dependency. That will make gradle specifically look for an aar library instead of a jar (I had this problem in Maven, and adding <type>aar</type> seemed to help).

###

For my gradle project, specifying <<BUILDTYPE>>Implementation seemed to work:

    dependencies {
        mybuildtypeImplementation 'com.squareup.leakcanary:leakcanary-android:1.6.3'
    }

###

I face this similar issue.You shouldn’t use the same class name LeakCanary when extends Application.

I have changed the below code:

public class LeakCanary extends Application { }

to

public class MainController extends Application { }

to make it done.

Leave a Reply

Your email address will not be published. Required fields are marked *