diff --git a/README.md b/README.md index 5376d7d..05b0f0f 100644 --- a/README.md +++ b/README.md @@ -43,6 +43,6 @@ This is my personal project to experiment with following tools & technologies * Database (local caching - Realm (maybe?)) * Scheduler - data syncing * Google Play Alpha Beta release - * LeakCanary + * LeakCanary _(See [#60](https://github.com/amardeshbd/android-daily-headlines/pull/60))_ I'll try to update references for these items when I use in the app :sunglasses: diff --git a/build.gradle b/build.gradle index d5c9880..05f83d7 100644 --- a/build.gradle +++ b/build.gradle @@ -90,4 +90,5 @@ ext { jodaTimeVersion = '2.9.4' glassfishJavaxAnnotationVersion = '10.0-b28' timberLibraryVersion = '4.3.1' + leakcanaryLibraryVersion = '1.5' } \ No newline at end of file diff --git a/core-lib/build.gradle b/core-lib/build.gradle index ad85f42..44fff00 100644 --- a/core-lib/build.gradle +++ b/core-lib/build.gradle @@ -74,6 +74,12 @@ dependencies { compile "com.squareup.picasso:picasso:$rootProject.picassoVersion" + // leakcanary - A memory leak detection library for Android and Java. + // https://github.com/square/leakcanary + debugCompile "com.squareup.leakcanary:leakcanary-android:$rootProject.leakcanaryLibraryVersion" + releaseCompile "com.squareup.leakcanary:leakcanary-android-no-op:$rootProject.leakcanaryLibraryVersion" + + // ---------------------------------------------------------------- // Android Unit and Instrumentation test // ---------------------------------------------------------------- @@ -82,4 +88,5 @@ dependencies { }) compile "com.android.support:appcompat-v7:$rootProject.supportLibraryVersion" testCompile "junit:junit:$rootProject.junitVersion" + testCompile "com.squareup.leakcanary:leakcanary-android-no-op:$rootProject.leakcanaryLibraryVersion" } diff --git a/core-lib/src/main/java/info/hossainkhan/android/core/CoreApplication.java b/core-lib/src/main/java/info/hossainkhan/android/core/CoreApplication.java index f92a9b6..f7af814 100644 --- a/core-lib/src/main/java/info/hossainkhan/android/core/CoreApplication.java +++ b/core-lib/src/main/java/info/hossainkhan/android/core/CoreApplication.java @@ -27,6 +27,8 @@ import android.app.Application; import android.content.Context; +import com.squareup.leakcanary.LeakCanary; + import info.hossainkhan.android.core.dagger.components.AppComponent; import info.hossainkhan.android.core.dagger.components.DaggerAppComponent; import info.hossainkhan.android.core.dagger.modules.InteractorsModule; @@ -46,10 +48,20 @@ public class CoreApplication extends Application { public void onCreate() { super.onCreate(); + initLeakCanary(); initAppComponent(); initLogger(); } + private void initLeakCanary() { + if (LeakCanary.isInAnalyzerProcess(this)) { + // This process is dedicated to LeakCanary for heap analysis. + // You should not init your app in this process. + return; + } + LeakCanary.install(this); + } + private void initLogger() { if (ENABLE_LOGGING) { android.util.Log.i(TAG, "Planting tree for timber logger.");