Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

167
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda