安卓studio插件开发(一)本地搭建工程

ops/2024/10/18 16:47:53/

下载idea 社区版本
建立IDE Plugin工程
在这里插入图片描述
点击create就行,新建立的工程长这样
在这里插入图片描述
比较重要的文件
build.gradle:配置工程的参数
plugin.xml:设置插件的Action位置

build.gradle.kts内容如下:

plugins {id("java")id("org.jetbrains.kotlin.jvm") version "1.9.0"  //设置kotlin版本id("org.jetbrains.intellij") version "1.13.1"  //设置插件版本
}group = "com.example"
version = "1.0-SNAPSHOT"repositories {mavenCentral()
}// Configure Gradle IntelliJ Plugin
// Read more: https://plugins.jetbrains.com/docs/intellij/tools-gradle-intellij-plugin.html
intellij {type.set("AI") // 设置启动的是androidstudiolocalPath.set("/Applications/Android Studio.app/Contents") //设置启动本地的安卓studio,而不是重新下载一个plugins.set(listOf("android","com.intellij.java","java","Kotlin"))
}tasks {// Set the JVM compatibility versionswithType<JavaCompile> {sourceCompatibility = "11"targetCompatibility = "11"}withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile> {kotlinOptions.jvmTarget = "11"}patchPluginXml {sinceBuild.set("221")untilBuild.set("231.*")}signPlugin {certificateChain.set(System.getenv("CERTIFICATE_CHAIN"))privateKey.set(System.getenv("PRIVATE_KEY"))password.set(System.getenv("PRIVATE_KEY_PASSWORD"))}publishPlugin {token.set(System.getenv("PUBLISH_TOKEN"))}
}

plugin.xml文件内容如下:
主要是设置了依赖项,以及action的弹出位置

<!-- Plugin Configuration File. Read more: https://plugins.jetbrains.com/docs/intellij/plugin-configuration-file.html -->
<idea-plugin><!-- Unique identifier of the plugin. It should be FQN. It cannot be changed between the plugin versions. --><id>com.example.plugin3</id><!-- Public plugin name should be written in Title Case.Guidelines: https://plugins.jetbrains.com/docs/marketplace/plugin-overview-page.html#plugin-name --><name>Plugin3</name><!-- A displayed Vendor name or Organization ID displayed on the Plugins Page. --><vendor email="support@yourcompany.com" url="https://www.yourcompany.com">YourCompany</vendor><!-- Description of the plugin displayed on the Plugin Page and IDE Plugin Manager.Simple HTML elements (text formatting, paragraphs, and lists) can be added inside of <![CDATA[ ]]> tag.Guidelines: https://plugins.jetbrains.com/docs/marketplace/plugin-overview-page.html#plugin-description --><description><![CDATA[Enter short description for your plugin here.<br><em>most HTML tags may be used</em>]]></description><!-- Product and plugin compatibility requirements.Read more: https://plugins.jetbrains.com/docs/intellij/plugin-compatibility.html --><depends>com.intellij.modules.platform</depends><depends>org.jetbrains.android</depends><depends>com.intellij.modules.androidstudio</depends><!-- Extension points defined by the plugin.Read more: https://plugins.jetbrains.com/docs/intellij/plugin-extension-points.html --><extensions defaultExtensionNs="com.intellij"></extensions><actions><action id="demo.hello.world" class="com.example.plugin3.HelloWorldAction" text="HelloWorld"description="Say Hello World"><add-to-group group-id="NewGroup" anchor="first"/></action></actions>
</idea-plugin>

HelloWordAction具体内容,作用是在右键的时候多出一个选项,点击选项之后,出一个弹窗提示

