0

i am trying to disable all logs

-assumenosideeffects class android.util.Log {

public static *** v(...);
public static *** i(...);
public static *** w(...);
public static *** d(...);
public static *** e(...);

}

 -assumenosideeffects class android.util.Log { *; }

but when i set

          proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'

build faild error

    UNEXPECTED TOP-LEVEL EXCEPTION:
Error:java.lang.InterruptedException: Too many errors
at com.android.dx.command.dexer.Main.processAllFiles(Main.java:600)
... 4 more
Error:Execution failed for task ':app:transformClassesWithDexForDebug'.

com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command '/Library/Java/JavaVirtualMachines/jdk1.8.0_66.jdk/Contents/Home/bin/java'' finished with non-zero exit value 2

with this proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' its build but logs are visible

The recommended solution is to recompile the class from source, using an up-to-date compiler and without specifying any "-target" type options. The consequence of ignoring this warning is that reflective operations on this class will incorrectly indicate that it is not an inner class.

Uncaught translation error: com.android.dx.cf.code.SimException: local variable type mismatch: attempt to set or access a value of type java.lang.Object using a local variable of type int. This is symptomatic of .class transformation tools that ignore local variable information.

andro
  • 1,007
  • 1
  • 14
  • 32
  • there might be some other error as well. Please check again. – Mustansar Saeed Feb 03 '16 at 07:07
  • check edit qus Warning:Ignoring InnerClasses attribute for an anonymous inner class (android.support.v7.widget.by) that doesn't come with an associated EnclosingMethod attribute. this type of error coming wtih different package name like (android.support.v7.widget.bx) , – andro Feb 03 '16 at 07:23
  • this shows that you have to keep the native references. Please post your proguard file – Mustansar Saeed Feb 03 '16 at 07:31
  • -keepparameternames -renamesourcefileattribute SourceFile -keepattributes Exceptions,InnerClasses,Signature,Deprecated,LineNumberTable,SourceFile -keepattributes EnclosingMethod ###remove log#### -assumenosideeffects class android.util.Log { public static *** v(...); public static *** i(...); public static *** w(...); public static *** d(...); public static *** e(...); } – andro Feb 03 '16 at 07:37
  • compile fileTree(dir: 'libs', include: ['*.jar'],exclude: 'android-support-*.jar') – andro Feb 03 '16 at 07:38
  • You have wrong proguard file. I post the correct file inwhich native methods need to keep as it is. – Mustansar Saeed Feb 03 '16 at 07:39
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/102436/discussion-between-andro-and-mustansar-saeed). – andro Feb 03 '16 at 07:49

2 Answers2

2

Please use the following proguard for the reference as during optimizations, native methods need to keep as it is.

-dontusemixedcaseclassnames
-optimizationpasses 5
-allowaccessmodification
-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.BroadcastReceiver
-keep public class * extends android.content.ContentProvider
-keep public class * extends android.preference.Preference
-keep public class * extends android.support.v4.app.Fragment
-keep public class * extends android.app.Fragment
# For native methods, see http://proguard.sourceforge.net/manual/examples.html#native
-keepclasseswithmembernames class * {
 native <methods>;
}
-keep public class * extends android.view.View {
 public <init>(android.content.Context);
 public <init>(android.content.Context, android.util.AttributeSet);
 public <init>(android.content.Context, android.util.AttributeSet, int);
 public void set*(...);
}
-keepclasseswithmembers class * {
 public <init>(android.content.Context, android.util.AttributeSet);
}
-keepclasseswithmembers class * {
 public <init>(android.content.Context, android.util.AttributeSet, int);
}
-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 *;
}

hope this helps.

Zahra.HY
  • 1,684
  • 1
  • 15
  • 25
Mustansar Saeed
  • 2,730
  • 2
  • 22
  • 46
  • This is a very popular but incorrect ProGuard config. AAPT automaticalle creates rules to keep classes mentioned in manifest, so Activities won't be stripped. But this config, for example, keeps even abstract activities. – Miha_x64 Nov 20 '17 at 21:42
0

You could try to create a dummy Log class in package com.example.mylog with NOPs for v,i,w,d,e and then use this proguard remapping

android.util.Log -> com.example.mylog.Log

wiht the option -applymapping

Radu Ionescu
  • 3,462
  • 5
  • 24
  • 43