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


    下载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") // 设置启动的是androidstudio
        localPath.set("/Applications/Android Studio.app/Contents") //设置启动本地的安卓studio,而不是重新下载一个
    
        plugins.set(listOf("android","com.intellij.java","java","Kotlin"))
    }
    
    tasks {
        // Set the JVM compatibility versions
        withType {
            sourceCompatibility = "11"
            targetCompatibility = "11"
        }
        withType {
            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"))
        }
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47

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

    
    
        
        com.example.plugin3
    
        
        Plugin3
    
        
        YourCompany
    
        
        
        most HTML tags may be used
      ]]>
    
        
        com.intellij.modules.platform
        org.jetbrains.android
        com.intellij.modules.androidstudio
    
        
        
    
        
    
        
            
                
            
        
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39

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

    package com.example.plugin3
    
    import 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.AnActionEvent
    
    class 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中展示弹窗
        }
    }
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25

    效果:

    在这里插入图片描述

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

  • 相关阅读:
    HTTPS基础原理和配置 - 1
    Linux常用命令(Hadoop)
    面试官:MyBatis 插件用途和底层原理
    L2TP客户端之Strongswan移植(三)
    无线路由器设置成交换机
    python创建空列表
    Android Studio 正则修改参数顺序
    汇编语言程序设计 --- 一元二次方程ax2+bx+c=0求解(含注释详细源代码)
    DevOps系列文章之 Docker-compose
    C++ Reference: Standard C++ Library reference: Containers: deque: deque: clear
  • 原文地址:https://blog.csdn.net/whoami_I/article/details/138199370