如何在Android项目中使用Arrow Meta [英] How to use Arrow Meta with Android project
问题描述
我尝试根据示例代码使用Arrow Meta为Android应用程序创建简单的编译器插件.问题是XPlugin
参数的使用因编译错误而失败
I try to create simple compiler plugin with Arrow Meta for Android application, base on example code. Problem is that usage with XPlugin
parameter fails with compilation error
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社区的帮助下使其正常工作.
I have been trying to use arrow meta in an Android project in the last weeks and fortunately I could make it work with the help of Arrow community.
在这里您会找到有关如何集成箭头的讨论一个Android项目中的meta.
Here you will find a discussion on how to integrate arrow meta in an android project.
这里有一个指向 repo 的链接,其中我使用了箭头meta .这基于箭头社区发布的最新示例.
Here there is a link to a repo where I use arrow meta. This is based in the latest examples published by arrow community.
基本上,您需要做的是创建插件,并且需要注意的重要一点是文件夹"create-plugin/src/main/resources/META-INF/services/".您必须在此处创建一个名为"org.jetbrains.kotlin.compiler.plugin.ComponentRegistrar"的文件.您需要在其中声明插件的地方.
Basically, what you need to do is to create your plugin and something important to notice is the folder "create-plugin/src/main/resources/META-INF/services/". There you will have to create a file called "org.jetbrains.kotlin.compiler.plugin.ComponentRegistrar" where you need to declare your plugin.
遵循此然后,您需要在app:build.grradle中编写下一行
Then you need to write the next lines in you 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中添加以下行:
Then in your create-pluing:build.gradle add the next lines:
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版本已连接.
It is important to notice that the kotlin version and the version of arrow meta are connected.
我使用的是Kotlin版本1.4.10和箭头编译器插件版本1.4.10-SNAPSHOT
I use kotlin version 1.4.10 and arrow compiler plugin version 1.4.10-SNAPSHOT
这篇关于如何在Android项目中使用Arrow Meta的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!