Non obfuscate Scala object are visible but unaccessible

Let’s define an object

package aaa
trait Keep
trait Toto extends Keep { def a: Int }
object Toto extends Keep {
  def apply(i: Int): Int = new Toto { val a: Int  = i }
}

Exclude it from obfuscating class

-keep class * extends aaa.Keep
-keep class * implements aaa.Keep
-keep class * extends aaa.Keep {*;}
-keep class * implements aaa.Keep {*;}

After obfuscation when exploring the jar i can see class Toto and Toto$ with theirs methods as on non obfuscated jar.

Now on another project depending of the obfuscated jar.

import aaa.Toto
val zero = Toto(0)

My IDEA ide reconize the Toto class and apply method but when i compile i fall on

error: class aaa.Toto is not a value.

Here are my other options

			"-dontnote",
			"-dontwarn",
			"-ignorewarnings", 
			"-dontskipnonpubliclibraryclassmembers", 
			"-dontoptimize", 
			"-keepparameternames",
			"-keeppackagenames aaa.*", 
			"-keepattributes Exceptions,InnerClasses,Signature,Deprecated,SourceFile,LineNumberTable,*Annotation*,EnclosingMethod,MethodParameters,ConstantValue,Module,ModulePackages,LocalVariableTable,LocalVariableTypeTable",
			
			"-keep interface org.** { *; }",
			"-keep class org.** { *; }",
			"-keep enum org.** { *; }",

			"-keep class * implements org.xml.sax.EntityResolver",
			"-keepclassmembers class * {** MODULE$;}",
			"-keep class * implements jline.Completor",
			"-keep class * implements jline.Terminal",
			"-keepclasseswithmembernames class * {native <methods>;}",
			"-keepclasseswithmembers class * {<init>(scala.tools.nsc.Global);}",
			"-keep class scala.tools.nsc.Global",
			"-keepclassmembers,allowoptimization enum * {public static **[] values();public static ** valueOf(java.lang.String);}",
			"-keepclassmembernames class * {java.lang.Class class$(java.lang.String);java.lang.Class class$(java.lang.String, boolean);}",

I probably forget an exclusion rule for a specific aspect but i cannot figure out which one.
How is it possible to call scala object methods on the obfuscated jar knowing the object is -keep ?

Kind Regards
Gaël

Hi @KyBe67 !

The scala compiler adds some custom attributes to Java class files:

$ javap -c -v -p Toto.class
....
Error: unknown attribute
  ScalaInlineInfo: length = 0x9
   01 00 00 01 00 0B 00 0C 00
Error: unknown attribute
  ScalaSig: length = 0x3
   05 00 00

Therefore you will need to keep these attributes also by adding Scala* to your -keepattributes:

-keepattributes Exceptions,InnerClasses,Signature,Deprecated,SourceFile,LineNumberTable,*Annotation*,EnclosingMethod,MethodParameters,ConstantValue,Module,ModulePackages,LocalVariableTable,LocalVariableTypeTable,Scala*

I also noticed that Scala requires the Keep superclass to be kept, so I had to add a -keep rule to get it to work:

-keep class aaa.Keep

Please try this out,

Thanks,

James