MSaudi
MSaudi

Reputation: 4652

Enable log with obfuscation in Android using proguard

I'm using proguard tool for obfuscation in Android. After making the release (export as signed APK), I can not see the Logs in LogCat. is there any specific flags than control this.

Thanks.

Edit 3: I use separate class for managing Logs, called LogUtil

Edit 2: Android Version android:minSdkVersion="14" android:targetSdkVersion="17"

Edit 1:

Proguard file :

# To enable ProGuard in your project, edit project.properties
# to define the proguard.config property as described in that file.
#
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in ${sdk.dir}/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the ProGuard
# include property in project.properties.
#
# For more details, see
#   http://developer.android.com/guide/developing/tools/proguard.html

# Add any project specific keep options here:

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
-keepclassmembers class com.mvapps.booko.ui.activity.bookactivity.ReaderController.AndroidBridge {
  public *;
}


# This is a configuration file for ProGuard.
# http://proguard.sourceforge.net/index.html#manual/usage.html

# Optimizations: If you don't want to optimize, use the
# proguard-android.txt configuration file instead of this one, which
# turns off the optimization flags.  Adding optimization introduces
# certain risks, since for example not all optimizations performed by
# ProGuard works on all versions of Dalvik.  The following flags turn
# off various optimizations known to have issues, but the list may not
# be complete or up to date. (The "arithmetic" optimization can be
# used if you are only targeting Android 2.0 or later.)  Make sure you
# test thoroughly if you go this route.


-optimizations !code/simplification/arithmetic,!code/simplification/cast,!field/*,!class/merging/*,!code/allocation/variable
-optimizationpasses 5
-allowaccessmodification
-dontpreverify
-dontwarn
-ignorewarnings 


# The remainder of this file is identical to the non-optimized version
# of the Proguard configuration file (except that the other file has
# flags to turn off optimization).

-dontusemixedcaseclassnames
-dontskipnonpubliclibraryclasses
-dontskipnonpubliclibraryclassmembers
-verbose

-keepattributes *Annotation*
-keepattributes Signature
-keep public class com.google.vending.licensing.ILicensingService
-keep public class com.android.vending.licensing.ILicensingService
-keep public class * extends android.app.Activity
-keep public class * extends android.app.Application
-keep public class * extends android.app.Service
-keep public class * extends android.content.ContentProvider
-keep public class * extends android.content.BroadcastReceiver
-keep public class * extends android.app.backup.BackupAgentHelper
-keep public class * extends android.preference.Preference


-keep class net.sqlcipher.** {
    *;
}



-keep class com.mvapps.booko.ui.view.** {
    *;
}

-keep class android.webkit.** {
    *;
}

-keep class com.intertrust.wasabi.** {
    *;
}

-keep class com.flurry.** {
    *;
}
-dontwarn com.flurry.**
-keepattributes *Annotation*,EnclosingMethod
-keepclasseswithmembers class * {
public <init>(android.content.Context, android.util.AttributeSet, int);
}

-keep class com.bugsense.trace.** {
    *;
}

-keepclassmembers class **.R$* {
    public static <fields>;
}

-keep class **.R$*

-keepclassmembers class com.mvapps.booko.* {
    public static <fields>;
}

-keep class com.mvapps.booko.*

-keepclassmembers class android.app.* {
    *;
}

-keep class android.app.*


-keepclassmembers class org.apache.* {
    *;
}

-keep class org.apache.*



-keep class org.acra.ReportingInteractionMode {
    *;
}

# OrmLite uses reflection
-keep class com.j256.**
-keepclassmembers class com.j256.** { *; }
-keep enum com.j256.**
-keepclassmembers enum com.j256.** { *; }
-keep interface com.j256.**
-keepclassmembers interface com.j256.** { *; }

# JSON Library uses reflection
-keep class com.google.**
-keepclassmembers class com.google.** { *; }
-keep enum com.google.**
-keepclassmembers enum com.google.** { *; }
-keep interface com.google.**
-keepclassmembers interface com.google.** { *; }


# Database files
-keep class com.mvapps.booko.common.dto.**
-keepclassmembers class com.mvapps.booko.common.dto.** { *; }
-keep enum com.mvapps.booko.common.dto.**
-keepclassmembers enum com.mvapps.booko.common.dto.** { *; }
-keep interface com.mvapps.booko.common.dto.**
-keepclassmembers interface com.mvapps.booko.common.dto.** { *; }


-keep public class * implements java.io.Serializable


-dontwarn com.j256.**
-dontwarn com.handmark.**
-dontwarn group.pals.** 
-dontwarn org.htmlcleaner.**
-dontwarn com.google.**
-dontwarn com.vis.**
-dontwarn com.androidquery.**
-dontwarn javax.naming.**


# For native methods, see http://proguard.sourceforge.net/manual/examples.html#native
-keepclasseswithmembernames class * {
    native <methods>;
}

# keep setters in Views so that animations can still work.
# see http://proguard.sourceforge.net/manual/examples.html#beans
-keepclassmembers public class * extends android.view.View {
   void set*(***);
   *** get*();
}

# We want to keep methods in Activity that could be used in the XML attribute onClick
-keepclassmembers class * extends android.app.Activity {
   public void *(android.view.View);
}

# For enumeration classes, see http://proguard.sourceforge.net/manual/examples.html#enumerations
-keepclassmembers enum * {
    public static **[] values();
    public static ** valueOf(java.lang.String);
}

-keep class * implements android.os.Parcelable {
  public static final android.os.Parcelable$Creator *;
}

-keepclassmembers class **.R$* {
    public static <fields>;
}

# The support library contains references to newer platform versions.
# Don't warn about those in case this app is linking against an older
# platform version.  We know about them, and they are safe.
-dontwarn android.support.**

Upvotes: 0

Views: 2777

Answers (2)

MSaudi
MSaudi

Reputation: 4652

The problem was in the separate class I use for logging, the developer of the class made this condition

if(DEBUG &&  BuildConfig.DEBUG)
{
    // log code here
}

Thanks for your efforts and sorry for that.

Upvotes: 1

Ken
Ken

Reputation: 31161

Please check your ProGuard configuration file for something to the effect of:

-assumenosideeffects class android.util.Log {
    public static *** d(...);
    public static *** i(...);
    public static *** v(...);
}

If this is present, please try removing it or adjusting it to suit.

Edit: If that doesn't work, please try removing all the optimisations starting from -optimizations...

-optimizations !code/simplification/arithmetic,!code/simplification/cast,!field/*,!class/merging/*,!code/allocation/variable
-optimizationpasses 5
-allowaccessmodification
-dontpreverify
-dontwarn
-ignorewarnings

When I'm debugging my ProGuard files I often remove several lines or keep a wide range of classes until what I want works, then restore the file as needed.

Upvotes: 0

Related Questions