how to enable logger in specific screen of release-build in android?
I Realeased an APK in playstore which is obfuscated apk and Logger are disabled , When customers find some issues in that apk in specific screen. So i want to Enable Logger in that specific screen of release-build.
Is it possible, If Yes how can i acheive..??
Updated Question:
Apk release build - Obfuscated by DexGuard
Thanks
You could use Log.i. Information logs are always showed to users. See more.
If you used ProGuard to remove all logs from your application you should remove clearing of public static int i(...); from rules.
If it wasn't enough flexibility try Timber
And setup ReleaseTree for your release versions
It is not possible to enable logger in release builds. Instead of that you can use this lib to print log on your screen.
Another solution you can find an example of it here. It's really simple, just add a class OnScreenLog to your project
Related
I'm new to software dev, so I don't know the proper etiquettes for this process.
I just want to keep certain debugging code (comments and stuff) and maybe some testing resources like images after cleaning an app for release. These are things the app will never need for functioning, just stuff I wanna keep.
Are comments kept after the compile? If not I can just comment out those lines.
I thought about using different flavours, but it doesn't seem appropriate? Just because the build release type makes 4 options.-which I never really understood. Does switching from Debug mode to Release mode change anything code-wise? Like other than the signing methods and other discrete (discrete to me anyways) changes?
Thanks!
Are comments kept after the compile? If not I can just comment out those lines.
Commented-out code isn't compiled, so if you want, yes you can comment out code and it won't show up in the final app. However, there's no way to comment out resources in the same way, so if there are resources you only want to have in your debug version, keep reading.
I thought about using different flavours, but it doesn't seem
appropriate? Just because the build release type makes 4 options.
You're right, you don't need flavors because there's already build types (Debug and Release) which are set up to do what you want. Your Java code can tell the difference between debug and release types via the BuildConfig class, which is automatically generated as part of the build. It has a DEBUG Boolean constant that's defined to true for debug builds and false for release. So you can have code that does something like this:
if (BuildConfig.DEBUG) {
// Do something here that you don't want to have in the final release
}
Since BuildConfig.DEBUG is a static final Boolean, then Java is smart enough to see that what's inside that if block will never run in a release build, so the compiler will strip that code out and it won't appear in your app.
If there are resources you'd only like to have in the debug and not release versions of the app, then you can put them in a different folder in your hierarchy:
ProjectDirectory
+--app
+--src
+--main
+--res <--Your normal resources go here
+--java
+--AndroidManifest.xml
+--debug
+--res <-- Put resources for the debug build only here
That debug/res folder won't be created by default, but if you set it up, the build system should pick it up. Having said that, debug-only resources are a little unusual; you would only have something like this if your debug version of the app had something like a diagnostic activity or menus or something like that. It's certainly possible, but it's a little more advanced than it sounds like what you're doing so far.
-which I never really understood. Does switching from Debug mode to Release mode change anything code-wise? Like other than the signing
methods and other discrete (discrete to me anyways) changes?
Some of the important changes in a release build are:
BuildConfig.DEBUG will be false as already noted.
Your app will be signed with a release key instead of the debug key. The release key is what you will use to sign it to upload to the Google Play store. You'll need to set up that key if you don't have it already.
Release apps are built as non-debuggable unless you change the setting.
You can run ProGuard (which does dead code stripping and obfuscation) on release builds, though it's not configured to run by default.
Android app submission says, remove any logging before submission. Have a few question on this one
Is System.out.println considered as logging? How can I disable it across the app without having to remove it on by one
Tried android:debuggable="false" inside manifest, but eclipse says "Avoid hardcoding the debug mode; leaving it out allows debug and release builds to automatically assign one"
I have some third party jar files that shows Log statement when I test my app. How can I remove them, considering I don't have the source.
Suggestions are highly appreciated.
I'm sure you've come across the fact that you can do the if(GLOBAL_VALUE) trick, because your logs are already there!
Therefore, my suggestions is to use Proguard; http://developer.android.com/tools/help/proguard.html
The following proguard.cfg chunk instructs to remove Log.d calls.
-assumenosideeffects class android.util.Log {
public static *** d(...);
}
You can do it for other calls like Log.i, Log.e, etc based on the value you put there!
As for your Jar, if it is referencing the Android Log system, ProGuard should take care of that.
I am developing an android application where i am using a lot of Logs for printing values at console for debugging purpose. Now i am using Log.i() method in Android. Now actually what the problem , before i have to give to testing team, i have to remove all logs. When the number of classes in the project is small, i can remove it manually. But when the project contains 40 to 50 classes, it is humanly impossible to go to all classes and remove it manually. So is there any settings is availaible in eclipse so that i can remove or disable all logs by changing a single settings or configuration or else is there any jar file that helps for debugging much more easier than Log.i() method. Any suggestion or guidance is highly appreciable
Thanks inAdvance
the logs will be kept on the phone and any user/developer can check them out by installing apps like Catlog even without using adb! This is a problem as you stand to give unnecessary and at times, confidential data to users/other developers.
Simple way to solve this?
a. Use Proguard to automatically block all logs, more information in this stackoverflow thread
Here you can automatically block all logs at the bytecode level in Proguard
-assumenosideeffects class android.util.Log {
public static int v(...);
}
The above, for example would remove any verbose logging, more in this thread
b. I use a if(DEBUG) Log.i for all my logs, so that with one change of the boolean DEBUG i can switch on/off all logs
This answer referred from this link
Android hide logs in the application when upload to market
I've been using Log.whatever() calls to Log various bits of information as I've been developing my Android app. As I prepare to publish my app to the Android Marketplace, I'm trying to figure out what I need to remove.
According to the Android developer Dev Guide, before publishing, they suggest:
Deactivate any calls to Log methods in the source code.
How does one deactivate the Log methods? Obviously I could go through and erase them all (which is a bit of a pain) but is there some other way to deactivate Log calls that I'm unaware of?
Also, what danger is there to having Log calls in a published application? Can anyone install Eclipse, plugin in their phone and enable Debug mode and see all the same LogCat information that I see as I'm developing?
Also the Dev Guide suggests:
Remove the android:debuggable="true" attribute from the <application> element of the manifest.
I was unaware of this flag until now. What does it do exactly? I've been developing and debugging my app just fine up to this point and this flag is not set to true or false for in my Manifest.
Yes, anyone can install the Android SDK (with or without Eclipse) to view all log messages on your device.
I don't recommend completely removing your logging code, but instead wrap it, such as: if (DEBUG) Log.d(...) where DEBUG is some static boolean you define in a convenient place. I prefer to create a utility class so that all log calls across various classes can be enabled/disabled at once.
Simplest chnages for that would be to define one custom Class say MyLog, now replace all the calls of Log.d() to MyLog.d().
Now inside your class you can have one flag that can enable or disable logs.
hope this helps.
A good practice is to use something like if (DEBUG) Log.whatever, and then simply make DEBUG false.
There is no real danger except that you may expose some underlying implementaion which may expose glitches and hackable points in you app. The real problem is the performance penalty that you will get from logging too much.
As for android:debuggable="true", search for it in here
Finally, yes, Logcat logs are global and can be seen by anyone using the Android SDK.
Yes logs can be seen by anyone. Not only that, apps can collect logs programmatically: http://www.cuteandroid.com/five-android-logcat-related-open-source-apps-for-developers
So make sure you don't expose sensitive data as many apps collect logs - mine do in case of unhandled exceptions / crashes.
Yep, most certainly. Everyone can see them.
If you don't want that to happen, delete them from your code. It's quite normal though. I see a lot of apps using logs, and odds are that almost none of your users will be using that to check your logs.
I would recommend not wrapping your Log statements; depending on the size of your application that could take a while, will probably result in a fair bit of extra code and is just a hassle IMHO.
Instead I found configuring Proguard to automatically optimize your code and strip out Log statements when exporting an app release to be much easier. It will also obfuscate specified areas slowing down any reverse engineers that are trying to break your app.
If you do decide to go with Proguard you can put something like the following in your proguard-project.txt file to strip out log statements.
-assumenosideeffects class android.util.Log {
public static boolean isLoggable(java.lang.String, int);
public static int v(...);
public static int i(...);
public static int w(...);
public static int d(...);
public static int e(...);
}
In the Android docs it talks about getting an application ready for the market.
It says that you should deactivite Log and debugging.
Is this totally neccessary? Or just an suggestion?
Also how do you go about doing this?
You can remove all logging by running progruard with the correct options.
Android Proguard, removing all Log statements and merging packages
Has some of the options needed. Takes some understanding of Proguard but allows the source to keep the log messages while not worrying about them in a released application. Additionally, you can add the other methods to the config as well to remove logging completely. Not all applications do this. Many of Google's own applications are fairly chatty on the log in release.