3
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Android、kotlinでViewBindingがエラーになる

Last updated at Posted at 2023-06-23

今日からViewBindingがエラーになる・・・?

今まで普通にViewBinding使えていたのに、今日、新規プロジェクトを作成するとViewBindingがエラーになる。kotlinソース的には何も変わらないのに・・・

build.gradle
android {
    ・・・
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_17
        targetCompatibility JavaVersion.VERSION_17
    }
    kotlinOptions {
        jvmTarget = '17'
    }
    viewBinding {
        enabled = true
    }
    ・・・
}
binding = ActivityMainBinding.inflate(layoutInflater)
Error in ViewBinding in Kotlin, Error is to check module classpath for missing or conflicting dependancies

stackOverFlowにも情報があった。

以前に作ったプロジェクトと比較するとgradle.propertiesに差異がある。

gradle.properties
- android.defaults.buildfeatures.buildconfig=true
- android.nonFinalResIds=false

この2行がない。この辺の新規プロジェクトで作成される雛形はAndroidStudioをアップデートすると結構頻繁に変わる。

上の2行を追加してgradleを同期。出たくなった。
試しにまた削除して、gradleを同期。エラーが出ない??!!

この2行は何なのか?AGP(Android Gradle Plugin)8.0に関係しているらしい。

  • android.defaults.buildfeatures.buildconfig
    • AGP 8.0 は、デフォルトでは BuildConfig を生成しません。このオプションは、必要なプロジェクトで DSL を使用して指定する必要があります。
  • android.nonFinalResIds
    • AGP 8.0 は、デフォルトで非最終フィールドを持つ R クラスを生成します。

なーんか、ちょっと釈然としないんだけど・・・
どなたか、この辺の事情に詳しい方、解説お願いします。

3
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?