用于Android开发的一些实用IDE插件

admin 6年前

下面是我每天使用,因此推荐给大家使用插件。你可以在Android Studio / IntelliJ IDEA: “Preferences (or Settings on Windows) -> Plugins -> Browse repositories”.中找到他们并安装。

ADB Idea

Developed by Philippe Breault, ADB Idea makes it easy to run commonly used ADB commands from within Android Studio. Because it knows the package name of your app from the IDE, it’ll save you quite bit of typing on the command line for things like adb uninstall com.mycompany.apppackage. Plus, you can restart the app or clear app data with just a few keystrokes — very handy indeed.

Philippe also wrote the indispensable Android Studio tips of the day blog series. Lots of tips and tricks for you to get the most out of Android Studio.

Kotlin

If you haven’t tried Kotlin, you should. Kotlin is a JVM language created by JetBrains that helps us write safe and concise code with modern features such as lambdas, null safety, data classes and extension functions. Its seamless interoperability with Java, first-class IDE support and small footprint make it a great choice for writing Android apps — it’s simply better than Java (even Java 8). In addition, the latest Kotlin M11 brought us goodies such as multiple constructors (finally, writing custom views in Kotlin!), an interesting way to replace the boring findViewById() calls (the counterpart for Java is ButterKnife), and Anko, an intriguing Kotlin-based DSL for writing type-safe, concise layouts. If you need more reasons to consider writing your next app in Kotlin, read this comprehensive report by Jake Wharton.

Have I mentioned Kotlin’s excellent IDE support? Great thing happens when the company creating the language built the IDE too. Although not 1.0 yet, Kotlin’s IntelliJ IDEA plugin already brought an experience on par with what’s available for Java. Reference search, refactoring, navigation, quick fixes etc. all work the way as they should (and that’s one of the reasons why we could quickly support Kotlin code hot-swapping along with Java support in our plugin).

In addition, the Kotlin plugin includes a few interesting features, such as converting Java code to Kotlin — even when you paste Java code into a Kotlin editor. I also find the Kotlin bytecode viewer useful for understanding what the Kotlin compiler does behind the scene.

With that being said, there are a few mysterious features that I don’t quite understand yet, such as “Kotlin Internal Mode” and “Find Implicit Nothing Class”.

Android Drawable Importer

This plugin makes it easy to import the awesome icons sets Android Icons and Google’s material design iconsinto the project. Another interesting (and very useful) feature is being able to import the so-called “Multisource-Drawable”. For example, if the assets from your designer look like the following, you can easily import them by dragging the files into the dialog and naming them once.

</div>
nice_icon_1_from_designer/ drawable_ldpi.png drawable_mdpi.png drawable_hdpi.png drawable_xhdpi.png
</div> </div> </div> </div> </div> </div>
</div> </div> </div>

Do I expect more from the plugin? Always. First of all, it’d be nice to merge the two icon sets into one. When adding an icon, in most cases I don’t know which icon sets to choose from — just give me a big list of all the icons! Second, finding an icon from a small dropdown can be quite frustrating. It’d be great to show a grid of icons filterable by keywords. Finally, when importing the “Multisource-Drawable”, it’d be nice if the plugin can recognize the naming pattern and import all images without having to repeat the drag&drop for each of them.

Genymotion

The Genymotion IDEA plugin adds a button on the toolbar that allows you to launch Genymotion VMs without leaving IntelliJ IDEA. There’s no new functionality compared to the Genymotion standalone app. In theory, to reach either of them I need to move the mouse about the same distance. But I find myself using the plugin a lot more. Maybe there is a psychological reason?

Android Parcelable plugin

To pass an object between activities, we need to make the object Parcelable or Serializable and put it in anintent or bundle. Parcelable is a lot faster than Serializable but it involves a lot of boilerplate code.

The Android Parcelable plugin generates the code of CREATOR, writeToParcel() etc. The plugin is smart enough to create different code according to the type of the field. For example, if you have a Date field, it’ll write the corresponding milliseconds since Epoch to the Parcel:

</div>
dest.writeLong(birthDate != null ? birthDate.getTime() : -1);
</div> </div> </div> </div> </div> </div>
</div> </div> </div>

This plugin is indeed a time saver. However, whenever looking at a code generator plugin, you might want to check if there’s an annotation based solution, which usually results in cleaner and more maintainable code. For Parcelable, check out Parceler.

ideaVim

Since 2007, I’ve been forcing myself to use Vim whenever possible — this way I’d be effective in text editing virtually anywhere. ideaVim was literally the first plugin I installed. It adds Vim keybindings to IDEA’s editors which allow me to use my muscle memory built up these years. I felt home again.

Key Promoter

The Key promoter plugin might be a bit controversial. It’ll nag at you and push you to use keyboard shortcuts more whenever it finds otherwise. If a menu item doesn’t yet have a shortcut set, it’ll ask if you want to set one. Not sure about you but I find it effective in helping me remember the standard key bindings.

As mentioned, I’ve been using Eclipse key bindings for quite a while. After confusing my co-workers in various ScreenHero sessions, I decided to switch to standard bindings (Mac OSX 10.5+) with the help of Key promoter. Suddenly Philippe Breault’s Android Studio tips of the day became more useful to me.

用于Android开发的一些实用IDE插件

jimu Mirror

Disclaimer: we are the creator of this plugin, and we use it to build itself, more specifically Mirror’s Android client and sample apps.

Mirror helps us quickly build layouts, custom views and animations with live, interactive previews on real devices. You can make a change to your code and verify on the device in seconds. The fast feedback loop has permanently changed our workflow of building the UI of our apps.

I’ll refrain from talking about our own thing too much here and leave you with a link: http://jimulabs.com.

Bonus: Terminal Tips

Although I spend a lot of time in IntelliJ IDEA, it’s very useful to keep a few terminal windows open. On Mac OSX, I use iTermZsh and YADR. What YADR you ask? “YADR is an opinionated dotfile repo that will make your heart sing” — I’ll let you dive into their website to see what that means. (BTW do you know that IDEA has a built-in terminal?)

Here are a couple of Android-specific things I do in iTerm:

adb logCat

Unfortunately the “Devices | logcat” window in Android Studio still feels buggy to me. It’s slow to catch up the latest logs and sometimes the logs would just disappear. In contrast, running it in command line is rock solid. Additionally, you can open multiple terminals to display different logs at the same time.

Tip: if you want to filter the logs by a log tag, you’ll need to do adb logcat -s MyTag:V. Note the -s flag here, without it, it’ll print all the logs. This took me quite a while to figure out.

Killing Daemons

Have you ever got this nasty error when you try to run the app? Unable to locate a Java Runtime to invoke The solution is simple, run ./gradlew --stop on the command line to kill the Gradle daemon with no mercy.

The Gradle daemon runs in the background to help make builds faster, but sometimes it’ll go into a bad state and it’s time to kill it. Android Studio will restart it properly next time when you run a build.

Conclusions

So here you go, I’ve covered quite a few plugins that you can download and give a try. How do you like them? What are your favourite plugins? Tell me in the comment box below!

For your convenience, here’s a list of all the links mentioned in the post: