Android Studio Otter: Can't run fun main() in Android module — “SourceSet 'main' not found”

1 day ago 7
ARTICLE AD BOX

After updating Android Studio to Otter (2025.2.1 Patch 1), I can no longer run simple Kotlin fun main() functions inside my standard Android app module (:app). This worked perfectly in Narwhal.

When I run this code via the gutter icon:

package com.example.sample fun main() { println("Hello") }

I get the following error:

Initialization script '...' line: 27 A problem occurred configuring project ':app'. > Could not create task ':app:com.example.sample.HelloKt.main()'. > SourceSet with name 'main' not found.

Script causing the error (line 27 shown below):

# line 27 (the failing line) classpath = project.sourceSets[sourceSetName].runtimeClasspath

Full context:

def gradleProjectId = 'Sample:app' def runAppTaskName = 'com.example.sample.HelloKt.main()' def mainClassToRun = 'com.example.sample.HelloKt' def javaExePath = '/Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java' def _workingDir = '/Users/XXXXX/AndroidStudioProjects/Sample' def sourceSetName = 'main' def isOlderThan64 = GradleVersion.current().getBaseVersion().compareTo(GradleVersion.version("6.4")) < 0 allprojects { afterEvaluate { project -> if (project.rootProject.name + project.path == gradleProjectId) { def overwrite = project.tasks.findByName(runAppTaskName) != null project.tasks.create(name: runAppTaskName, overwrite: overwrite, type: JavaExec) { if (javaExePath) executable = javaExePath if (project.pluginManager.hasPlugin("org.jetbrains.kotlin.multiplatform")) { project.kotlin.targets.each { target -> target.compilations.each { compilation -> if (compilation.defaultSourceSetName == sourceSetName) { classpath = compilation.output.allOutputs + compilation.runtimeDependencyFiles } } } } else { classpath = project.sourceSets[sourceSetName].runtimeClasspath } if (isOlderThan64) { main = mainClassToRun } else { mainClass = mainClassToRun } if(_workingDir) workingDir = _workingDir standardInput = System.in } } } }

What I noticed

“Run with Coverage” works, so the class (com.example.sample.HelloKt) and classpath are correct.

Otter seems to generate a temporary Gradle task to run the function, and that task fails because Android modules don't have a standard JVM main SourceSet.

What I tried (none worked)

Invalidated caches, deleted .gradle & .idea

Reset all Run Configurations

Manual “Kotlin” Run Configuration

Main class: com.example.sample.HelloKt

Module classpath: :app
→ Fails with: “Class ... not found in module ...”

Adding id("application") to app/build.gradle.kts
→ Fails due to Android plugin vs Java plugin conflict

Question

Is there a way (an IDE setting or a Gradle workaround) to force Android Studio Otter to run this fun main() as a simple Kotlin/JVM application, without generating the failing temporary Gradle task?

Read Entire Article