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?
6 Answers
Add android:debuggable="true"
(default is false) to your Manifest inside the <application>
tag.
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.
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)
-
6I 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.– LarsHCommented 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.– LarsHCommented Oct 27, 2017 at 18:34 -
4You'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 correspondingbuild.gradle
property calleddebuggable
which can be set depending on the buildType.– reVerseCommented Oct 28, 2017 at 9: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.
-
5This 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 :)– MohKCommented Nov 19, 2019 at 9:51 -
@MohK, agree with you. Strange, but in another project I have
debuggable false
inrelease
build, but see logs and debugging does not work even intrue
state. :)– CoolMindCommented Nov 19, 2019 at 11:39 -
It seems it only works with System.out.println() in the new versions of AS.– IldiXCommented Feb 26, 2020 at 16:06
-
-
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/
)
-
3joxi.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
-
@DenRimus, in Play Market, I think, an application should be in release mode. So, there can be turned off all logs.– CoolMindCommented 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.– JensVCommented Sep 7, 2017 at 12:47
-
1Android 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
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.
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.
-
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 instanceconst val TEST = true
. But don't forget to change it's value when publish an application.– CoolMindCommented Jun 17, 2021 at 12:10 -
-
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.– solamourCommented Apr 11 at 17:03
Log.d
calls are removed when a release version is exported - I'm not sure what other levels (if any) are also removed.