在Java Android中,我们使用MyActivity.class
开始新活动。我正在玩Android Studio 3 beta1并尝试将其转换为kotlin。它被转换为MyActivity::class.java
,但这不会编译。它给了我Unresolved reference: java
。什么是正确的等价物?
Project 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" }
}
}
App 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'
答案 0 :(得分:1)
尝试在gradle文件中添加以下更改。
在项目build.gradle文件中添加classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.1.3-2"
。
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'
app build.gradle文件中的两行。
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
并遇到此问题。
我希望这有帮助。
答案 1 :(得分:0)
我认为这是一个错误。我刚刚更新到beta2,问题解决了。