0

Am trying to use repeat function in the MainActivity.kt file but id doens seems working correctly here is the error that I have got:

enter image description here

NB: even print doesn't work

here is the suggested imports for println

enter image description here

I said maybe there are somthing missing in Kotin configuration so here is my build.gradle (Module)

plugins {
    id 'com.android.application'
    id 'kotlin-android'
    id 'kotlin-android-extensions'
}

android {
    compileSdk 32

    defaultConfig {
        applicationId "com.example.myapplication4"
        minSdk 21
        targetSdk 32
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

    buildFeatures {
        viewBinding = true
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    kotlinOptions {
        jvmTarget = '1.8'
    }
}

dependencies {
    implementation 'androidx.core:core-ktx:1.7.0'
    implementation 'androidx.appcompat:appcompat:1.5.1'
    implementation 'com.google.android.material:material:1.7.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
    implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
    testImplementation 'junit:junit:4.13.2'
    androidTestImplementation 'androidx.test.ext:junit:1.1.4'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.0'
    apply plugin : "kotlin-android"
    apply plugin : "kotlin-android-extensions"

}

Build.gradle (project)

buildscript {
    ext.kotlin_version = "1.6.21"
    ext.supportLibVersion = "25.3.0"
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.3.0'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath "org.jetbrains.kotlin:kotlin-android-extensions:$kotlin_version"

    }
}
plugins {
    id 'com.android.application' version '7.1.0' apply false
    id 'com.android.library' version '7.1.0' apply false
    id 'org.jetbrains.kotlin.android' version '1.6.21' apply false
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

Plugins is already installed:

enter image description here

Kotlin configuration in my project:

Tools > Kotlin > Configure kotlin in Project

enter image description here

1 Answer 1

1

(Opinion) Android studio is not really the best IDE to learn plain kotlin (and by plain I mean stuff not related to android)

(Answer) In your case, if you want to print stuff (which will appear in the logcat btw) you would have to import the first thing, which is: enter image description here

And you will have to (probably, not sure) do something similar for your repeat

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

6 Comments

Oh, also kotlin-android-extensions is deprecated: stackoverflow.com/questions/65179275/…
Thank you for the answer, but am actually trying to make a mobile application using Kotlin, that is why I am using Andoird Studio. print was just an example to test if Kotlin packages can be imported correctly, but it seems like it does not. For the repeat function unfortunatelly there is not import suggestion, that is why I am wondering why I cannot Import that. Same thing for the fuction Random for example, it gives me only the suggestions of Java packages and not Kotlin
Oh, sorry then, that's a bit interesting tho...
Could you make sure that your .kt files are associated with Kotlin? File -> Settings -> Editor -> File Types.
I would say Android Studio comes close to tying IntelliJ IDEA as being the best IDE for learning Kotlin. The only thing it lacks is a wizard for creating new projects that aren’t for Android.
|

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.