Search code examples
androidandroid-appwidget

Android AppWidget Timber not logging


I'm trying to switch from standard Log to Timber, in order to easily remove logging messages when deploying my app to Google Play, but it is not working

build.gradle

apply plugin: 'com.android.application'

android {
    compileSdkVersion 22
    buildToolsVersion "22.0.1"

    defaultConfig {
        applicationId "org.myapp"
        minSdkVersion 16
        targetSdkVersion 22
        versionCode 1
        versionName "1.0"
    }
}

buildscript {
    repositories {
        jcenter()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:1.1.3'
    }
}

repositories {
    mavenCentral()
}

dependencies {
    compile 'com.jakewharton.timber:timber:3.1.0'
}

MyApp.java

package org.myapp;

...

import timber.log.Timber;
import static timber.log.Timber.DebugTree;

public class MyApp extends AppWidgetProvider {

  @Override
  public void onEnabled(Context context) {
    super.onEnabled(context);

    if (MyBuildConfig.DEBUG) {
      Timber.plant(new DebugTree());
    } else {
      //Timber.plant(new CrashReportingTree());
    }

    Timber.d("MyApp.onEnabled");
  }

MyBuildConfig.java

package org.myapp;

public class MyBuildConfig {
  public static final boolean DEBUG = true;
}

The app compiles fine with

./gradlew assembleDebug

but when doing

adb logcat | grep -i thing

my debug statements are not there.

I still would like to see debug messages with the debug apk but not with the release apk, what is wrong?


Solution

  • Moving

    Timber.plant(new DebugTree());
    

    to onUpdate from onEnabled solved the problem, as onEnabled was not called since the AppWidget was already installed