Android Studio 3.4.2
build.gradle:
buildscript {
ext.kotlin_version = '1.3.41'
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.4.2'
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
}
}
在app / build.gradle中:
def AAVersion = '4.6.0'
def KOTLIN_COROUTINE_VERSION = '1.2.1'
dependencies {
annotationProcessor "org.androidannotations:androidannotations:$AAVersion"
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation('com.crashlytics.sdk.android:crashlytics:2.7.0@aar') { transitive = true; }
implementation 'com.google.android.material:material:1.1.0-alpha07'
implementation 'com.google.code.gson:gson:2.8.5'
implementation "org.androidannotations:androidannotations-api:$AAVersion"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:$KOTLIN_COROUTINE_VERSION"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$KOTLIN_COROUTINE_VERSION"
}
我有活动( java类),其注释为org.androidannotations.annotations.EActivity
以下代码段:
import android.app.Activity;
import android.os.Bundle;
import org.androidannotations.annotations.EActivity
@EActivity
public class LoginActivity extends Activity {
}
另一个Java活动( SplashActivity.java )像这样调用此LoginActivity
:
import android.app.Activity;
import android.os.Bundle;
import org.androidannotations.annotations.EActivity
@EActivity
public class SplashActivity extends Activity {
Intent intent = new Intent(thisActivity, LoginActivity_.class);
startActivity(intent);
很好,工作正常。
现在,我仅将 LoginActivity 迁移到Kotlin类(LoginActivity.kt
)
像这样:
import org.androidannotations.annotations.Background
import org.androidannotations.annotations.EActivity
@EActivity
open class LoginActivity : Activity() {
}
现在 SplashActivity.java 在此行中有编译错误:
Intent intent = new Intent(thisActivity, LoginActivity_.class);
错误消息:
Cannot resolve symbol 'LoginActivity_'
P.S。如果我删除“ _”而不是编译成功:
Intent intent = new Intent(thisActivity, LoginActivity.class);
但是我需要使用LoginActivity_
答案 0 :(得分:0)
您必须use kapt
而不是annotationProcessor
来处理Kotlin文件。任何注释处理器可能会或可能不会正确处理它们; androidannotations
,尤其是there is documentation on Kotlin support。