Understanding Gradle in Flutter Projects
FlutterPulseThis article was translated specially for the channel FlutterPulseYou'll find lots of interesting things related to Flutter on this channel. Don't hesitate to subscribe!🚀

Hello Flutter developers
Today I'm going to talk to you about a bit of a thorny topic 😂 God willing it will be simple and might help you solve a problem
Of course, it's Gradle. I don't need to know what it is because we all know what it is and we might hate it more than anything else 😂
- But first, we want to know what exactly the Android Folder does so we can get the topic up to speed.
= The function of this folder is to build your Android App properly. Well, that is through some files inside it, including,
for example, .gradle, which is responsible for some configs, and some other files that help it in the build process, such as gradle version, and gradle.properties tells you the size of this data, how much it will take in memory, and so on. We also have settings.gradle, which we will talk about in a moment. Finally, you have gradle, which is responsible for configs and some things that help in the build process.
= We have two types of Gradle:
App level: This is located in the app folder and is also responsible for app-level configurations, such as namespace and applicationId.
Project level: This is located under the android folder and is responsible for configurations specific to the entire project, such as setting specific classpaths for Google Services, AGP, etc.
= There are some configurations that can be placed outside of it in settings.gradle, such as kotlin version, for example.
Note: Gradle is written in Groovy, the standard language for Gradle, or KTS (Kotlin script).
This is found in new projects.
Now let's get to know AGP and its relationship to the Gradle version.
- Now, what is AGP and how does it relate to the gradle version?
= Basically, both create tasks specific to the build process and complement each other. Compatibility is required for the application to work with you.
- The gradle version is located in gradle-wrapper.properties.
We can say that it's the foundation of your application's build process.
- It creates tasks such as load plugins, and based on them, AGP is executed. Therefore, compatibility is required between them.
- AGP (Android Gradle Plugin) is placed at the gradle project level.
- What kind of tasks does it have?
- Such as packaging to APK and AAP, and possibly compiling and app signing.
The table in below somewhat illustrates the compatibility between them.

There's also a related topic I want to talk to you about, which is the namespace
found in app build.gradle. What does it do?
Basically, it appeared after AGP 7.0.0+, so you must add it.
Through it, you can uniquely identify app-level modules. It can also help you avoid multi-module project problems if you have more than one app within the project and manage them via setting.gradle. We'll talk about this in a bit.
There's also an error that occurs when you try to modify an old project and upgrade it to a newer SDK. It may say something like this for a specific plugin: "Namespace not specified. Please add a `namespace` property." This is because you used AGP 7.0.0+, which is already outdated. You must modify it within the package and add the namespace.
- Let's assume that you want to create multiple apps or modules. How will this happen?
First, you will add a new app folder and a new namespace, and consequently, a new activity. Therefore, the starting point of each one will be different, as you will know where each activity's starting point is, and they will look like this:

and then we can change android manifest.xml like this by adding new activity

by the previous code the customMainActivity is launch because it has intent filter

so we can say the activity which has intent filter will launch first and there is only one should has intent filter and we can determine which activity has the intent filter and launch by Flavors
they muliply apps will look like this

and we will connect everything by setting.gradle like this:

and will make changes in android/build.gradle by adding subprojects
This way, you will have multiple apps that you can put in the same project, and each one will have its own configurations without any problems.
and this article talks about multi gradle projects in detail
https://docs.gradle.org/current/userguide/intro_multi_project_builds.html
The last thing we'll talk about is the Java version (JDK) and the Kotlin version.
So, what are they for and what do they do?
Ultimately, their job is to compile native code, whether from plugins or the MainActivity class, whether in Java, Kotlin, or other languages.
And they must be compatible with the Gradle version, just like that.
Java 11–19 is safe for Flutter's default Gradle (7.x),
Java 17 with Gradle ≥ 7.3,
Java 21+ requires Gradle 8+.
These versions are downloaded with Android Studio, and you can change them if the version that provided you with Android Studio is not compatible with Gradl and so on.
Here you will find how to make compatibility between Kotlin version, AGP and Gradle.
Configure a Gradle project | KotlinTo build a Kotlin project with Gradle, you need to add the Kotlin Gradle plugin to your build script file…
kotlinlang.org
In conclusion, we can say that Kotlin version and Java version, and AGP and Gradle version must be compatible with each other. to launch your project correctly
I hope you benefited and tell me your opinion in the comments.