我添加了一个Kotlin文件,其中包含最初用Java编写的Android Studio项目的三个类。这个文件在Android Studio中编译得很好,在我试图让Java类与Kotlin类交互之前,这个项目一直在构建中。Android Studio给了我以下错误:
Java compiler:
[path]/[project]
app/src/main/java
[project].jav
error: cannot find symbol class Quiz_abTime
当我添加文件时,Android Studio抱怨gradle的配置,但是我运行了配置,它说所有使用Kotlin的模块都配置好了。
这是我的
build.gradle
文件夹。首先是模块:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext.kotlin_version = '1.2.61'
repositories {
jcenter()
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.4'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
maven {
url "https://maven.google.com"
}
}
}
build.gradle公司
:
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
android {
compileSdkVersion 26
defaultConfig {
applicationId [application name deleted for SO]
minSdkVersion 16
targetSdkVersion 26
versionCode 6
versionName "2.0.5"
vectorDrawables.useSupportLibrary = true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:support-v4:26.1.0'
implementation 'com.android.support:support-vector-drawable:26.1.0'
implementation 'com.android.support:appcompat-v7:26.1.0' // where X.X.X version
implementation 'com.github.yukuku:ambilwarna:2.0.1'
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
}
repositories {
mavenCentral()
}
import android.support.v7.app.ActionBar;
奇怪的是,
ActionBar
Cannot resolve symbol
动作条`。还有其他一些像这样的高亮度;这是在Android Studio要求升级后开始的。但是,至少这会生成;只有当我试图从Java类访问Kotlin类时,生成才会失败。
我以前在Android Studio中用Java做过Kotlin,这不是问题,但是有人能告诉我在哪里查找阻止Java编译器看到Kotlin类的问题吗?