Unresolved reference: BuildConfig

Android Gradle Plugin (AGP) 8.0 以降、BuildConfig ファイルの生成はデフォルトで無効になっており、必要なモジュールに対してのみ手動で有効にする必要があります。

モジュール別であれば、


// build.gradle.kts

android {
  buildFeatures {
    buildConfig = true
  }
}

すべてのモジュールに適用する場合は以下。


# gradle.properties

android.defaults.buildfeatures.buildconfig=true

Unresolved reference: BuildConfig



Android Studio Giraffe | 2022.3.1 の dependencies の揃え方

Android Studio Giraffe | 2022.3.1 の dependencies の揃え方Android Studio Giraffe | 2022.3.1 の dependencies の揃え方

Version Catalog + libs.versions.toml で説明します。

まず最初に、Android GradlePlugin と API バージョンを確認します。


👉 Android Studio Flamingo | 2022.2.1  |  Android Developers hatena-bookmark


Giraffe | 2022.3.1	
AGP 8.1	
API  33

これから、


com.android.tools.build.gradle-8.1.0

👉 Google's Maven Repository hatena-bookmark


# libs.versions.toml

[versions]
android-gradle-plugin = "8.1.0"

[plugins]
android-application = { id = "com.android.application", version.ref = "android-gradle-plugin" }


// build.gradle (root)

android {
  def sdkVersion = 33

  compileSdk sdkVersion
  defaultConfig {
    targetSdk sdkVersion
  }
}

が決まります。

また、Kotlin のバージョンを 1.9.0 にあげることができるので、

Android Studio Giraffe | 2022.3.1 の dependencies の揃え方
👉 Compose to Kotlin Compatibility Map  |  Android Developers hatena-bookmark

Compose Compiler のバージョンも 1.5.0 にあげることができました。

 

◾️ まとめ

大きいところで以下の3つをアップグレードすることができました。


[versions]

android-gradle-plugin = "8.1.0"

kotlin = "1.9.0"

compose-compiler = "1.5.0"

少し触った雰囲気、Android Studio Giraffe は、かなり起動やビルド時間が短くなっているように感じます。

👉 【Plugin DSL】Android Gradle Plugin のバージョンを調べる方法 hatena-bookmark
👉 【Plugin DSL】「com.android.tools.build:gradle」の記述は不要? hatena-bookmark



【Android Studio】[File] - [Project Structure] - [Suggestions] で「Update」する dependencies の妥当性 💉

Suggestions に表示されてるので Update する。

androidx.navigation:navigation-compose が 2.7.0-beta02 で NG だが 2.7.0-beta01 で OK な件


androidx.navigation:navigation-compose:2.7.0-beta01

  ↓

androidx.navigation:navigation-compose:2.7.0-beta02

はい、NG です。

androidx.navigation:navigation-compose が 2.7.0-beta02 で NG だが 2.7.0-beta01 で OK な件

なんでや!?

 

💉 エラーメッセージ 「5 issues were found when checking AAR metadata」

エラーメッセージを見てみる。


