Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 39 additions & 14 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ if (project.hasProperty("release")) {
}

val ideaVersion = providers.gradleProperty("ideaVersion").get()
val intellijIdeaVersion = providers.gradleProperty("intellijIdeaVersion").get()
val platformType = providers.gradleProperty("platformType").getOrElse("AS")
val dartPluginVersion = providers.gradleProperty("dartPluginVersion").get()
val sinceBuildInput = providers.gradleProperty("sinceBuild").get()
val untilBuildInput = providers.gradleProperty("untilBuild").get()
Expand All @@ -79,7 +81,9 @@ group = "io.flutter"

// For debugging purposes:
println("flutterPluginVersion: $flutterPluginVersion")
println("platformType: $platformType")
println("ideaVersion: $ideaVersion")
println("intellijIdeaVersion: $intellijIdeaVersion")
Comment thread
cj-radcliff marked this conversation as resolved.
println("dartPluginVersion: $dartPluginVersion")
println("sinceBuild: $sinceBuildInput")
println("untilBuild: $untilBuildInput")
Expand Down Expand Up @@ -142,6 +146,21 @@ sourceSets {
"third_party/vmServiceDrivers"
)
)
if (platformType == "IC") {
// Option 1 experiment: keep AS-specific code in src and exclude for IC builds.
java.exclude(
listOf(
"io/flutter/FlutterStudioStartupActivity.java",
"io/flutter/actions/OpenAndroidModule.java",
"io/flutter/android/AndroidStudioGradleSyncProvider.java",
"io/flutter/utils/AddToAppUtils.java",
"io/flutter/utils/AndroidLocationProvider.java",
"io/flutter/utils/FlutterExternalSystemTaskNotificationListener.java",
"io/flutter/utils/GradleUtils.java",
"org/jetbrains/android/facet/AndroidFrameworkDetector.java"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The path org/jetbrains/android/facet/AndroidFrameworkDetector.java is included in the exclusion list. This class is part of the Android plugin, not a source file within this project. Including it here is incorrect and confusing, and it should be removed. The reflective access to this class in ProjectOpenActivity.java is the correct way to handle the optional dependency.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was the intended fix.

)
)
}
kotlin.srcDirs(
listOf(
"src",
Expand Down Expand Up @@ -201,8 +220,13 @@ dependencies {
// Documentation on the default target platform methods:
// https://plugins.jetbrains.com/docs/intellij/tools-intellij-platform-gradle-plugin-dependencies-extension.html#default-target-platforms
// Android Studio versions can be found at: https://plugins.jetbrains.com/docs/intellij/android-studio-releases-list.html
// IntelliJ IDEA CE versions can be found at: https://www.jetbrains.com/idea/download/other.html
try {
androidStudio(ideaVersion)
if (platformType == "IC") {
intellijIdeaCommunity(intellijIdeaVersion)
} else {
androidStudio(ideaVersion)
}
} catch (e: Exception) {
throw GradleException(
"Failed to resolve Android Studio / IDEA download URL. This is likely due to a network issue blocking the download URL. Please check your internet connection or VPN.",
Expand All @@ -216,20 +240,21 @@ dependencies {
// Plugin dependency documentation:
// https://plugins.jetbrains.com/docs/intellij/tools-intellij-platform-gradle-plugin-dependencies-extension.html#plugins
// https://plugins.jetbrains.com/docs/intellij/plugin-dependencies.html#project-setup
bundledPlugins(
immutableListOf(
"com.intellij.java",
"com.intellij.properties",
"JUnit",
"Git4Idea",
"org.jetbrains.kotlin",
"org.jetbrains.plugins.gradle",
"org.jetbrains.plugins.yaml",
"org.intellij.intelliLang",
"org.jetbrains.android",
"com.android.tools.idea.smali"
)
val commonPlugins = immutableListOf(
"com.intellij.java",
"com.intellij.properties",
"JUnit",
"Git4Idea",
"org.jetbrains.kotlin",
"org.jetbrains.plugins.gradle",
"org.jetbrains.plugins.yaml",
"org.intellij.intelliLang"
)
if (platformType == "AS") {
bundledPlugins(commonPlugins + listOf("org.jetbrains.android", "com.android.tools.idea.smali"))
} else {
bundledPlugins(commonPlugins)
}
plugin("Dart:$dartPluginVersion")

if (sinceBuildInput == "243" || sinceBuildInput == "251") {
Expand Down
4 changes: 4 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@
#

ideaVersion=2025.2.3.9
intellijIdeaVersion=2025.2.6.1
dartPluginVersion= 503.0.0
# Set to IC to run against IntelliJ IDEA Community instead of Android Studio.
# Usage: .\gradlew runIde -PplatformType=IC
platformType=AS
# Also update the versions for verify checks in tool/github.sh.
sinceBuild=251
untilBuild=261.*
Expand Down
12 changes: 8 additions & 4 deletions src/io/flutter/ProjectOpenActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

import com.intellij.framework.FrameworkType;
import com.intellij.framework.detection.DetectionExcludesConfiguration;
import com.intellij.ide.plugins.IdeaPluginDescriptor;
import com.intellij.ide.plugins.PluginManagerCore;
import com.intellij.notification.Notification;
import com.intellij.notification.NotificationType;
Expand All @@ -29,7 +28,8 @@
import io.flutter.sdk.FlutterSdk;
import io.flutter.utils.AndroidUtils;
import io.flutter.utils.FlutterModuleUtils;
import org.jetbrains.android.facet.AndroidFrameworkDetector;
// AndroidFrameworkDetector is loaded reflectively to avoid a compile-time dependency on
// org.jetbrains.android, which is only bundled in Android Studio (not IntelliJ IDEA CE).
import org.jetbrains.annotations.NotNull;

import java.util.Collection;
Expand Down Expand Up @@ -93,21 +93,25 @@ private static void excludeAndroidFrameworkDetector(@NotNull Project project) {
if (FlutterUtils.isAndroidStudio()) {
return;
}
IdeaPluginDescriptor desc;
if (PluginManagerCore.getPlugin(PluginId.getId("org.jetbrains.android")) == null) {
return;
}
try {
final DetectionExcludesConfiguration excludesConfiguration = DetectionExcludesConfiguration.getInstance(project);
try {
final FrameworkType type = new AndroidFrameworkDetector().getFrameworkType();
final Class<?> detectorClass = Class.forName("org.jetbrains.android.facet.AndroidFrameworkDetector");
final Object detector = detectorClass.getDeclaredConstructor().newInstance();
final FrameworkType type = (FrameworkType)detectorClass.getMethod("getFrameworkType").invoke(detector);
if (!excludesConfiguration.isExcludedFromDetection(type)) {
excludesConfiguration.addExcludedFramework(type);
}
}
catch (NullPointerException ignored) {
// If the Android facet has not been configured then getFrameworkType() throws a NPE.
}
catch (ReflectiveOperationException ignored) {
// AndroidFrameworkDetector could not be loaded reflectively.
}
}
catch (NoClassDefFoundError ignored) {
// This should never happen. But just in case ...
Expand Down
Loading