AGP8系対応でやったことまとめ

## 環境
- Android Studio Ladybug Feature Drop | 2024.2.2
- Flutter 3.27系
## build.gradle(Project)
以下のエラーを解消する
```console
Namespace not specified. Specify a namespace in the module's build file. See https://d.android.com/r/tools/upgrade-assistant/set-namespace for information about setting the namespace. If you've specified the package attribute in the source AndroidManifest.xml, you can use the AGP Upgrade Assistant to migrate to the namespace value in the build file. Refer to https://d.android.com/r/tools/upgrade-assistant/agp-upgrade-assistant for general information about using the AGP Upgrade Assistant.
```
- `jcener`が非推奨なため`mavenCentral`に置き換え
- AGP8系へ移行(Android StudioでAndroidフォルダを開き`[Tools]` > `[AGP Upgrade Assistant]`でアップデート)
- namespace対応
```diff_gradle
buildscript {
    ext.kotlin_version = '1.9.20'
    repositories {
        google()
+       mavenCentral()
-       jcenter()
    }

    dependencies {
-       classpath 'com.android.tools.build:gradle:7.4.1'
+       classpath 'com.android.tools.build:gradle:8.2.2' // [Tools] > [AGP Upgrade Assistant]でアップデート私は8.2.2にしました
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
-       classpath 'com.google.gms:google-services:4.3.8'
+       classpath 'com.google.gms:google-services:4.4.2'  // 推奨バージョンがエディタに出ていたので更新
    }
}

 allprojects {
     repositories {
         google()
-        jcenter() //非推奨
+        mavenCentral()
     }
+    // namespaceが必要になったためその対応
+    subprojects {
+        afterEvaluate { project ->
+            if (project.hasProperty('android')) {
+                project.android {
+                    if (namespace == null) {
+                        namespace project.group
+                    }
+                }
+            }
+        }
     }
 }
```

## build.gradle(Module)
下記エラーの対応
```console
Inconsistent JVM-target compatibility detected for tasks 'compileDevelopDebugJavaWithJavac'  (1.8) and 'compileDevelopDebugKotlin'  (17) ``` Execution failed for task ':app:compileDevelopDebugKotlin' .  > Inconsistent JVM-target compatibility detected for tasks 'compileDevelopDebugJavaWithJavac'  (1.8) and 'compileDevelopDebugKotlin'  (17).
```
- 非推奨の`compileSdkVersion` => `compileSdk`
- Javaのバージョンを変更
- `kotlinOption`追加
- `jvmTarget`の追加
```diff_gradle
 android {
-    compileSdkVersion 34 // 非推奨な書き方
+    compileSdk 34
 
     compileOptions {
-        sourceCompatibility JavaVersion.VERSION_1_8
-        targetCompatibility JavaVersion.VERSION_1_8
+        sourceCompatibility JavaVersion.VERSION_17
+        targetCompatibility JavaVersion.VERSION_17
     }

+    kotlinOptions {
+        jvmTarget = "17"
+        // jvmTarget = JavaVersion.VERSION_17.toString()でもいいと思います
+    }

+    kotlin {
+        jvmToolchain(17)
+     }
+    namespace 'com.example.sample.hoge' // namespaceを追加
```
## android/gradle.properties
- AGP Upgrade Assistantで以下が追加される
```diff_properties
+ android.defaults.buildfeatures.buildconfig=true
+ android.nonTransitiveRClass=false
+ android.nonFinalResIds=false
```
## 参考
https://developer.android.com/build/releases/past-releases/agp-8-0-0-release-notes?hl=ja#default-changes

https://minpro.net/namespace-not-specified

https://qiita.com/kilalabu/items/5289fd216c71e1f2d3ed

https://github.com/jonataslaw/VideoCompress/issues/255