Safiul Azam
Safiul Azam

Reputation: 29

Kotlin/Native -> androidMain -> Unresolved symbol

I have added this line in common gradle.

implementation ("com.google.android.gms:play-services-location:17.0.0")

I'm tring to instantiate FusedLocationProviderClient inside a class in androidMain.

But it says, unresolved symbol. Any idea why?

Upvotes: 0

Views: 217

Answers (1)

Sujit Poudel
Sujit Poudel

Reputation: 541

What you are trying to accomplish here is not possible the exact same way you are architecting this.

In the common, you cannot have platform specific implementations. In the common, you can add the code that is platform agnostic. The FusedLocationProviderClient is android specific. So, that dependencies you have with

implementation ("com.google.android.gms:play-services-location:17.0.0")

must be placed for the android's dependencies block. And if you need android specific dependencies, you will need android SDK, and android {} block in your gradle file as well. Something like this:

android {
    compileSdkVersion(29)
    defaultConfig {
        minSdkVersion(21)
        targetSdkVersion(29)
    }
}

And then in kotlin{} block, you can have this:

kotlin {
...
    sourceSets {
        val androidMain by getting {
            dependencies {
                ...
                implementation ("com.google.android.gms:play-services-location:17.0.0")
                ...

            }
        }
...
}

Also, note that you might need AndroidManifest.xml in src/main to define the packge. Something like

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
          package="com.example.packageName" />

Hope that helps.

Upvotes: 1

Related Questions