CPS251 Android Development by Scott Shaper

Change Log Page

Android Studio constantly updates and because of this I created this change log page to address the changes that may affect us.


Default MainActivity Change (added 2/18/2026)

The default MainActivity.kt file will need you to import the edge to edge function. This is to allow the app to display correctly on the new devices that have the edge to edge display.

This is the correct default MainActivity.kt file:

package com.example.bookexampleapp

    import android.os.Bundle
    import androidx.activity.ComponentActivity
    import androidx.activity.compose.setContent
    import androidx.activity.enableEdgeToEdge
    import androidx.compose.foundation.layout.fillMaxSize
    import androidx.compose.foundation.layout.padding
    import androidx.compose.material3.Scaffold
    import androidx.compose.material3.Text
    import androidx.compose.runtime.Composable
    import androidx.compose.ui.Modifier
    import com.example.bookexampleapp.ui.theme.BookExampleAppTheme
    
    class MainActivity : ComponentActivity() {
        override fun onCreate(savedInstanceState: Bundle?) {
            super.onCreate(savedInstanceState)
            enableEdgeToEdge()
            setContent {
                BookExampleAppTheme {
                    Scaffold(modifier = Modifier.fillMaxSize()) { innerPadding ->
                        Greeting(
                            name = "Android",
                            modifier = Modifier.padding(innerPadding)
                        )
                    }
                }
            }
        }
    }
    
    @Composable
    fun Greeting(name: String, modifier: Modifier = Modifier) {
        Text(
            text = "Hello $name!",
            modifier = modifier
        )
    }

Gradle File Change (add 3/18/2025)

This may not affect you but it appears as if we can no longer use:

compileSdkVersion = 35

We have to now do:

compileSdkVersion = "android-35"

The Android Gradle Plugin (AGP) 8.0 and later versions introduced a new format for specifying the compileSdkVersion in Android projects. This change requires the SDK version to be specified as a string with the format "android-XX" (e.g., "android-35" for Android 14) instead of just a number. This new format was introduced to better support different types of SDK versions, including preview versions, vendor-specific versions, and extended SDK versions. While the change was introduced in AGP 8.0, it became strictly enforced in later versions, particularly in AGP 8.9.0. The old format using just a number (e.g., compileSdkVersion 35) will no longer work in AGP 8.0 and above, and developers will need to update their build.gradle files to use the new string format. This change affects both Kotlin and Java Android projects, as it's a build system requirement rather than a language-specific change.

The change is part of Google's ongoing effort to modernize the Android build system and make it more flexible for future SDK releases. Developers using older versions of AGP (pre-8.0) can continue using the numeric format, but those upgrading to AGP 8.0 or later will need to adopt the new string format. This is particularly important for developers creating new projects with recent versions of Android Studio, as the IDE will automatically use the latest AGP version and enforce the new format.


Empty Views Activity Change (added around April of 2024)

The default Empty Views Activity has changed its code. The change happened with Android JellyFish. The MainActivityhas changed it includes the code shown below. In the examples for this book I do not use it because it is not needed for this class and has thus been removed.

enableEdgeToEdge()
setContentView(R.layout.activity_main)
ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main)) { v, insets ->
    val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars())
    v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom)
    insets
} 

Explaination of the code

The code snippet show above is used to adjust an Android application's UI to handle system bars in edge-to-edge display mode. This is typically used in modern Android development to ensure that the UI elements of the application seamlessly extend into the areas typically reserved for system UI elements like the navigation bar and the status bar. Let's break down the code piece by piece to understand it better:

Function Call enableEdgeToEdge()

This seems to be a custom function (not shown in the snippet), likely intended to set up the application window for an edge-to-edge experience. The typical operations in such a function would include setting system UI flags that allow the app content to extend into the system bars areas.

Set Content View

setContentView(R.layout.activity_main)

Apply Window Insets Listener

ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main)) { v, insets ->
    val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars())
    v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom)
    insets
}

Summary

The code is typically part of setting up an Android application to utilize a modern, immersive design where the app content extends behind system bars, using padding to ensure interactivity is not compromised. This setup is especially popular in apps that want to take full advantage of modern displays with minimal bezels, providing a more immersive user experience.