0

I am trying to update an existing app to target SDK 33. The project currently has the following in the project build.gradle file.

ext {
compileSdkVersion = 30
targetSdkVersion = 30
// more stuff
}

The module app/build.gradle file has this

android {
    // more stuff    
    compileSdkVersion rootProject.ext.compileSdkVersion

    defaultConfig {
        // more stuff
        targetSdkVersion 30

    }

I am going to change the compileSdkVersion and targetSdkVersion values in the project build.gradle file to 33. I see where the module app/build.gradle file references the compileSdkVersion value in the project build.gradle file. Is there a way to do the same with the targetSdkVersion value? Or do I need to manually set it to 33? What happens if I leave the targetSdkVersion value at 30 in the module app/build.gradle file?

ponder275
  • 903
  • 2
  • 12
  • 33

1 Answers1

1

To set compileSdkVersion and targetSdkVersion to 33:

ext {
    compileSdkVersion = 33
    targetSdkVersion = 33
    // more stuff
}

To use the references from project build.gradle file for compileSdkVersion and targetSdkVersion:

android {
    // more stuff    
    compileSdkVersion rootProject.ext.compileSdkVersion

    defaultConfig {
        // more stuff
        targetSdkVersion rootProject.ext.targetSdkVersion

    }
...

Here the answer about the difference between compileSdkVersion and targetSdkVersion, I recommend you to have both of these values the same

easy_breezy
  • 1,073
  • 7
  • 18
  • Thanks! Do you know which value would be used if the `targetSdkVersion` is different in the project `build.gradle` and the module `app/build.gradle` files? – ponder275 May 02 '23 at 13:18
  • 1
    @ponder275 will be used the value from app/build.gradle, because project build.gradle doesn't have "android {...}" block but can have "ext {...}" block which is used as a constants storage like in your case – easy_breezy May 02 '23 at 14:14