How can I take a picture of my sdk encoded with kotlin (and get rid of metadata)

I am developing an SDK (Android library) and I have to confuse most of my code so that the client cannot try and play with the internal code. My library is encoded in kotlin, and I used proguard to obfuscate the code. The problem is that during compilation and obfuscation, the code still has @ kotlin.Metadata (runtime) annotations. With these annotations, it is very easy to get the Java code that generated this "(not so) obfuscated" bytecode. "

At first, I thought it was my mistake, and my project had too many entropy sources that could cause this behavior, so I made a sample project to prove that the problem is not related to my sdk implementation. I created a new project with AS, then a lib module with 2 files:

  • facade.kt is my facade class, one that I don’t want to confuse, so the client can use it:

    package com.example.mylibrary
    
    class MyFacade(val internalClass:InternalClass) {
    
       fun doSomething() {
          internalClass.doSomething(
                 firstArgument=1,
                 secondArgument=2
          )
        }
     }
    
  • and in this example inner.kt contains the classes that I want to confuse:

    package com.example.mylibrary
    
    class InternalClass {
        fun doSomething(firstArgument: Int, secondArgument: Int) {
            System.out.println("Arguments are : $firstArgument, $secondArgument")
        }
    }
    

The proguard rules are introduced into the gradle project with this release closure:

buildTypes {
    release {
        minifyEnabled true
        proguardFiles 'proguard-rules.pro'
    }
}

And so proguard-rules.pro(only one line, no more):

-keep class com.example.mylibrary.MyFacade {*;}

: ./gradlew clean myLib:assembleRelease, aar, , "a" "a", , kotlin @Metadata, , , , ..... ...

@Metadata(
   mv = {1, 1, 7},
   bv = {1, 0, 2},
   k = 1,
   d1 = {"\u0000\u001a\n\u0002\u0018\u0002\n\u0002\u0010\u0000\n\u0002\b\u0002\n\u0002\u0010\u0002\n\u0000\n\u0002\u0010\b\n\u0002\b\u0002\u0018\u00002\u00020\u0001B\u0005¢\u0006\u0002\u0010\u0002J\u0016\u0010\u0003\u001a\u00020\u00042\u0006\u0010\u0005\u001a\u00020\u00062\u0006\u0010\u0007\u001a\u00020\u0006¨\u0006\b"},
   d2 = {"Lcom/example/mylibrary/InternalClass;", "", "()V", "doSomething", "", "firstArgument", "", "secondArgument", "mylibrary_release"}
)
public final class a {
    ...
}

, : , , , - ?

+4
1

, , , ProGuard , :

android {
    defaultConfig {
        consumerProguardFiles 'consumer-proguard-rules.pro'
    }
}

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

- , ( ) , .

0

Source: https://habr.com/ru/post/1681932/


All Articles