Alex
Alex

Reputation: 2027

Migrate java class to Kotlin - Cannot resolve symbol annotate class

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
    }
}

in 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"

    }

I has activity (java class) annotate by org.androidannotations.annotations.EActivity

Here snippet:

import android.app.Activity;
import android.os.Bundle;
import org.androidannotations.annotations.EActivity

@EActivity
public class LoginActivity extends Activity {

}

And another java activity (SplashActivity.java) that call this LoginActivity like this:

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);

Nice it's work fine.

Now I migrate only LoginActivity to Kotlin class (LoginActivity.kt)

like this:

import org.androidannotations.annotations.Background
import org.androidannotations.annotations.EActivity

@EActivity
open class LoginActivity : Activity() {

}

and now SplashActivity.java has compile error in this line:

Intent intent = new Intent(thisActivity, LoginActivity_.class);

error message:

Cannot resolve symbol 'LoginActivity_'

P.S. If I remove "_" than compile success:

Intent intent = new Intent(thisActivity, LoginActivity.class);

But I need to use LoginActivity_

Upvotes: 0

Views: 1273

Answers (1)

Alexey Romanov
Alexey Romanov

Reputation: 170713

You have to use kapt instead of annotationProcessor to handle Kotlin files. Any annotation processor may or may not correctly handle them; for androidannotations in particular there is documentation on Kotlin support.

Upvotes: 1

Related Questions