Koltin MyClass.class.java未解决的参考:java

在Java Android中,我们使用MyActivity.class来开始一个新的活动。 我正在玩Android Studio 3 beta1,并试图将其转换为kotlin。 它被转换为MyActivity::class.java但不能编译。 它给了我Unresolved reference: java 。 什么是正确的等值?

项目Build.gradle:

 buildscript { repositories { jcenter() } dependencies { classpath 'com.android.tools.build:gradle:3.0.0-beta1' classpath 'com.google.gms:google-services:3.0.0' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files } } allprojects { repositories { jcenter() maven { url "https://jitpack.io" } } } 

应用程序Build.gradle:

 apply plugin: 'com.android.application' android { signingConfigs { } compileSdkVersion 25 buildToolsVersion "25.0.2" lintOptions { abortOnError false } defaultConfig { vectorDrawables.useSupportLibrary = true applicationId "app" minSdkVersion 15 targetSdkVersion 25 versionCode 104 versionName "4.0.11" } buildTypes { release { minifyEnabled true proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } debug { minifyEnabled false } } flavorDimensions "mode" productFlavors { free { dimension "mode" } paid { dimension "mode" applicationId "app.paid" } } compileOptions { sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 } } dependencies { compile fileTree(include: ['*.jar'], dir: 'libs') compile 'com.android.support:appcompat-v7:25.3.1' compile 'com.android.support:support-v4:25.3.1' compile 'com.android.support:design:25.3.1' compile 'com.android.support:recyclerview-v7:25.3.1' compile 'com.android.support:cardview-v7:25.3.1' compile 'com.google.android.gms:play-services-ads:10.2.6' releaseCompile 'ch.acra:acra:4.9.1' // compile 'ch.acra:acra:4.9.1' compile 'com.google.firebase:firebase-core:10.2.6' compile 'com.google.firebase:firebase-database:10.2.6' compile 'com.google.firebase:firebase-auth:10.2.6' compile 'com.google.android.gms:play-services-auth:10.2.6' compile 'com.github.frangsierra:rx2firebase:1.1.3' } apply plugin: 'com.google.gms.google-services' 

尝试在您的gradle文件中添加以下更改。

在项目build.gradle文件中添加classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.1.3-2"

的build.gradle(:项目)

 buildscript { repositories { jcenter() } dependencies { classpath 'com.android.tools.build:gradle:3.0.0-beta1' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.1.3-2" // New classpath 'com.google.gms:google-services:3.0.0' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files } } ... ... 

并添加

apply plugin: 'kotlin-android-extensions' apply plugin: 'kotlin-android'

应用程序build.gradle文件中的两行。

的build.gradle(:APP)

 apply plugin: 'com.android.application' apply plugin: 'kotlin-android-extensions' // New apply plugin: 'kotlin-android' // New android { ... ... ... ... } dependencies { ... ... } apply plugin: 'com.google.gms.google-services' 

这必须解决您的问题,因为我已经更新我的Android Studio 3.0 beta 1并有这样的问题。

我希望这有帮助。

我认为这是一个错误。 我刚刚更新到beta2一个问题解决了。