I’m working on a Flutter project and trying to run it on an Android emulator. However, I’m encountering an issue when I try to build the project using Gradle. The build fails with the following error:
My file app/build.gradle:
plugins {
id 'com.android.application'
id 'org.jetbrains.kotlin.android'
// id 'com.google.gms.google-services'
}
def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
localPropertiesFile.withReader('UTF-8') { reader ->
localProperties.load(reader)
}
}
def flutterRoot = localProperties.getProperty('flutter.sdk')
if (flutterRoot == null) {
throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
}
def flutterVersionCode = localProperties.getProperty('flutter.versionCode') ?: '1'
def flutterVersionName = localProperties.getProperty('flutter.versionName') ?: '1.0'
def keystoreProperties = new Properties()
def keystorePropertiesFile = rootProject.file('key.properties')
if (keystorePropertiesFile.exists()) {
keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
}
android {
namespace 'com.semenov.canada'
compileSdkVersion 34
defaultConfig {
applicationId "com.semenov.canada"
minSdkVersion 21
targetSdkVersion 34
versionCode 1
versionName "1.0"
// versionCode flutterVersionCode.toInteger()
// versionName flutterVersionName
manifestPlaceholders = [applicationName: "com.semenov.canada"]
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
sourceSets {
main.java.srcDirs += 'src/main/kotlin'
}
signingConfigs {
release {
keyAlias keystoreProperties['keyAlias']
keyPassword keystoreProperties['keyPassword']
storeFile keystoreProperties['storeFile'] ? file(keystoreProperties['storeFile']) : null
storePassword keystoreProperties['storePassword']
}
}
buildTypes {
release {
signingConfig signingConfigs.release
}
}
}
//flutter {
// source '/Users/skv/Apps/Apps/canada'
//}
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
}
My file android/build.gradle:
buildscript {
ext.kotlin_version = '2.0.20'
repositories {
google()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle-kotlin:8.5.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
allprojects {
repositories {
google()
mavenCentral()
}
}
rootProject.buildDir = '../build'
subprojects {
project.buildDir = "${rootProject.buildDir}/${project.name}"
}
subprojects {
project.evaluationDependsOn(':app')
}
tasks.register("clean", Delete) {
delete rootProject.buildDir
}
Please help. I don’t know what else to change to get the project running. I’ve already lost a week on this.
I tried to fix the error: ‘You are applying Flutter’s app_plugin_loader Gradle plugin imperatively using the apply script method, which is deprecated and will be removed in a future release. Migrate to applying Gradle plugins with the declarative plugins block.’ I changed the build.gradle files, versions, and ended up breaking everything.
2
Answers
Gradle version in some projects is like this
You must follow this documentation
You have command lines to delete from both gradle files.