benny.huo

    benny.huo

    4 years ago
    Hey guys. I have a problem using kotlin-reflect with proguard. I called
    superTypes
    to retrieve superTypes of
    RepoListFragment
    while its superClass
    CommonListFragment
    was mapped to
    com.bennyhuo.github.view.common.b
    . The runtime crash:
    java.lang.IllegalStateException: Incomplete hierarchy for class RepoListFragment, unresolved classes [com.bennyhuo.github.view.common.CommonListFragment]
    at kotlin.reflect.jvm.internal.components.RuntimeErrorReporter.reportIncompleteHierarchy(RuntimeErrorReporter.kt:26)
    at kotlin.reflect.jvm.internal.impl.serialization.deserialization.descriptors.DeserializedClassDescriptor$DeserializedClassTypeConstructor.computeSupertypes(DeserializedClassDescriptor.kt:187)
    After hours of searching I found that kotlin-reflect get the type infomation from the annotation
    Metadata
    while the value of it may not be processed by proguard.
    @Metadata(
       mv = {1, 1, 7},
       bv = {1, 0, 2},
       k = 1,
       d1 = {"..."},
       d2 = {"Lcom/bennyhuo/github/view/fragments/subfragments/RepoListFragment;", "Lcom/bennyhuo/github/view/common/CommonListFragment;", "Lcom/bennyhuo/github/network/entities/Repository;", "Lcom/bennyhuo/github/presenter/RepoListPresenter;", "()V", "adapter", "Lcom/bennyhuo/github/view/fragments/RepoListAdapter;", "getAdapter", "()Lcom/bennyhuo/github/view/fragments/RepoListAdapter;", "production sources for module app"}
    )
    Any suggestions or workaround?😳
    udalov

    udalov

    4 years ago
    I can only suggest to go ahead and vote on the feature request to support Kotlin class files in Proguard: https://sourceforge.net/p/proguard/feature-requests/182/
    Zac Sweers

    Zac Sweers

    2 years ago
    @udalov Since this was not accepted into upstream proguard, and android’s toolchain uses R8, could I propose embedding these rules in kotlin-reflect’s runtime jar instead? The android toolchain automatically extracts rules from dependency jars and will merge them into the proguard or R8 minification step with any other rules. Happy to contribute a PR if you’re open to it, I think it’s pretty sorely needed by the community. https://github.com/square/moshi/issues/402 https://github.com/airbnb/MvRx/issues/232 and many more
    udalov

    udalov

    2 years ago
    Whoa, I didn’t know about such feature of Android build tools. Yes, that makes sense and a PR is very welcome
    BTW note that Proguard has beta Kotlin support now, where among other things, they transform metadata: https://www.guardsquare.com/en/products/proguard/proguard-manual-kotlin-beta
    Zac Sweers

    Zac Sweers

    2 years ago