我无法使用自定义 Kotlin 库中的顶级函数

I'm not able to use top level functions from my custom Kotlin library

我想为 android 创建一个包含一些顶级函数的 kotlin 库。

我创建了一个 android 库项目。

我添加了一些顶级函数和一些 类

// filename TestMethodFirst.kt
fun testMethodFirst() {}
// filename TestClass.kt
class TestClass() {}

我已经使用 ./gradlew build

构建了库

我已将此库作为 aar 库包含到另一个项目中

库中的 类 已解决并顺利导入。顶级函数未解析,因此无法使用。我试图手动添加导入,但它也没有用。当我尝试使用 java 中的顶级函数作为静态方法执行时,它起作用了。

这行不通

// filename Test1.kt
fun test1() {
    testMethodFirst()
}

这个有效

// filename Test2.kt
fun test1() {
    TestClass()
}

这个有效

// filename Test3.java
class Test {
    void test() {
        TestMethodFirstKt.testMethodFirst();
    }
}

我已经用 AS 4.1 Canary 7 和 AS 3.6.2 试过了

附件包含库项目和aar库

Project

Generated aar

对于 Android Studio 4.1 Canary,this is a known bug, until Canary 9, fixed in Canary 10. Based on this comment,尝试添加:

android {
    packagingOptions {
        excludes -= "/META-INF/*.kotlin_module"
    }
}

这对我有用,并且计划为 Canary 10 提供更永久的修复。