5 issues were found when checking AAR metadata:


  1.  Dependency 'androidx.navigation:navigation-common:2.7.0-beta02' requires libraries and applications that
      depend on it to compile against version 34 or later of the
      Android APIs.

      :app is currently compiled against android-33.

      Also, the maximum recommended compile SDK version for Android Gradle
      plugin 8.0.1 is 33.

      Recommended action: Update this project's version of the Android Gradle
      plugin to one that supports 34, then update this project to use
      compileSdk of at least 34.

      Note that updating a library or application's compileSdk (which
      allows newer APIs to be used) can be done separately from updating
      targetSdk (which opts the app in to new runtime behavior) and
      minSdk (which determines which devices the app can be installed
      on).


  2.  Dependency 'androidx.navigation:navigation-runtime:2.7.0-beta02' requires libraries and applications that
      depend on it to compile against version 34 or later of the
      Android APIs.

      :app is currently compiled against android-33.

      Also, the maximum recommended compile SDK version for Android Gradle
      plugin 8.0.1 is 33.

      Recommended action: Update this project's version of the Android Gradle
      plugin to one that supports 34, then update this project to use
      compileSdk of at least 34.

      Note that updating a library or application's compileSdk (which
      allows newer APIs to be used) can be done separately from updating
      targetSdk (which opts the app in to new runtime behavior) and
      minSdk (which determines which devices the app can be installed
      on).

  3.  Dependency 'androidx.navigation:navigation-common-ktx:2.7.0-beta02' requires libraries and applications that
      depend on it to compile against version 34 or later of the
      Android APIs.

      :app is currently compiled against android-33.

      Also, the maximum recommended compile SDK version for Android Gradle
      plugin 8.0.1 is 33.

      Recommended action: Update this project's version of the Android Gradle
      plugin to one that supports 34, then update this project to use
      compileSdk of at least 34.

      Note that updating a library or application's compileSdk (which
      allows newer APIs to be used) can be done separately from updating
      targetSdk (which opts the app in to new runtime behavior) and
      minSdk (which determines which devices the app can be installed
      on).

  4.  Dependency 'androidx.navigation:navigation-runtime-ktx:2.7.0-beta02' requires libraries and applications that
      depend on it to compile against version 34 or later of the
      Android APIs.

      :app is currently compiled against android-33.

      Also, the maximum recommended compile SDK version for Android Gradle
      plugin 8.0.1 is 33.

      Recommended action: Update this project's version of the Android Gradle
      plugin to one that supports 34, then update this project to use
      compileSdk of at least 34.

      Note that updating a library or application's compileSdk (which
      allows newer APIs to be used) can be done separately from updating
      targetSdk (which opts the app in to new runtime behavior) and
      minSdk (which determines which devices the app can be installed
      on).

  5.  Dependency 'androidx.navigation:navigation-compose:2.7.0-beta02' requires libraries and applications that
      depend on it to compile against version 34 or later of the
      Android APIs.

      :app is currently compiled against android-33.

      Also, the maximum recommended compile SDK version for Android Gradle
      plugin 8.0.1 is 33.

      Recommended action: Update this project's version of the Android Gradle
      plugin to one that supports 34, then update this project to use
      compileSdk of at least 34.

      Note that updating a library or application's compileSdk (which
      allows newer APIs to be used) can be done separately from updating
      targetSdk (which opts the app in to new runtime behavior) and
      minSdk (which determines which devices the app can be installed
      on).

長いですが要するに、


androidx.navigation:navigation-compose:2.7.0-beta02

が依存している以下、


androidx.navigation:navigation-common:2.7.0-beta02
androidx.navigation:navigation-runtime:2.7.0-beta02
androidx.navigation:navigation-common-ktx:2.7.0-beta02
androidx.navigation:navigation-runtime-ktx:2.7.0-beta02

は、


Android API 34

以上を必要としているので使えません。

ということのよう。

 

💉 なぜ私は、Android API 33 だったけか

「Flamingo」なのでそれが最新安定版。

androidx.navigation:navigation-compose が 2.7.0-beta02 で NG だが 2.7.0-beta01 で OK な件

Android Studio Flamingo | 2022.2.1 を使ってる場合、33 までです。

👉 Android Studio Flamingo | 2022.2.1  |  Android Developers hatena-bookmark

 

💉 まとめ

Android Studio の Suggestion ダイアログ

androidx.navigation:navigation-compose が 2.7.0-beta02 で NG だが 2.7.0-beta01 で OK な件


[File]

  |

[Project Structue]

  |

[Suggestions]

は、Android Studio までを含めた全ての依存性を考慮していない

Version Catalog (toml) ですが、なんだか不便です。

👉 【Android Studio Flamingo】dependencies をバージョンアップデートするときに確認するべき3つの相性 hatena-bookmark