proguard IllegalArgumentException - proguard

Trying to build release version of my application. It comes up with an error saying that
Caused by: java.io.IOException: java.lang.RuntimeException: java.lang.IllegalArgumentException: Value "a" is not an integer value [proguard.evaluation.value.UnknownReferenceValue]
I saw a similar case here:
https://sourceforge.net/p/proguard/bugs/573/
I have already added -optimizations !class/unbosing/enum
but the error still shows
there is no change. Maybe I am missing something else from the proguard-rules?
-optimizationpasses 5
-dontusemixedcaseclassnames
-dontskipnonpubliclibraryclasses
-dontpreverify
-verbose
-optimizations !class/unboxing/enum
-optimizations !code/simplification/arithmetic,!field/*,!class/merging/*
-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.app.backup.BackupAgentHelper
-keep public class * extends android.preference.Preference
-keep public class com.google.vending.licensing.ILicensingService
-keep public class com.android.vending.licensing.ILicensingService
-keep class android.support.v4.** { *; }
-keep public class * extends android.support.v4.**
-keep public class * extends android.app.Fragment
-keep class android.support.v8.renderscript.** { *; }
-dontwarn android.support.**
-dontobfuscate
-keep public class com.google.android.gms.** { public *; }
-dontwarn com.google.android.gms.**
-dontwarn okio.**
-dontwarn retrofit2.Platform$Java8
# Keep all things of data model classes
-keep public class com.hotmob.sdk.model.** { *; }
-keepclasseswithmembernames class * {
native <methods>;
}
-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);
}
-keepclassmembers enum * {
public static **[] values();
public static ** valueOf(java.lang.String);
}
-keepclassmembers class * extends java.lang.Enum {
<fields>;
public static **[] values();
public static ** valueOf(java.lang.String);
}
-keep class * implements android.os.Parcelable {
public static final android.os.Parcelable$Creator *;
}
-keep class MyClass;
-Adagger.android.experimentalUseStringKeys
# gson
-keepattributes Signature
-keepattributes *Annotation*
-keep class sun.misc.Unsafe { *; }
# android-saripaar
-keep class com.mobsandgeeks.saripaar.** { *; }
-keep #com.mobsandgeeks.saripaar.annotation.ValidateUsing class * { *; }
# loading icon
-keep class com.wang.avi.** { *; }
-keep class com.wang.avi.indicators.** { *; }
This is the error that shows
Optimizing (pass 1/5)...
> Task :app:transformClassesAndResourcesWithProguardForRelease
Unexpected error while evaluating instruction:
Class = [kotlin/reflect/jvm/internal/impl/load/java/lazy/descriptors/LazyJavaPackageScope$classes$1]
Method = [invoke(Lkotlin/reflect/jvm/internal/impl/load/java/lazy/descriptors/LazyJavaPackageScope$FindClassRequest;)Lkotlin/reflect/jvm/internal/impl/descriptors/ClassDescriptor;]
Instruction = [311] ificmpne +113 (target=424)
Exception = [java.lang.IllegalArgumentException] (Value "a" is not an integer value [proguard.evaluation.value.UnknownReferenceValue])
Unexpected error while performing partial evaluation:
Class = [kotlin/reflect/jvm/internal/impl/load/java/lazy/descriptors/LazyJavaPackageScope$classes$1]
Method = [invoke(Lkotlin/reflect/jvm/internal/impl/load/java/lazy/descriptors/LazyJavaPackageScope$FindClassRequest;)Lkotlin/reflect/jvm/internal/impl/descriptors/ClassDescriptor;]
Exception = [java.lang.IllegalArgumentException] (Value "a" is not an integer value [proguard.evaluation.value.UnknownReferenceValue])
Warning: Exception while processing task java.io.IOException: java.lang.RuntimeException: java.lang.IllegalArgumentException: Value "a" is not an integer value [proguard.evaluation.value.UnknownReferenceValue]
Thread(Tasks limiter_2): destruction
> Task :app:transformClassesAndResourcesWithProguardForRelease FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:transformClassesAndResourcesWithProguardForRelease'.
> Job failed, see logs for details
The stacktrack debug shows pretty much the same
19:04:39.831 [ERROR] [system.err] Unexpected error while evaluating instruction:
19:04:39.831 [ERROR] [system.err] Class = [kotlin/reflect/jvm/internal/impl/load/java/lazy/descriptors/LazyJavaPackageScope$classes$1]
19:04:39.832 [ERROR] [system.err] Method = [invoke(Lkotlin/reflect/jvm/internal/impl/load/java/lazy/descriptors/LazyJavaPackageScope$FindClassRequest;)Lkotlin/reflect/jvm/internal/impl/descriptors/ClassDescriptor;]
19:04:39.833 [ERROR] [system.err] Instruction = [311] ificmpne +113 (target=424)
19:04:39.833 [ERROR] [system.err] Exception = [java.lang.IllegalArgumentException] (Value "a" is not an integer value [proguard.evaluation.value.UnknownReferenceValue])
19:04:39.834 [ERROR] [system.err] Unexpected error while performing partial evaluation:
19:04:39.834 [ERROR] [system.err] Class = [kotlin/reflect/jvm/internal/impl/load/java/lazy/descriptors/LazyJavaPackageScope$classes$1]
19:04:39.834 [ERROR] [system.err] Method = [invoke(Lkotlin/reflect/jvm/internal/impl/load/java/lazy/descriptors/LazyJavaPackageScope$FindClassRequest;)Lkotlin/reflect/jvm/internal/impl/descriptors/ClassDescriptor;]
19:04:39.834 [ERROR] [system.err] Exception = [java.lang.IllegalArgumentException] (Value "a" is not an integer value [proguard.evaluation.value.UnknownReferenceValue])
19:04:40.541 [QUIET] [system.out] Warning: Exception while processing task java.io.IOException: java.lang.RuntimeException: java.lang.IllegalArgumentException: Value "a" is not an integer value [proguard.evaluation.value.UnknownReferenceValue]
19:04:40.550 [QUIET] [system.out] Thread(Tasks limiter_1): destruction
19:03:00.186 [LIFECYCLE] [class org.gradle.internal.buildevents.TaskExecutionLogger]
19:03:00.186 [LIFECYCLE] [class org.gradle.internal.buildevents.TaskExecutionLogger] > Task :app:transformClassesAndResourcesWithProguardForRelease
19:04:40.550 [DEBUG] [org.gradle.internal.operations.DefaultBuildOperationExecutor] Completing Build operation 'Execute transform for :app:transformClassesAndResourcesWithProguardForRelease'
19:04:40.551 [DEBUG] [org.gradle.internal.operations.DefaultBuildOperationExecutor] Build operation 'Execute transform for :app:transformClassesAndResourcesWithProguardForRelease' completed
19:04:40.551 [DEBUG] [org.gradle.api.internal.tasks.execution.DefaultTaskFingerprinter] Fingerprinting property otherFileOutputs.otherFileOutput1 (Output) for task ':app:transformClassesAndResourcesWithProguardForRelease'
19:04:40.551 [DEBUG] [org.gradle.api.internal.tasks.execution.DefaultTaskFingerprinter] Fingerprinting property otherFileOutputs.otherFileOutput2 (Output) for task ':app:transformClassesAndResourcesWithProguardForRelease'
19:04:40.570 [DEBUG] [org.gradle.api.internal.tasks.execution.DefaultTaskFingerprinter] Fingerprinting property otherFileOutputs.otherFileOutput3 (Output) for task ':app:transformClassesAndResourcesWithProguardForRelease'
19:04:40.579 [DEBUG] [org.gradle.api.internal.tasks.execution.DefaultTaskFingerprinter] Fingerprinting property streamOutputFolder (Output) for task ':app:transformClassesAndResourcesWithProguardForRelease'
19:04:40.579 [DEBUG] [org.gradle.internal.execution.steps.CacheStep] Not storing result of task ':app:transformClassesAndResourcesWithProguardForRelease' in cache because the execution failed
19:04:40.580 [DEBUG] [org.gradle.api.internal.tasks.execution.ResolveTaskExecutionModeExecuter] Removed task artifact state for {} from context.
19:04:40.581 [DEBUG] [org.gradle.internal.operations.DefaultBuildOperationExecutor] Completing Build operation 'Task :app:transformClassesAndResourcesWithProguardForRelease'
19:04:40.583 [LIFECYCLE] [class org.gradle.internal.buildevents.TaskExecutionLogger]
19:04:40.583 [LIFECYCLE] [class org.gradle.internal.buildevents.TaskExecutionLogger] > Task :app:transformClassesAndResourcesWithProguardForRelease FAILED

Related

Is there a way to keep Kotlin annotations only for public functions/members when obfuscating with proguard?

I am trying to obfuscate a library written in Kotlin using Proguard.
In the library I use default and named arguments. In order for these to work when including the obfuscated jar as a lib I need the flag -keepattributes RuntimeVisibleAnnotations in the Proguard file.
With this flag all private functions are no longer obfuscated, because the annotations for them contain the plain names. Is there a possibility to apply this flag only to public functions and members and to delete the annotations for private functions and members?
This is probably also connected to the fact that public members of an interface only work with the above-mentioned flag. Is there a solution that solves the problem with both the interface and the classes?
current Proguard file:
-dontwarn
-dontoptimize
-keepparameternames
-keepattributes Signature, InnerClasses, Exceptions
-keepattributes RuntimeVisibleAnnotations
-keep class custom.package.** {
!private <fields>;
!private <methods>;
}
-keep interface custom.package.** {
!private <fields>;
!private <methods>;
}
obfuscation result with this config:
public class ExampleClass {
private val clearNameAttr: kotlin.String /* compiled code */
private fun clearPrivateMethod (namedParam: kotlin.String) : kotlin.Boolean { /* compiled code */ }
public fun clearPublicMethod (namedParam: kotlin.String) : kotlin.Boolean { /* compiled code */ }
}
desired obfuscation result:
public class ExampleClass {
private String a
private boolean a (String var1) { /* compiled code */ }
public boolean clearPublicMethod (String namedParam) { /* compiled code */ }
}

