Code: Select all
:appWenn ich diesen Code über das Leistensymbol ausführe:
Code: Select all
package com.example.sample
fun main() {
println("Hello")
}
Code: Select all
Initialization script '...' line: 27
A [url=viewtopic.php?t=26065]problem[/url] occurred configuring project ':app'.
> Could not create task ':app:com.example.sample.HelloKt.main()'.
> SourceSet with name 'main' not found.
Code: Select all
# line 27 (the failing line)
classpath = project.sourceSets[sourceSetName].runtimeClasspath
Code: Select all
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
}
}
}
}
- „Run with Coverage“ funktioniert, also ist die Klasse () und Klassenpfad sind korrekt.
Code: Select all
com.example.sample.HelloKt - Otter scheint eine temporäre Gradle-Aufgabe zu generieren, um die Funktion auszuführen, und diese Aufgabe schlägt fehl, weil Android-Module kein standardmäßiges JVM-Hauptquellensatz haben.
- Ungültige Caches, gelöschte .gradle & .idea
- Alle Laufkonfigurationen zurücksetzen
- Manuelle „Kotlin“-Laufkonfiguration
Hauptklasse: com.example.sample.HelloKt - Modul-Klassenpfad: :app
→ Schlägt fehl mit: „Klasse ... nicht im Modul gefunden ...“
→ Schlägt aufgrund von Android-Plugin vs Java-Plugin-Konflikt
Frage
Gibt es eine Möglichkeit (eine IDE-Einstellung oder eine Gradle-Problemumgehung), Android Studio Otter zu zwingen, dieses unterhaltsame main() als einfache Kotlin/JVM-Anwendung auszuführen, ohne die fehlerhafte temporäre Gradle-Aufgabe zu generieren?
Mobile version