简体   繁体   中英

NullPointer in Kotlin Synthetics for some views with Jetpack Compose Integration

I am trying to integrate the new jetpack compose in my existing app. My app is right now dependent on kotlin synthetics. When I tried to integrate compose, I am getting NullPointerException in some Kotlin synthetics while trying to access views. Here is my code

    internal const val compose = "1.0.0-beta07"
    internal const val activityCompose = "1.3.0-alpha03"
    internal const val kotlinVersion = "1.4.32"
kotlinOptions {
        jvmTarget = '1.8'
    }

    buildFeatures {
        compose true
    }

    composeOptions {
        kotlinCompilerVersion "${Versions.kotlinVersion}"
        kotlinCompilerExtensionVersion "${Versions.compose}"
    }
    const val composeUI = "androidx.compose.ui:ui:${Versions.compose}"

    const val activityCompose = "androidx.activity:activity-compose:${Versions.activityCompose}"
    const val materialCompose = "androidx.compose.material:material:${Versions.compose}"
    const val toolingCompose = "androidx.compose.ui:ui-tooling:${Versions.compose}"

But when I remove below Code it works well. Also I tried with view binding it is working fine.

 buildFeatures {
        compose true
    }

What can be the problem here?

@Fixit "Yes I know it is deprecated but I can't move all my code to view binding at once. Can't we use both compose and synthetics together."

If you are planning to postpone ViewBinding migration, you can use this gradle task to generate Kotlin snythetic code without the "Kotlin android extensions" plugin

https://github.com/sanjeevirajm/kotlin_synthetic_undepreciated

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM