I have been working on a Flutter application that I've successfully run on both an Android emulator and a physical device during the past couple of weeks. Somehow and all of a sudden, I'm unable to run it in debug mode. I tried several answers found in SO but they all seem to be hacks that don't really fix the issue.
The Error
When I tried to run the application, an error is thrown from Gradle daemon because it could not create a JVM as seen in the screenshot below...
Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.
Unrecognized option: --add-opens
Possible cause???
I remember I upgraded the Gradle Plugin to I-don't-know-what-version, I wasn't really paying attention to it (my bad) but I kept on working without any issues. Then, I upgrade Flutter to version 2.2.2, that's when the issue started to creeping in (Maybe).
Supporting Info
OS: Windows Server 2016 Standard (x64)
IDE: Android Studio Artic Fox 2020.3.1
Flutter Version: 2.2.2
JAVA_HOME: Pointing to JDK 1.8
Project Structure -> Project Settings -> Project
Gradle files
android/build.gradle
buildscript {
ext.kotlin_version = '1.3.50'
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:4.1.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
allprojects {
repositories {
google()
jcenter()
}
}
rootProject.buildDir = '../build'
subprojects {
project.buildDir = "${rootProject.buildDir}/${project.name}"
project.evaluationDependsOn(':app')
}
task clean(type: Delete) {
delete rootProject.buildDir
}
app/build.gradle
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 30
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.domain.app_name"
minSdkVersion 16
targetSdkVersion 30
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"
}
Question
Is there an obvious fix to the error?
I haven't worked on Android for about 2 years since I started this project so it might be possible that my problem is quite obvious. I might be missing something here but if I am, please let me know and I'll update the answer.
from Flutter error in Android Studio (Windows): Unrecognized option: --add-opens


No comments:
Post a Comment