3

In Java Android we use MyActivity.class to start a new activity. I was playing with Android Studio 3 beta1 and tried to convert it to kotlin. It gets converted to MyActivity::class.java but this doesn't compile. It gives me Unresolved reference: java. What would be the correct equivalent?

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'
12
  • 2
    what is the error message / logs? Can you post your code snippet? Commented Aug 9, 2017 at 19:18
  • MyActivity::class.java is the kotlin version. What are the error logs ? Commented Aug 9, 2017 at 19:24
  • Which version of kotlin are you using? Commented Aug 9, 2017 at 19:34
  • @Natan I believe it is 1.1 Commented Aug 9, 2017 at 19:35
  • 1
    At a first look, i guess you are missing classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.1.3-2" line in your project level build.gradle file. Commented Aug 9, 2017 at 19:50

2 Answers 2

1

Try adding following changes in your gradle file.

Add classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.1.3-2" in your project build.gradle file.

build.gradle(:project)

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

...
...

And add

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

two lines in app build.gradle file.

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'

This must solve your problem as i have updated My Android Studio to 3.0 beta 1 and having so issues.

I Hope this helps.

Sign up to request clarification or add additional context in comments.

2 Comments

It doesn't make a difference. I even did a clean build. Any other suggestions?
@RobinDijkhof dumb thing to ask but still : have you installed kotlin plugin?
1

I think this was an bug. I just updated to beta2 an the problem was solved.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.