先到 https://www.jetbrains.com/idea/download/
選擇好自己的作業系統,我是下載Community版。
開始安裝,因為要開發Plugin,左下角的那個插頭圖示需要設為Enable,但沒什麼作用。

裝好後,隨便new一個專案,然後進入設定,把Plugin裝好。

之後IntelliJ IDEA會要求重啟,重啟後new Project就可以找到開發Plugin的項目了。
new好了一個新的Plugin專案後,在src上按右鍵,選擇Action

方便測試,參數都填入一樣的字串plugintest,Groups選ToolsMenu(Tools),Actions選ToolsBasicGroup(Tools Basic Group)

按下OK後,上方會會出現提示,選擇右邊的藍字就好了。

在plugintest.java的actionPerformed函式加入以下程式碼。
Project project = e.getProject();
Messages.showMessageDialog(project, "plugintest","title",Messages.getInformationIcon());接下來可以先測試一下,按下右上方的箭頭執行。

會再執行一個IntelliJ IDEA,選擇Tools選項會看到多了一個項目,點擊後會跳出一個對話框,代表成功了。

在專案上案右鍵選Prepare Plugin Module 'plugintest' For Deployment,就可以打包了

將產生的jar拿給Android Studio安裝會顯示不相容的錯誤。

回到IntelliJ IDEA在resources->META-INF->plugin.xml內
<idea-version since-build="145.0"/>把這行找出,注意編號的值,需要修改,至於改成多少可以參考一下 其它的Plugin,例如:
Coverage、Gradle、Properties、Setings Repository等...,我是改成143.0
修改完成後,在Tools下按下plugintest就會跳出對話框了。
以上是Android Studio在2.1.3版的情況,但在2.2.3版按下增加的功能會跳不出對話框 ,還需要回IntelliJ IDEA作些修改。
在src->plugintest.java內要補上類似package com.my.test;的程式碼,就像在寫android時一樣,名稱自己決定,寫好後也要把plugintest.java移至相同的位置。
別忘了在resources->META-INF->plugin.xml內找到
<action id="plugintest" class="plugintest" text="plugintest" description="plugintest">把class的值加上剛才自己定的包名,例如com.my.test.plugintest。這樣2.2.3版就可以顯示對話框了。
另外在plugin.xml內有一行
<depends>com.intellij.modules.lang</depends>
碰到其它錯誤時,可視需要打開,或修改。
沒有留言:
張貼留言