1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

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

Posted at

環境

  • Android Studio Ladybug Feature Drop | 2024.2.2
  • Flutter 3.27系

build.gradle(Project)

以下のエラーを解消する

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対応
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)

下記エラーの対応

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の追加
 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で以下が追加される
+ android.defaults.buildfeatures.buildconfig=true
+ android.nonTransitiveRClass=false
+ android.nonFinalResIds=false

参考

1
0
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
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?