24

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.

Community
  • 1
  • 1
WenChao
  • 3,586
  • 6
  • 32
  • 46
  • 2
    Just import "import com.squareup.leakcanary.LeakCanary;" and see it works or not. – Sharjeel May 11 '15 at 02:04
  • updated, LeakCanary doesn't exist in the package :( – WenChao May 11 '15 at 02:26
  • Can you post more code from your build.gradle file where you put this? You could try to remove dependencies, sync gradle and the added them again to see if it works. – Sharjeel May 11 '15 at 02:34
  • i noticed this issue too in one of my projects, but haven't resolved it yet. my best guess is some gradle dependency or magic script that's either excluding or stripping out the dependency. Try following the instructions on a greenfield project. You'll notice no issues there. – KG - May 11 '15 at 03:37
  • what versions of gradle, the android-gradle plugin and Android Studio are you using? – KG - May 11 '15 at 06:13
  • Add this `compile 'com.squareup.leakcanary:leakcanary-android:1.3'` to your gradle temporary to test. – xDragonZ May 11 '15 at 07:17
  • 1
    I have the same problem and haven't found a solution yet. Any ideas? – Roberto May 11 '15 at 09:59
  • 1
    @xDragonZ I have tried that approach, still no luck. The jar hosted on jcenter contains the LeakCanary class, somehow gradle doesn't download that. – WenChao May 11 '15 at 10:08
  • @WenChao what versions of gradle, the android-gradle plugin and Android Studio are you using? if you're using a previous version, can you up the version to the latest and check if it works? – KG - May 12 '15 at 00:23
  • Hi @KaushikGopal, Im using the latest version AS 1.2.1.1, with plugin version 1.2 and gradle version 2.3. – WenChao May 12 '15 at 00:42
  • dang it. (wild goose chase but) does upgrading to gradle 2.4 + gradle version 2.3.**1** make any difference? after upgrading try a Build > Clean project from AS (i should warn you, i'm just throwing out ideas to hone in on the problem. Build > Clean didn't work for me, but my initial guess was because i was using an older version) – KG - May 12 '15 at 00:51
  • Hi @Lancelot, Clean the project works for me mysteriously, cheers! – WenChao May 13 '15 at 05:34

7 Answers7

12

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

Community
  • 1
  • 1
Maragues
  • 37,861
  • 14
  • 95
  • 96
7

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'
}
Vic Torious
  • 1,757
  • 3
  • 21
  • 24
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()
         }
    }
    
GabrielOshiro
  • 7,986
  • 4
  • 45
  • 57
tuder
  • 339
  • 3
  • 10
1

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).

Thorbear
  • 2,303
  • 28
  • 23
  • 1
    Hi , adding @aar to the dependency doesn't seem to work. Gradle just simply ignores this dependency at all ! – WenChao May 12 '15 at 00:58
0

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

    dependencies {
        mybuildtypeImplementation 'com.squareup.leakcanary:leakcanary-android:1.6.3'
    }
Tom Howard
  • 4,672
  • 2
  • 43
  • 48
0

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.

Stephen
  • 9,899
  • 16
  • 90
  • 137
0

I had multiple build types inside my Gradle build types block. I added separate Implementation for my build types and it worked for me. For example, if you have build types other than debug and release then try

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