Kotlin / Native-> androidMain->无法解析的符号

时间:2019-10-04 15:14:22

标签: android gradle kotlin kotlin-multiplatform

我已在通用gradle中添加了此行。

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

我想在FusedLocationProviderClient中的一个类中实例化androidMain

但是它说unresolved symbol。知道为什么吗?

1 个答案:

答案 0 :(得分:1)

您试图在这里完成的工作与构筑此结构的方式不可能完全相同。

通常,您不能具有特定于平台的实现。通常,您可以添加与平台无关的代码。 FusedLocationProviderClient是特定于android的。因此,您对

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

必须放置在android的dependencies块中。而且,如果您需要特定于android的依赖项,则还需要android SDK,并且在gradle文件中也需要android {}进行阻止。像这样:

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

然后在kotlin{}块中,您可以这样做:

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

            }
        }
...
}

此外,请注意,您可能需要AndroidManifest.xml中的src/main来定义包装。像

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

希望有帮助。