I am using Windows 11 machine and learning flutter for the first time and I am using it without Android Studio. I have installed and setup the android SDK manually. Added the SDK to path. Made an ANDROID_SDK_ROOT environment variable. Using the sdkmanager I have installed the "build-tools;33.0.1" "platforms;android-33" "platform-tools". I have added flutter sdk, platform-tools to path.
I have manually installed Gradle version 8.0.2 and added it to path as well.
Now I opened VS Code, opened the command palette and selected Flutter:New Project and then selecting Application.
I ran "flutter run" in the bash terminal but received the following error:
this is the error I get
Here is my gradle version:
gradle version 8.0.2
Flutter Doctor output:
I am using flutter without android studio
I have installed jdk version 19.0.2 and added that to path as well. Added JAVA_HOME variable in the environment.
I have tried changing the version of gradle in the gradle-wrapper.properties file:
Before the version was gradle-7.5-all.zip, so I simply changed it to gradle-8.0.2-all.zip, matching the one installed on my machine
Before the version was gradle-7.5-all.zip, so I simply changed it to gradle-8.0.2-all.zip, matching the one installed on my machine.
Due to this in my .gradle folder there are two subfolders made, which are 7.5 and 8.0.2.
I have tried deleting this folder and recompiling it, but it still doesn’t work.
I have searched the web and tried multiple solutions. I ran flutter clean
, flutter pub get
etc. etc. but none of them seem to work. What can I try next?
Here is my root/android/app/build.gradle
script:
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')
if (flutterVersionCode == null) {
flutterVersionCode = '1'
}
def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) {
flutterVersionName = '1.0'
}
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
android {
compileSdkVersion flutter.compileSdkVersion
ndkVersion flutter.ndkVersion
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
sourceSets {
main.java.srcDirs += 'src/main/kotlin'
}
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.example.sampleapp"
// You can update the following values to match your application needs.
// For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-gradle-build-configuration.
minSdkVersion flutter.minSdkVersion
targetSdkVersion flutter.targetSdkVersion
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
}
buildTypes {
release {
// TODO: Add your own signing config for the release build.
// Signing with the debug keys for now, so `flutter run --release` works.
signingConfig signingConfigs.debug
}
}
}
flutter {
source '../..'
}
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
}
I tried many solutions available on the internet, but none of them seem to work.
3
Answers
I don’t think upgrade gradle version is a good idea for this. Since flutter is a cross-platform frameword, it has some limit in use latest version of gradle.
So, I can give you some recommend to fix, hope this help you that downgrade java version and gradle version
As you can see, we have two build.gradle file seperately,
You should downgrade version in project/build.gradle
And in gradle-wrapper.properties, you should downgrade version, too
Then in terminal, you call
flutter clean
andflutter run
to build again.Hope this help
Try
flutter doctor -v
. This will give you much more detailed info about your environment.But I recommend you use Android Studio so that you don’t have to reinvent the wheel. It’s much easier to start out on and can save you a lot of time.
I just answered another guy with the same problem as yours, I guess it’s gonna work as it worked for me Check this , I answered