93

By default, when I change Build Variants to release I don't get any Logs on the logcat, but I do need to read release logs of my app, how can I enable this?

2
  • 1
    Change your log level. I may be wrong but as I understand it Log.d calls are removed when a release version is exported - I'm not sure what other levels (if any) are also removed.
    – Squonk
    Commented Sep 1, 2014 at 18:02
  • @Squonk I have also recently observed that Log.v logs are also not exposed in release build. Do any one know what can be the reason for it? Commented Oct 16, 2019 at 12:40

6 Answers 6

103

Add android:debuggable="true" (default is false) to your Manifest inside the <application> tag.

From the docs:

android:debuggable
Whether or not the application can be debugged, even when running on a device in user mode — "true" if it can be, and "false" if not.

respectively

You can disable debugging by removing the android:debuggable attribute from the tag in your manifest file, or by setting the android:debuggable attribute to false in your manifest file.

Edit

You may need to add the following to your build.gradle file inside the android{...} tag:

lintOptions {
   checkReleaseBuilds false
}

And as a side-note: Right on the device the Logs are always written, no matter if your application's debuggable is set to false or true. But via the LogCat in Android Studio it's only possible if debuggable is set to true. (Just tested this)

3
  • 6
    I don't think this answer is correct. At least, the docs it cites don't say that turning on android:debuggable will turn on logging. In fact, developer.android.com/studio/publish/… is fairly clear that turning off logging and turning off debugging are two separate things. The OP asked how to turn on logging.
    – LarsH
    Commented Oct 27, 2017 at 18:26
  • P.S. Please correct me if I'm wrong, citing a source that says that android:debuggable="true" enables logging.
    – LarsH
    Commented Oct 27, 2017 at 18:34
  • 4
    You're somewhat right, but debuggable means that the Android Monitor in Android Studio can be attached to the currently running APK. This enables the Logcat to show the log statements like in debug builds. Other than that: This answer is now a little bit over three years old - so most probably you should switch to the corresponding build.gradle property called debuggable which can be set depending on the buildType.
    – reVerse
    Commented Oct 28, 2017 at 9:44
44

You should add

android {
    buildTypes {
        release {
            debuggable true

In this case you can use Log. or System.out.println and see logs.

If you cannot run release version (app is disabled), and error is shown: "apk is not signed. Please configure the signing information for the selected flavor using the Project Structure dialog", see app-release-unsigned.apk is not signed.

7
  • 5
    This works for me. Having logs in release build is necessary at lease after enabling proguard for the first time. But don't forget to make debuggable false for production builds :)
    – MohK
    Commented Nov 19, 2019 at 9:51
  • @MohK, agree with you. Strange, but in another project I have debuggable false in release build, but see logs and debugging does not work even in true state. :)
    – CoolMind
    Commented Nov 19, 2019 at 11:39
  • It seems it only works with System.out.println() in the new versions of AS.
    – IldiX
    Commented Feb 26, 2020 at 16:06
  • @IldiX, did you also try Kotlin println() or Timber.?
    – CoolMind
    Commented Feb 26, 2020 at 16:11
  • @CoolMind the project is in java.
    – IldiX
    Commented Feb 27, 2020 at 14:37
34

I do not like the other solution because then you are not testing how the App really is deployed.

A better solution is to open the Android Device Monitor where you can see the logs even when in release configuration with debuggable=false.

Find it here:

Tools -> Android -> Android Device Monitor

Update:
Android Device Monitor was removed in Android Studio 3.2. However, it is still present in SDK, and you can use it to see the logs (it is located in $ANDROID_SDK/tools/)

9
  • 3
    joxi.ru/eAOl5EWu8Ll5ro App from market with debuggable not mentioned in manifest (thus, it's false). Nothing - in AS LogCat or in DeviceMonitor Commented Jul 8, 2015 at 9:22
  • 5
    you will not see Log.v and Log.d this way
    – NikkyD
    Commented Feb 23, 2017 at 12:18
  • @DenRimus, in Play Market, I think, an application should be in release mode. So, there can be turned off all logs.
    – CoolMind
    Commented May 19, 2017 at 9:17
  • You won't be able to filter this way because you can't see which log corresponds to your package.
    – JensV
    Commented Sep 7, 2017 at 12:47
  • 1
    Android Device Monitor was removed in AS 3.2 - developer.android.com/studio/profile/monitor However, it is still present in SDK, and you can use it to see the logs (it is located in $ANDROID_SKD/tools/) Commented May 28, 2019 at 14:38
5

This approach will obviously help you to get logs while testing the production build. But be careful while uploading your app to Google Play Store, Toggle debuggable to false before uploading to production.

buildTypes {
    debug {
        manifestPlaceholders = [crashlyticsCollectionEnabled: "false"]
    }
    release {
        manifestPlaceholders = [crashlyticsCollectionEnabled: "false"]
        lintOptions {
            checkReleaseBuilds false
            abortOnError false
        }
        shrinkResources true
        minifyEnabled true
        debuggable true
        signingConfig signingConfigs.productionrelease
        proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
    }
}

set crashlyticsCollectionEnabled to false to avoid your crashes to report to Google Play-Store while debugging.

4

debuggable true in build.gradle works well, except that BuildConfig.DEBUG is also going to be true. This might be a problem if your app relies on BuildConfig.DEBUG to do something only when it's a debug build.

In such a case, try Log.wtf(BuildConfig.APPLICATION_ID, "something went wrong"), which will print to logcat even if it's a release build.

4
  • Agree with you. In this case I added a constant in a config class for test and release builds (and didn't rely on BuildConfig.DEBUG). For instance const val TEST = true. But don't forget to change it's value when publish an application.
    – CoolMind
    Commented Jun 17, 2021 at 12:10
  • Log.wtf is super helpful
    – tenprint
    Commented Oct 26, 2022 at 20:42
  • I'd argue that Log.wtf isn't really intended for the purpose of general logging though. Better to keep the log levels clean and use them the proper way. Commented Apr 11 at 12:16
  • 1
    @SimonForsberg, I completely agree. I'd say "Log.wtf()" was meant for truly catastrophic cases, not something benign, or even mildly benign. Then again, it's an option you want to keep in your back pocket, hoping you'd never have to resort to such an extreme.
    – solamour
    Commented Apr 11 at 17:03
4

remove "package:mine" in filter field of logcat

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.