proguard+springboot plugin -> no classes in jar

I have to obfuscate lib and application. Lib - simple lib with two classes. Obfuscation done well. Application(with obfuscated lib in dependencies) builded with springboot plugin, works well.
When I try to obfuscate application jar I have got jar without *.classes of my app.
here is proguard conf:
-verbose
-dontwarn
-dontoptimize
-dontpreverify
-printmapping out.map
-keepattributes Exceptions,InnerClasses,Signature,Deprecated,SourceFile,LineNumberTable,*Annotation*,EnclosingMethod
-keepdirectories
-keep class org.springframework.******* { *;}
-keep public class * extends RequestEntity { *;}
-keep public class * extends ResponseEntity { *;}
-keepclassmembers,allowoptimization enum * {
public static **[] values();
public static ** valueOf(java.lang.String);
}
-keepnames class * implements java.io.Serializable {*; }
-keepclasseswithmembers public class * {
public static void main(java.lang.String[]);
}
classes:
public class TestEntity {
private Integer fieldInt;
private String fieldStr
--cut--- (set* get*)
public class TestActions {
private TestEntity entity;
Gson gson = new Gson();
--cut---(set* get*)
import my.act.TestActions;
public class App {
public static void main(String[] args) {
TestActions testActions=new TestActions();
testActions.doPrintEntity();
}
}
out.map:
my.App -> my.App:
6:6:void <init>() -> <init>
8:10:void main(java.lang.String[]) -> main
org.springframework.boot.loader.ExecutableArchiveLauncher -> org.springframework.boot.loader.ExecutableArchiveLauncher:
org.springframework.boot.loader.archive.Archive archive -> archive
37:44:void <init>() -> <init>
--cut---
rows about spring...
and I have got test_app1.jar without my.App, only empty folder:
test_app1.jar\BOOT-INF\classes\my\
Any ideas? Help please...
If you use proguard maven plugin for a springboot application. Don't forget to add spring package plugin as well.

Unable to access companion object used in kotlin class after enabling proguard

I have a Kotlin class with some variables in companion object. After enabling proguard, The variables are not getting accessed.
class Test{
......
companion object {
const val USER_NAME = "user_name"
.....
}
.....
}
Proguard rules include:-
-keep class kotlin.** { *; }
-keep class kotlin.Metadata { *; }
-dontwarn kotlin.**
-keepclassmembers class **$WhenMappings {
<fields>;
}
-keepclassmembers class kotlin.Metadata {
public <fields>;
public <methods>;
}
-keepclassmembers class * {
static final % *;
static final java.lang.String *;
}
Problem resolved using #Keep before companion object
class Test{
......
#Keep companion object {
const val USER_NAME = "user_name"
.....
}
.....
}
The accepted answer uses the #Keep annotation. If that works for you, then great, but in our case it didn't make a difference.
For anyone else in the same boat, here's the solution that worked for us (add to your proguard rules):
-keepclassmembers class com.example.some.package.SomeClass {
public static ** Companion;
}
After many struggles with it the thing that worked best for me is:
-keep class <class>$Companion { *; }
no annotations needed.
I faced a similar problem, there was a function in the companion object that was not being accessed after enabling proguard.
#Keep didn't work for me, after a lot of struggle. I found the solution.
Just add #JvmStatic annotation to the function inside the companion object.
And you are good to go.

Error generating signed APK due to proguard rules

Generating signed APK giving error after I updated Android Studio to 3.3-rc01 and enabled R8 code shrinking.
It is giving following proguard error :
Error: ~/app/proguard-rules.pro, offset: 2613, line: 74, column: 7, Expected char '-' at ~/app/proguard-rules.pro:74:7
-dump class_files.txt
before android studio 3.3-rc01 and without R8 code shrinking it was working perfectly fine.
Any workarounds for this or I have to disable the proguard rules now.
Following is my proguard-rules.pro file
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable
# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
# Retrofit does reflection on generic parameters and InnerClass is required to use Signature.
-keepattributes Signature, InnerClasses
# Retain service method parameters when optimizing.
-keepclassmembers,allowshrinking,allowobfuscation interface * {
#retrofit2.http.* <methods>;
}
# Ignore annotation used for build tooling.
-dontwarn org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement
# Ignore JSR 305 annotations for embedding nullability information.
-dontwarn javax.annotation.**
# Guarded by a NoClassDefFoundError try/catch and only used when on the classpath.
-dontwarn kotlin.Unit
# Top-level functions that can only be used by Kotlin.
-dontwarn retrofit2.-KotlinExtensions
# A resource is loaded with a relative path so the package of this class must be preserved.
-keepnames class okhttp3.internal.publicsuffix.PublicSuffixDatabase
# Animal Sniffer compileOnly dependency to ensure APIs are compatible with older versions of Java.
-dontwarn org.codehaus.mojo.animal_sniffer.*
# OkHttp platform used only on JVM and when Conscrypt dependency is available.
-dontwarn okhttp3.internal.platform.ConscryptPlatform
-dontwarn javax.xml.stream.**
-dontwarn rx.internal.util.unsafe.**
#Glide proguard rules
-keep public class * implements com.bumptech.glide.module.GlideModule
-keep public class * extends com.bumptech.glide.module.AppGlideModule
-keep public enum com.bumptech.glide.load.resource.bitmap.ImageHeaderParser$** {
**[] $VALUES;
public *;
}
-keep class android.support.v7.widget.LinearLayoutManager { *; }
-keep public class * extends android.support.v7.widget.RecyclerView$LayoutManager {
public <init>(...);
}
##---------------Begin: proguard configuration common for all Android apps ----------
-optimizationpasses 5
-dontusemixedcaseclassnames
-dontskipnonpubliclibraryclasses
-dontskipnonpubliclibraryclassmembers
-dontpreverify
-verbose
-dump class_files.txt
-printseeds seeds.txt
-printusage unused.txt
-optimizations !code/simplification/arithmetic,!field/*,!class/merging/*
-allowaccessmodification
-keepattributes *Annotation*
-renamesourcefileattribute SourceFile
-repackageclasses ''
-keep class com.qikcircle.qiketask.models.** { *; }
-keep class android.support.v4.** {*;}
-keep public class * extends android.app.Activity
-keep public class * extends android.support.v4.app.Fragment
-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.app.backup.BackupAgentHelper
-keep public class * extends android.preference.Preference
-keep public class com.android.vending.licensing.ILicensingService
-dontnote com.android.vending.licensing.ILicensingService
# Explicitly preserve all serialization members. The Serializable interface
# is only a marker interface, so it wouldn't save them.
-keepclassmembers class * implements java.io.Serializable {
static final long serialVersionUID;
private static final java.io.ObjectStreamField[] serialPersistentFields;
private void writeObject(java.io.ObjectOutputStream);
private void readObject(java.io.ObjectInputStream);
java.lang.Object writeReplace();
java.lang.Object readResolve();
}
# Preserve all native method names and the names of their classes.
-keepclasseswithmembernames class * {
native <methods>;
}
-keepclasseswithmembernames class * {
public <init>(android.content.Context, android.util.AttributeSet);
}
-keepclasseswithmembernames class * {
public <init>(android.content.Context, android.util.AttributeSet, int);
}
# Preserve static fields of inner classes of R classes that might be accessed
# through introspection.
-keepclassmembers class **.R$* {
public static <fields>;
}
# Preserve the special static methods that are required in all enumeration classes.
-keepclassmembers enum * {
public static **[] values();
public static ** valueOf(java.lang.String);
}
-keep public class * {
public protected *;
}
-keep class * implements android.os.Parcelable {
public static final android.os.Parcelable$Creator *;
}
##---------------End: proguard configuration common for all Android apps ----------
##---------------Begin: proguard configuration for Gson ----------
# Gson uses generic type information stored in a class file when working with fields. Proguard
# removes such information by default, so configure it to keep all of it.
# For using GSON #Expose annotation
# Gson specific classes
-keep class sun.misc.Unsafe { *; }
#-keep class com.google.gson.stream.** { *; }
# Application classes that will be serialized/deserialized over Gson
-keep class com.google.gson.examples.android.model.** { *; }
##---------------End: proguard configuration for Gson ----------
#removing logs
-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(...);
}
#for getting crash reports
-assumenosideeffects class android.util.Log {
public static int v(...);
public static int d(...);
}
#Crashlytics proguard rules
-keepattributes SourceFile,LineNumberTable
-keep public class * extends java.lang.Exception
-ignorewarnings
-keep class * {
public private *;
}
I've tried the dump directive with Proguard (I didn't use it before) and all works fine.
[...]
## Strip Log.d
-assumenosideeffects class android.util.Log {
public static *** d(...);
}
-dump foo.txt
[...]
And I find my foo.txt under ./app/foo.txt
Printing classes to [./app/foo.txt]...
Then I enable R8 in legacy mode:
# For the bravests
android.enableR8=true
# For the crazyest. Must be enable also the previous setting
#android.enableR8.fullMode=true
And I got your error.
Without this line I can compile my APK even in full mode without any (apparent) issue.
So I confirm that this directive is not supported. Remember that R8 is still in beta. If you want you can submit an issue on the link I posted in comment.
Opened the issue here.
for me i had to remove the first line " public private *; " in my prograuard.pro file

Failed to create EJB in REST service

I have a problem with injecting EJB inside of a REST service (using jersey on glassfish 3.2 server) and I'm puzzled.
I have an EJB interface declared as:
import javax.ejb.Local;
#Local
public interface TestServiceLocal {
public String getText();
}
and the class bean that implements it:
import javax.ejb.Local;
import javax.ejb.Stateless;
/**
* Session Bean implementation class TestService
*/
#Stateless
#Local(TestServiceLocal.class)
public class TestService implements Serializable, TestServiceLocal {
private static final long serialVersionUID = 1L;
/**
* Default constructor.
*/
public TestService() {
// TODO Auto-generated constructor stub
}
#Override
public String getText() {
return this.getClass().getName();
}
}
The REST service looks like:
#Path("/service")
#Stateless
public class TestRestService {
#EJB(beanName="TestService")
private TestServiceLocal testService;
public TestRestService () {
}
#GET
#Produces(MediaType.TEXT_PLAIN)
#Path("/events")
public String getText() {
return testService.getText();
}
}
The problem is that when the REST service is called the bean cannot be created:
SEVERE: EJB5070: Exception creating stateless session bean : [TestRestService]
WARNING: EJB5184:A system exception occurred during an invocation on EJB TestRestService, method: public java.lang.String TestRestService.getText()
WARNING: javax.ejb.EJBException: javax.ejb.EJBException: javax.ejb.CreateException: Could not create stateless EJB
at com.sun.ejb.containers.StatelessSessionContainer._getContext(StatelessSessionContainer.java:454)
at com.sun.ejb.containers.BaseContainer.getContext(BaseContainer.java:2547)
at com.sun.ejb.containers.BaseContainer.preInvoke(BaseContainer.java:1899)
at com.sun.ejb.containers.EJBLocalObjectInvocationHandler.invoke(EJBLocalObjectInvocationHandler.java:212)
at com.sun.ejb.containers.EJBLocalObjectInvocationHandlerDelegate.invoke(EJBLocalObjectInvocationHandlerDelegate.java:88)
at com.sun.proxy.$Proxy839.getText(Unknown Source)
I had already took a look at the answers posted here but none of them seemed to work for me. Any help will be appreciated. Thank you!
PS: I forgot to mentioned (don't know if it's relevant). My project is created under eclipse Juno as Dynamic Web Project.