package com.example.plugin3import com.intellij.notification.NotificationDisplayType
import com.intellij.notification.NotificationGroup
import com.intellij.notification.NotificationType
import com.intellij.openapi.actionSystem.AnAction
import com.intellij.openapi.actionSystem.AnActionEventclass HelloWorldAction : AnAction() {override fun actionPerformed(event: AnActionEvent) {//这里创建了一个消息提示弹窗,在IDE中展示“Hello World”val notificationGroup = NotificationGroup(displayId = "myActionId",displayType = NotificationDisplayType.BALLOON)val notification = notificationGroup.createNotification(title = "chentao Demo",content = "Hello World",type = NotificationType.INFORMATION).notify(event.project) //从方法的Event对象中获取到当前IDE正在展示的project,在该project中展示弹窗}
}

效果:

在这里插入图片描述

容易出现的问题主要在build.gradle里面kotlin、intelij版本和jdk版本,建议可以先用idea建立一个新工程,然后先尝试跑起来,如果跑不起来,看具体的报错信息来调整上面说的版本号


http://www.ppmy.cn/ops/15601.html

相关文章

c++模板初阶

1. 泛型编程 泛型编程&#xff1a;编写与类型无关的通用代码&#xff0c;是代码复用的一种手段。模板是泛型编程的基础。 使用函数重载实现一个通用的交换函数&#xff0c;虽然可以实现&#xff0c;但是有几个不好的地方&#xff1a; 1. 重载的函数仅仅是类型不同&#xff0c…

【LeetCode】191. 位1的个数

题目链接&#xff1a;191. 位1的个数 题目描述&#xff1a; 解法1&#xff1a;题意很简单就不说了&#xff0c;这里先说一种最简单的解法&#xff0c;首先我们知道一点&#xff1a;n&(n-1)相当于把是将n的二进制位中最低位的1变为了0&#xff0c;其它位保持不变&#xff0…

【C++】:拷贝构造函数和赋值运算符重载

目录 一&#xff0c;拷贝构造函数1. 什么是拷贝构造函数2. 拷贝构造函数的特性3. 实践总结 二&#xff0c;赋值运算符重载2.1 运算符重载2.2 赋值运算符重载 一&#xff0c;拷贝构造函数 1. 什么是拷贝构造函数 拷贝构造函数是特殊的构造函数。是用一个已经存在的对象&#x…

bit、进制、位、时钟(窗口)、OSI七层网络模型、协议、各种码

1.bit与进制 &#xff08;个人理解&#xff0c;具体电路是非常复杂的&#xff09; 物理层数据流&#xff0c;bit表示物理层数据传输单位&#xff0c; 一个电路当中&#xff0c;通过通断来表示数字1和0 两个电路要通讯&#xff0c;至少要两根线&#xff0c;一根作为电势参照…

ubuntu安装QEMU

qemu虚拟机的使用&#xff08;一&#xff09;——ubuntu20.4安装QEMU_ubuntu安装qemu-CSDN博客 遇到的问题&#xff1a; (1)本来使用git clone https://github.com/qemu/qemu.git fatal: 无法访问 https://github.com/qemu/qemu.git/&#xff1a;GnuTLS recv error (-110): …

pycharm永久改变sys.path

进入pycharm&#xff0c;选择file->settings->interpreter 在这里选择图中所示show all 再单击左上角减号右侧第三个&#xff0c;长得像思维导图的图标 之后添加你的路径&#xff0c;确认即可

npm 常用命令详解

npm&#xff08;Node Package Manager&#xff09;是 Node.js 的包管理工具&#xff0c;用于安装、管理和发布代码包。以下是 npm 常用命令的详解&#xff1a; npm init&#xff1a;初始化一个新的 Node.js 项目&#xff0c;生成一个 package.json 文件&#xff0c;用于管理项目…

stack,queue的模拟实现以及优先级队列

这篇博客用来记录stack&#xff0c;queue的学习。 stack的模拟实现 stack的模拟实现比较简单&#xff0c;先上代码 #pragma once #include<vector> #include<list> #include<deque> #include<iostream> using std::deque; using namespace std;name…