Enable LogCat on Release Build in Android Studio - android

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?

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)

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.

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/)

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.

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.

Related

Android Profiler: No debuggable processes

It can find my device, but without any debuggable process. It's not the first time this problem occurred. But it still worked yesterday, I used profiler to observe my app's memory info. And when I try to debug my app, the process is debuggable. I tried all solutions just like restart Android Studio, none worked. Does anyone know why?
Works for me:
In build.gradle(:app) -> find "buildTypes" -> to "debug" section -> set it to "true" -> done
buildTypes {
release {
debuggable false
minifyEnabled true
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.config
}
debug {
debuggable true
}
}
Mabe you can Close the AndroidStudio.And then restart the adb service.try again.
Keep your application installed is a Debug mode.
if is done,it will be work. I tried.
Since running apps on an emulator is slow, sometimes you may have more than one instance of your app on the emulator which will cause a problem. Just delete the existing emulator and create a new one, or you can instead just wipe the data on an existing emulator:

when i generated the signed apk file and trying to run on other devices some fuction not working. can anyone have solution?

I am trying to run my android application on other devices, it installed properly but some XML file not working properly. It works as I expected when I installed through USB debugging. I am trying to find solution for many days. I don't get anything related to my issue.
This must be the result of Obfuscation
Add this lines in your build.gradle
buildTypes {
release {
...
debuggable false
shrinkResources false
minifyEnabled false
...
}
}
or you can add your files in pro-gaurd

Android Release build can be attached

I recently find my Android Release version can be attached through Android Studio and all logs are available to be seen as well, even though I'm sure that AndroidManifest.xml file doesn't contain "android:debuggable=true" and app's build.gradle file specified that
buildTypes {
...
release {
...
debuggable false
...
}
...
}
Do you guys have any good idea to avoid this?
You can only keep like this code below:
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
hopefully works it.
Logs are nothing to do with debuggable true.
The option debuggale is to making your application debuggable in release mode, so you can attach debugger even on your release build by default it is false.
If you are using Log class and printing any log it will always display until and unless you put the check before logging them.
What you can do is put a check before every log is Build.Debug == true then print the log.
Or you can use open source library for this work like this one which provide the control of logging based on your configuration.
Or you can find a more helpful answer here.

You uploaded a debuggable APK. For security reasons you need to disable debugging before it can be published in Google Play-Upload apk to google play

I Want to upload my apk to google play store.but its Show me error like this.
**You uploaded a debuggable APK. For security reasons you need to disable debugging before it can be published in Google Play**
and than i searched for this and i receive suggetion to change the android:debuggable="false" in manifast.xml.
I changed like this
manifast.xml
<application
android:allowBackup="true"
android:debuggable="false"
android:icon="#mipmap/ic_launcher"
android:label="Concall"
android:screenOrientation="portrait"
android:theme="#style/AppTheme" >
and in my build.grable(Module)
android {
buildTypes {
debug {
debuggable false
}
}
1.is the enough for upload Apk to google play store?
2.if i pick up apk from my project folder(app>>build>>output>>apk>>apk-debug.apk) after this change than after it will able to upload in google play store??
Don't use the debug variant output! Build a release apk. You can do that in Android Studio by going to the menu Build -> Generate Signed APK. Or by executing ./gradlew assembleRelease if you have properly configured signing in the build file.
I ran into this error and my application did not reference debuggable anywhere. After a little bit of searching, I found that I accidentally had testCoverageEnabled true in my release build type.
release {
testCoverageEnabled true
...
}
Removing this resolved the issue.
In my build.gradle file, I had debuggable = false and I was wondering why I'm getting this issue. later I found that it was debuggable = true in my AndroidManifest.xml file's application tag
I was having the same problem. Unknowingly I kept
debuggable true in release buildType
buildTypes {
release {
minifyEnabled false
shrinkResources false
debuggable true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
After changed to false. Its working fine.
buildTypes {
release {
minifyEnabled true
shrinkResources true
debuggable false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
This should be the flags for uploading the Apk to Playstore. Not needed to be release build. If you want to test your qa build, you can do ./gradlew assembleQa
with flags
minifyEnabled true
debuggable false
shrinkResources true
testCoverageEnabled = false
This feature can be controlled from the manifest file also, disable from there
android:debuggable="false
I was getting this warning when I wasn't selecting the "Signed" version.In the signed version, select release to deploy.
.

android debugger does not stop at breakpoints

I am seeing debug statements in the console but the debugger does not stop on any breakpoints. I tried clearing all breakpoints and adding them back in. Not sure how this can happen but it is.
Solution that worked for me:
Simply uninstall the app from the device (manually on the device) and try debugging again(!)
If you use Android studio, click debug app instead of run app:
According to this answer, Inside build.gradle for your app module, disable minifyEnable for your build variant and change it to false. Then, it should be:
minifyEnabled false
othewise you will see Line number not available in class xxxx when you hover over breakpoint markers and they will be looked with a cross on them
Have you set the debuggable flag in the AndroidManifest?
If you miss that, do so by adding android:debuggable="true" in the application tag.
It should look like that in the end:
<application android:icon="#drawable/icon" android:label="#string/app_name" android:debuggable="true">
In my case, click the "Attach debugger to Android process"
And it will shows a window said "Choose Process"
Select the device you are using, and select the project that you want to debug. And it works.
Sometimes the debugger need to re-attach to the devices when you open the debugger at the first time.
For Android Studio:
Check if the option Mute Breakpoints is enabled by mistake. The icon looks like this:
For Eclipse:
Check if the option "Skip All Breakpoints" is enabled by mistake. It is the last icon on the following toolbar
Did you do "Debug As --> Android Application" instead of "Run As"?
Only if you do "Debug As", eclipse will stop at breakpoints.
I had the same problem.
Go to build.gradle.
You must change this code if you have one.
buildTypes {
release {
minifyEnabled true
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
debug {
debuggable true
minifyEnabled true
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
The debug section should look like this:
buildTypes {
release {
minifyEnabled false
shrinkResources false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
debug {
debuggable true
minifyEnabled false
shrinkResources false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
I hope your problem is solved
if you have added some build type in build.gradle check to have debuggable true
buildTypes {
debug {
debuggable true
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
In my case, the app created a service with a different process with android:process=":service" in the AndroidManifest. So I was setting breakpoints in the service process code while the debugger is automatically attached to the main app process. Pretty stupid of me but it might help someone else.
You attach to the service process with Run > Attach Debugger To Android Process and choose the service process. You might need to add android.os.Debug.waitForDebugger(); to your service process code if you can't attach in time manually.
As far as I know, there's no way to automatically tell Android Studio or IntelliJ to attach to a different process before running.
i had this problem i clean buildTypes part of build.gradle
and try age so it work me.
If you are finding this issue while using the Flutter plugin, you can try updating the plugin to version >65.1.3 as specified in this article
None of the valid answers above worked for me. In my case there was another app still in the background that I had launched some time earlier via Android Studio. So not the same App/PackageId, but another. After closing that app I got hits on breakpoints via wifi debugging.
I had the same issue and resolved it by increasing the debugger timeout values.
The emulator is slow as a dog on my Dev box and that is what prevented the debugger to catch and stop on breakpoints.
I changed the timeout values respectively from 3000 to 10000 and 20000 to 60000 and all is fine now.
V.

Categories

Resources