gpt4 book ai didi

android - 如何在Android项目中使用Arrow Meta

转载 作者:行者123 更新时间:2023-12-03 03:25:36 30 4
gpt4 key购买 nike

我尝试基于示例代码使用Arrow Meta for Android应用程序创建简单的编译器插件。问题是XPlugin参数的使用因编译错误而失败

kotlinOptions {
jvmTarget = "1.8"
freeCompilerArgs = ["-Xplugin=${project.rootDir}/plugin/core/build/libs/core-all.jar"]
}
e: java.lang.NoSuchMethodError: org.jetbrains.kotlin.com.intellij.openapi.extensions.impl.ExtensionsAreaImpl.getExtensionPoints()[Lorg/jetbrains/kotlin/com/intellij/openapi/extensions/impl/ExtensionPointImpl;

最佳答案

在过去的几周中,我一直在尝试在Android项目中使用arrow meta,幸运的是,我可以在Arrow社区的帮助下使其正常运行。
在这里,您将找到有关如何将箭头meta集成到android项目中的discussion
这里有一个指向repo的链接,其中我使用了箭头meta。这基于arrow社区发布的最新examples
基本上,您需要做的就是创建插件,并且需要注意的重要一点是文件夹“create-plugin / src / main / resources / META-INF / services /”。在那里,您将需要创建一个名为“org.jetbrains.kotlin.compiler.plugin.ComponentRegistrar”的文件,并在其中声明您的插件。
在我的仓库中关注这个link
然后,您需要在app:build.grradle中编写下一行

android {
kotlinOptions {
jvmTarget = '1.8'
freeCompilerArgs += "-Xplugin=${project.rootDir}/create-plugin/build/libs/create-plugin-all.jar"
}
}
tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile) {
compileTask -> compileTask.dependsOn ":create-plugin:createNewPlugin"
}
然后在您的create-pluing:build.gradle中添加以下几行:
import java.nio.file.Paths

dependencies {
compileOnly "org.jetbrains.kotlin:kotlin-stdlib:1.4.10"
compileOnly "org.jetbrains.kotlin:kotlin-compiler-embeddable:$kotlin_version"
compileOnly "io.arrow-kt:compiler-plugin:1.4.10-SNAPSHOT"
}

// Create a new JAR with: Arrow Meta + new plugin
task createNewPlugin(type: Jar, dependsOn: classes) {
archiveClassifier = "all"
from 'build/classes/kotlin/main'
from 'build/resources/main'
from (
zipTree(sourceSets.main.compileClasspath.find {
it.absolutePath.contains(Paths.get("io.arrow-kt","compiler-plugin").toString())
})
) {
exclude 'META-INF/services/org.jetbrains.kotlin.compiler.plugin.ComponentRegistrar'
}
}
重要的是要注意,kotlin版本和arrow meta的版本已连接。
我使用的是Kotlin版本1.4.10和箭头编译器插件版本1.4.10-SNAPSHOT

关于android - 如何在Android项目中使用Arrow Meta,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61279518/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com