我有这个Gradle设置:
android/build.gradle
:
apply plugin: "com.android.library"
apply plugin: "kotlin-android"
repositories {
mavenCentral()
jcenter()
}
android {
compileSdkVersion 26
buildToolsVersion "26.0.2"
defaultConfig {
minSdkVersion 15
targetSdkVersion 26
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src/main/kotlin']
}
}
// compileOptions {
// sourceCompatibility JavaVersion.VERSION_1_7
// targetCompatibility JavaVersion.VERSION_1_7
// }
}
dependencies {
compile project(':core')
}
core/build.gradle
:
apply plugin: 'kotlin'
repositories {
mavenCentral()
}
dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib-jre8:$kotlin_version"
testCompile 'junit:junit:4.12'
}
compileKotlin {
kotlinOptions.jvmTarget = "1.8"
}
compileTestKotlin {
kotlinOptions.jvmTarget = "1.8"
}
build.gradle
:
group 'com.my.group'
version '1.0-SNAPSHOT'
buildscript {
ext.kotlin_version = '1.1.51'
repositories {
mavenCentral()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
repositories {
mavenCentral()
}
settings.gradle
:
rootProject.name = 'my-app-name'
include 'core'
include 'android'
core/src/main/kotlin/com/my/package/Runner.kt
:
fun main(args: Array<String>) {
println("RUNS")
}
当我尝试从IntelliJ运行主程序时( Ctrl + Shift + F10 )我收到错误:
Error: Could not find or load main class RunnerKt
Process finished with exit code 1
但是,当我从settings.gradle
删除此行并刷新Gradle时,这样:
//include 'android'
然后主要运行。
如何设置这个项目,我可以运行带有Android(库)模块的主程序?
注意:我也尝试过运行测试,然后我收到此错误:
Class not found: "Tester"Empty test suite.
使用./gradlew test
从命令行运行测试适用于这两种情况。只有从IntelliJ运行的东西才能工作。
Gradle包装:4.3
IntelliJ 2017.3和2017.2.5测试