Skip to content

Using build.gradle File in New Android Studio Project

In the newer version of Android Studio projects (After February 2022 update), there has been change in the structure of build.gradle file and there is not much information available on how to update build.gradle for new projects.

I recently faced this issue, I was trying to integrate Google Analytics in an Android project and the Google documentation was showing the build.gradle file changes for older version. Here I will take reference from same problem and show you how you can update old file structure to the newer one.

Here is the Google Analytics for Android application documentation shows the gradle setting, which is using the older format:

GA for Android gradle setting

Now if you see the build.gradle file for project or app level, you won’t see this structure, so here are few points:

For the project level build.gradle, latest version after February 2022 doesn’t need to add buildscript anymore, and also we can’t add classpath. For that we can just add id with version, just like below:

id 'com.google.gms.google-services' version '4.3.3' apply false

Repository is moved to settings.gradle file, so to add any new repository, you can use this file.

After all these changes, Google Analytics for Android will have following gradle setting:

New Gradle file structure

That’s all for now.

Be First to Comment

Leave a Reply

Your email address will not be published.