Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

174
Views
Data class metada is removed with proguard / R8

I have a package with some data classes and I'm trying to access the constructor at runtime using Kotlin reflection clazz.primaryConstructor, Everything is working as expected but when I enable R8, data classes metadata are removed so for example when I check if the KClass isData it returns false and the primary constructor is also null which happens only when enabling R8. I tried everything including adding the @keep annotation to all data classes and adding a rule to keep everything in the models package, I also added these rules

-keep class kotlin.reflect.**

-keep class kotlin.Metadata { *; }

but still no luck, any idea what is going wrong or how to fix this ?

Sample Repo

Thanks in advance.

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

What turned out to be the issue is that R8 bundeled with AGP 7.0 (release with Android Studio - Arctic Fox) does not handle Kotlin metadata correctly for Kotlin 1.6.0.

If using Kotlin 1.6.0 (classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.0") with AGP 7.0, then R8 version 3.0.77 is required for shrinking Kotlin libraries and for using kotlin-reflect. Updating to AGP 7.0.4 is not enough, as that version is bundled with R8 3.0.76.

To use R8 3.0.77 add the following to your settings.gradle or settings.gradle.kts:

pluginManagement {
    buildscript {
        repositories {
            mavenCentral()
            maven {
                url = uri("https://storage.googleapis.com/r8-releases/raw")
            }
        }

        dependencies {
            classpath("com.android.tools:r8:3.0.77")
            classpath('com.google.guava:guava:30.1.1-jre')
        }
    }
}

Another option for AGP 7.0 is to use Kotlin 1.5.31.

Also consider aligning your version of kotlin-reflect with the version of the Kotlin compiler.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!