3

I'm trying to add a Kotlin library to Android studio, that does not have any dependencies on Android. I followed Create a Kotlin library in Android Studio. The following code in that library compiled fine,

import java.util.*


class DateTimeProvider {

    inner class Helper: TimerTask() {
        override fun run() {

        }
    }

    fun start(period: Long) {
        val timer = Timer()

    }
}

but the code completion doesn't see java.util.Date, etc. For example, if I remove the import statement and type Date(0), Android Studio won't add an action to import java.util.Date.

The build.grade file looks like this:

// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
    repositories {
        google()
        mavenCentral()
    }
    dependencies {
        classpath "com.android.tools.build:gradle:7.0.4"
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.10"

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

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

When I create an Android library instead, it works, but the whole point is to not depend on Android.

Thank you,

Update

Here is the library's build.grade file content:

buildscript {
    repositories {
        google()
        mavenCentral()
    }
}

plugins {
    id 'java-library'
    id 'kotlin'
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.6.10"
}
Sven
  • 175
  • 1
  • 8
  • "The build.grade file looks like this" -- that is the project-level `build.gradle` file. Your problem lies in the module's `build.gradle` file. – CommonsWare Jan 02 '22 at 16:56
  • @CommonsWare I have updated the post with the propject-level ```build.gradle``` file. Do you mind pointing me to what's wrong/missing? Thx – Sven Jan 02 '22 at 19:36
  • So now you've shared your project-level `build.gradle` file twice. We need to see your **module**-level `build.gradle` file. – Tenfour04 Jan 02 '22 at 20:15
  • @Tenfour04 My bad, I attached the correct build.gradle file. Thank you – Sven Jan 02 '22 at 20:27

0 Answers0