Upgrading Android TargetSDKVersion to 35 in Kotlin Project


As required by Google, our Android app must now target Android 15 (API level 35) or higher. After spending an entire day upgrading the code, I finally got it working! I’d like to share my experience to help anyone else who might be struggling with this transition.

Environment:

- MAC OS: Sonoma 14.5

- Android Studio: Narwhal

- Gradle Version: 8.13

- Android Gradle Plugin Version: 8.11.0

- TargetSDKVersion: 35

- MinSDKVersion: 24

Due to using Gradle version above 8.0, there are several points we need to follow:

  1. Manifest.xml:
  • Remove attribute “package”, this attribute is no longer used to specify the application's namespace. Instead, the namespace property in the build.gradle file should be used to declare the namespace.

Add code in build.gradle.kts (app):

android {

     namespace = “com.your_company.main_app”

     defaultConfig {
         applicationId = “com.your_company.app_name”
     }
} 
  • Changes in how Google Mobile Ads handles Ad Services configuration, be rised this error “resource xml/gma_ad_services_config not found”, let fix by adding this code inside application tag:

      <property
      android:name="android.adservices.AD_SERVICES_CONFIG"
      android:resource="@xml/gma_ad_services_config"
      tools:replace="android:resource" />
    
  1. The jcenter() repository is deprecated and should be replaced with mavenCentral(). JFrog deprecated JCenter in February 2021, with a full shutdown planned for February 2022. Add these following codes to fix missing libs:

    buildscript {
     repositories {
       gradlePluginPortal()
       google()
       mavenCentral()
       maven { url = uri("https://jitpack.io") }
       maven { url = uri("https://android-sdk.is.com/") }
       maven { url = uri("https://maven.aliyun.com/repository/public" )}
       maven { url = uri("https://maven.aliyun.com/repository/apache-snapshots" )}
     }
     dependencies {
       classpath("com.android.tools.build:gradle:8.11.0")
       classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.9.0")
       classpath("com.google.gms:google-services:4.3.3")
     }
    }
    allprojects {
     repositories {
       gradlePluginPortal()
       google()
       maven { url = uri("https://jitpack.io") }
       maven { url = uri("https://android-sdk.is.com/") }
       mavenCentral()
       maven { url = uri("https://maven.aliyun.com/repository/public" )}
       maven { url = uri("https://maven.aliyun.com/repository/apache-snapshots" )}
     }
    }
    

After applying the changes mentioned above, I was able to successfully sync, build, and run the app on a real device. While there are still some warnings due to the upgrade, I don’t consider them critical—just minor adjustments that can be resolved with a bit of attention and adaptation. I hope this helpful to you guys.

0
Jul 16 at 5:04 AM
User AvatarBinh Le
#android#kotlin#android-gradle-plugin#build.gradle#targetsdkversion

No answer found for this question yet.