Android: Problem building Flutter project #11753
Labels
e2-days
Effort: < 5 days
from.page-issue
Reported in a reader-filed concern
p2-medium
Necessary but not urgent concern. Resolve when possible.
Page URL
https://docs.flutter.dev/deployment/android/
Page source
https://github.com/flutter/website/tree/main/src/content/deployment/android.md
Describe the problem
I have created a new Flutter project (using the
flutter create
command), which by default uses the gradle.kts (Kotlin DSL) configuration and does not use Groovy. However, when building the APK with the commandflutter build apk
, I encounter the following error:Environment and Setup:
gradle-wrapper.properties
)key.properties
.Steps and Changes Taken:
Plugin Setup:
android/app/build.gradle.kts
, I have the following plugins block:pluginManagement
block in mysettings.gradle.kts
, but the error persists.Changing Gradle and Plugin Versions:
plugins
block (e.g., version 8.0.2 for the Android plugin and 1.8.20 for the Kotlin plugin), but the issue is still unresolved.Kotlin Plugin Warning:
Server Issue:
Summary of the Problem:
Even though my project is created with gradle.kts by default, and I have not migrated or changed from Groovy, the main issue lies in not finding the
com.android.application
plugin during the build process. All typical fixes (setting plugins in thesettings
andbuild
files, changing Gradle and plugin versions, checking Android SDK and other settings) have been tried, but the problem still persists.Could you please guide me on whether there is a specific configuration required when using Flutter with Kotlin DSL, or if I’ve missed something in this configuration that might be causing the issue?
Thank you for your attention and assistance.
Best regards,
[Ramin ....
Expected fix
Expected Outcome:
My goal is for the
flutter build apk
process to complete successfully without encountering errors, especially the error regarding thecom.android.application
plugin not being found. I would like the build to finish without any issues so I can generate the APK for my Flutter project.Additional context
PS D:\afghan> flutter build apk
Flutter assets will be downloaded from https://storage.flutter_io.cn/. Make sure you trust this source!
FAILURE: Build failed with an exception.
Where:
Build file 'D:\afghan\android\app\build.gradle.kts' line: 4
What went wrong:
Plugin [id: 'com.android.application'] was not found in any of the following sources:
BUILD FAILED in 13s
Running Gradle task 'assembleRelease'... 14.2s
Gradle task assembleRelease failed with exit code 1
PS D:\afghan> cd android
PS D:\afghan\android> .\gradlew clean
Starting a Gradle Daemon, 2 incompatible and 2 stopped Daemons could not be reused, use --status for details
FAILURE: Build failed with an exception.
Where:
Build file 'D:\afghan\android\app\build.gradle.kts' line: 4
What went wrong:
Plugin [id: 'com.android.application'] was not found in any of the following sources:
BUILD FAILED in 9s
PS D:\afghan\android> flutter doctor
Flutter assets will be downloaded from https://storage.flutter_io.cn/. Make sure you trust this source!
Doctor summary (to see all details, run flutter doctor -v):
[√] Flutter (Channel stable, 3.29.0, on Microsoft Windows [Version 10.0.26100.3194], locale en-US)
[√] Windows Version (11 Pro 64-bit, 24H2, 2009)
[√] Android toolchain - develop for Android devices (Android SDK version 35.0.1)
[√] Chrome - develop for the web
[√] Visual Studio - develop Windows apps (Visual Studio Community 2022 17.12.4)
[√] Android Studio (version 2024.2)
[√] VS Code (version 1.97.2)
[√] Connected device (3 ava
//android/app/build.gradle.kts
import java.util.Properties
import java.io.FileInputStream
plugins {
id("com.android.application")
id("kotlin-android")
id("dev.flutter.flutter-gradle-plugin")
}
val keystoreProperties = Properties()
val keystorePropertiesFile = rootProject.file("key.properties")
if (keystorePropertiesFile.exists()) {
keystoreProperties.load(FileInputStream(keystorePropertiesFile))
}
android {
namespace = "com.example.my_now"
compileSdk = flutter.compileSdkVersion
ndkVersion = flutter.ndkVersion
}
flutter {
source = "../.."
}
dependencies {
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8:2.0.20")
}
// settings.gradle.kts
pluginManagement {
val flutterSdkPath = run {
val properties = java.util.Properties()
file("local.properties").inputStream().use { properties.load(it) }
val flutterSdkPath = properties.getProperty("flutter.sdk")
require(flutterSdkPath != null) { "flutter.sdk not set in local.properties" }
flutterSdkPath
}
}
include(":app")
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https://services.gradle.org/distributions/gradle-8.4-bin.zip
//key.properties
storePassword=#####
keyPassword=######
keyAlias=upload
storeFile=$env:android/upload-keystore.jks
I would like to fix this problem.
The text was updated successfully, but these errors were encountered: