An Android plugin for Sublime Text 2

I've recently purchased a Galaxy Nexus, and while my previous phone had some unknown proprietary OS, this one has Android! Version 4.0.2 even! I love to tinker around, so I naturally felt a need to program something for this thing.

However, being spoiled by the luxuries of Visual Studio, I couldn't stand to work with other IDEs like Eclipse or IntelliJ IDEA. So I decided to work with the SDK command line and figure out how to compile stuff manually. But going through the process by hand every time can be tiring, so I wrote a plugin for my favorite code editor, Sublime Text 2.

I should mention that I had no prior Python experience when I spent a single sunday evening writing this plugin. So it might blow up your computer.

What it should do:

  • Provide a sort-of simple interface for creating new Android projects
  • Compile and build your application (signed with a debug key)
  • Provide a fully automated build-install system
  • Run ADB logcat to see device output (like System.out.println) with continuous updates.

Getting it working:

First you need to download the archive below and extract it to "Data/Packages", located in your Sublime Text 2 installation. The archive comes with a file called "android.sublime-settings", which contains information about where Java, Android SDK and Apache Ant are located. You will need to configure these paths like this:

  • "jdk_bin": The folder you would usually set as JAVA_HOME.
  • "default_android_project_dir": Up to you
  • "android_sdk": Android SDK root folder.
  • "ant_bin": The /bin folder of wherever you have installed apache-ant.

And that's it! After restarting Sublime Text 2, an "Android" menu-item should now show up under the 'Tools' menu, in addition to two build-systems. The "Android" build will attempt to uninstall the package (if it exists), followed by a debug build and installation onto the connected device. "Android (Build only)" will only compile a debug build and create a signed .apk.

Download: .zip

Note that I will not be providing further support for this plugin. However, a kind person has taken the liberty to extend the plugin to support multiple platforms. See here

21 comments:

  1. did not blow up my computer :D it works.
    thanks, great tool!

    ReplyDelete
  2. It's looks great but this plugin works only on Windows.
    Thanks, I would edit it for my Linux.

    ReplyDelete
  3. This was so easy to set up, and I'm thrilled to be able to use sublime text to develop, thanks so much!

    ReplyDelete
  4. Works great for me once I had all the paths set up - although one curious bug that I found is that it only builds successfully (ctrl+b, or from menu) if the current file opened is the build.xml file.

    Thanks for the great tool!
    Donski

    ReplyDelete
  5. Hello, any chance to get it on github so the community can improve it? (and also install/update through the package manager) :P

    ReplyDelete
  6. Not exactly the same, but eerily similar:
    http://gitorious.org/sublime-android

    ReplyDelete
  7. God I just need autocomplete for Android SDK and I'll replace eclipse by Sublime Text 2. Any suggestion?
    Thanks for your work!

    ReplyDelete
    Replies
    1. Thanks for the compliment!

      I actually wanted to include an autocompletion feature for both Android class names and strings in the resources (R.java) file. You can see a snippet of the code in android.py.

      I finished some of it a time ago. If you want to try your hand and modify it to also auto-complete Android functions/classes/etc, you can replace the AndroidAutoCompleteRCommand in android.py with this: http://pastebin.com/udLumtTG

      In the Android documentation files you can find a sitemap, which contains all possible links like http://developer.android.com/reference/java/util/LinkedList.html
      and http://developer.android.com/reference/android/view/MenuItem.html

      As you can see, parsing this document can give java.util.LinkedList and android.view.MenuItem, which can be useful in auto-completing stuff. Perhaps you could even extend the right-click menu to include a button for going to document page, when right-clicking a keyname...

      Delete
  8. Very very nice! I'm just starting with android development, but have been using ST2 for quite some time now, and this is just perfect. I really dislike the performance killer Eclipse is on my laptop, so seeing that it's possible to use ST2 for this made my day! Thanks a lot sir!

    ReplyDelete
  9. I'm having really tough time getting the JDK path to work. I've installed JDK from Apple and from Sun directly and really feel like I have the right path for "jdk_bin" (/Library/Java/JavaVirtualMachines/1.6.0_37-b06-434.jdk/Contents/Home/bin) but no matter what I do I keep getting the error:

    "Error: JDK path is incorrect. Please configure Android/android.sublime-settings"

    Any advice?

    I'm running lion BTW.

    Here's my settings file atm:

    {
    "jdk_bin": "/Library/Java/JavaVirtualMachines/1.6.0_37-b06-434.jdk/Contents/Home/bin",
    "default_android_project_dir": "/Users/Chris/Documents/Android/projects",
    "android_sdk": "/Users/Chris/Documents/Android",
    "ant_bin": "/Users/Chris/Documents/Development/apache-ant-1.8.3/bin",
    "last_apk_path": "",
    "last_package_name": ""
    }

    ReplyDelete
    Replies
    1. I'm not familiar with OSX, but I think jdk_bin should point to just /Home. That is, not to /bin. I guess the name was sort of misleading...

      Hopefully that works!

      Delete
    2. Thanks for replying Uint9

      Sadly a no go so far. :(

      I've tried with/without /Home, with/without /Contents, even copying the whole java folder to my documents folder and pointing there... but I keep getting: "Error: JDK path is incorrect. Please configure Android/android.sublime-settings"

      If you have any other ideas/suggestions please let me know!

      Thanks

      Delete
    3. I wonder if this line in android.py is the problem:

      Line 30: if not (os.path.exists(self.jdk) and os.path.isfile(self.jdk + "/bin/java.exe")):

      Obviously there are no exe files on OSX. I changed to just /bin/java but that didn't seem to fix it though.

      Delete
    4. Yeah - looks like the code was written for Windows only - though the very-similar android package here (http://gitorious.org/sublime-android#more) seems to have OSX and Windows support ... but, of course, it's not working out of the box either.

      UGH... really don't want to have to install Eclipse! :(

      Delete
    5. That repo is based on this plugin. I didn't aim for multiplatform support when I made this, but it looks like that guy has got some stuff going. I suggest you ask him, as I have no idea how the Android build sequence works for OSX :|

      Delete
  10. How would you install this plugin on Windows?

    ReplyDelete
    Replies
    1. Assuming you have downloaded and setup the Android SDK and java stuffs, all you need to do is extract the contents of the .zip file to Data/Packages in your ST2 folder. You also need to edit the lines in android.sublime-settings as described in the post.

      Delete
  11. Thanks so much!... really good :D..

    But I have open the build.xml file to execute Build Commando (CTRL+B), why?

    ReplyDelete
  12. I get an invalid escape error I'm guessing it's because of all the \ in my folder but it's funny because these are all in "". Can you help?

    ReplyDelete
  13. Great and I have a nifty provide: What Home Renovation Expenses Are Tax Deductible house renovation credit

    ReplyDelete