LeakCanary is a memory leak detection library for Android and Java. LeakCanary
My project is based on android make file system, which relies on some android internal interfaces and custom methods.
How can I add the LeakCanary as a lib into my app to detect memory leak.
My solution: First, I have to build the LeakCanary as a jar file, but how to. as it's a gradle directory structure, and I have never used Gradle before.
Any tip is precious.
For Leak Canary, you should work with Android Studio. In Android Studio, In your build.gradle, add this
dependencies {
debugCompile 'com.squareup.leakcanary:leakcanary-android:1.3.1'
releaseCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.3.1'
}
And in your Application class, add this line LeakCanary.install(this); in onCreate() method like this
public class ExampleApplication extends Application {
@Override public void onCreate() {
super.onCreate();
LeakCanary.install(this);
}
}
follow this link https://github.com/square/leakcanary for more details.
Hope this might be helpful.
This is needed to be part of your application in order for leakcanary to work.
public class ExampleApplication extends Application {
@Override public void onCreate() {
super.onCreate();
LeakCanary.install(this);
}
}
but this is confusing because most of us do not write such kind of class that extends the Application class directly, a work around rather a simple statement will fix this problem,
public class YourClass extends Activity{//AppCompatActivity, A ctionBarActivity or anything
@Override public void onCreate() {
super.onCreate();
LeakCanary.install(getApplication());
}
}
hope this helps!!!
Its better to call this method in
onPostCreate()
LeakCanary is not just a JAR - it contains not only the java code, but resources too (png's for example). If you are using ANT, then the only thing you can do is to include LeakCanary as a library project. But I strongly recommend switching to gradle. Because android development team is not going to support importing any library which is not just jar in any user-friendly way in the nearest future (because gradle is priority). And importing as library projects is a painful procedure, which get's more painful when it sometimes comes to including library's dependencies also as library projects. I've done it by hand long ago only because the client used eclipse with ant for big project for ages. Generally, you must do the following:
The final step is to enable manifest merger. Add the following line to project.properties of your project:
manifestmerger.enabled=true
It is done to merge all the AndroidManifest.xml from library project into final apk.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With