Problems with Instant Run (Android Studio 2.0 beta 4) and Retrofit

This morning I was playing with a toy app I have which uses Retrofit, and I’ve found the following problem with it (and Instant Run):

02-16 07:41:55.550 2976-2976/com.test.android A/art: art/runtime/thread.cc:1329] Throwing new exception 'length=227; index=1017' with unexpected pending exception: java.lang.ArrayIndexOutOfBoundsException: length=227; index=1017

The exception was in the call itself, so it was either Retrofit doing strange things or something deeper. I found the problem to be because of some interaction between ART and Instant Run, and it was already reported.

The original reporter has opened a bug in the AOSP and it’s still unsolved. See also (Retrofit).

All in all, currently there is no fully reliable solution. So, if you find this problem in a call using Retrofit, the best course of action is to disable Instant Run and rebuild. Preferences -> Build, Execution, Deployment -> Instant Run -> (uncheck) Enable Instant Run to hot swap code/resource changes on deploy (default enabled)

Disable Instant Run

Hilarious Git plugin: git-blame-someone-else

This plugin allows to change the commit author information. Super-useful to avoid to be the one to blame for bugs and mistakes. ;)

“I love git-blame-someone-else!!” –Linus Torvalds says*

*Linus Torvalds didn’t really approve of this. It’s a joke to prove it works. See his fake commit here

Kotlin RC and kotlinx

I’ve been toying with Kotlin for a while. Yesterday RC was released, making it one step closer to have a stable version.

One small change that has made me scratch my head a little, even if I read the solution, has been the changes regarding Kotlin Extensions. This had been integrated with the main Kotlin plugin (instead of being a separated plugin) but on RC you need to change your Gradle file a little to keep using it.

The symptom is that you find an “Unresolved reference: kotlinx” plus others that come from the same namespace. Resolution is easy: in the announcement for the release Kotlin 1.0 Release Candidate is Out! in the section Tooling, it reads (bold is mine):

To enable Android Extensions in Gradle in a more idiomatic way, we now say:

apply plugin: 'kotlin-android-extensions'

in the build.gradle file (individually for each project).

The old way doesn’t work any more and prints fixing instructions to the output.

So, I haven’t found this instructions, but the solution is easy: apply the new kotlin-android-extensions plugin right after the kotlin-android plugin in your gradle file. Usually, the end result will be like this:

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'

After that you just need to sync your Gradle configuration and rebuild the whole project.

FizzBuzz in CSS

Wat

Fun moment: Wat

Re-enabling Xcode plugins

After updating my Xcode, I noticed that plugins got disabled. To reenable them, the easiest way is just “touching” all the plugin directories:

$ cd ~/Library/Application\ Support/Developer/Shared/Xcode/Plug-ins
$ touch *

After that, restart Xcode and you will get a dialog asking if plugins should be loaded.

An alternate take on this is can be found here: Re-enable Alcatraz on Xcode 6.3.2 or Newer

Additional tip: if the update was the OS, maybe this StackOverflow answer can be also useful: CocoaPods doesn’t work after upgrading Mac OS X EI Capitain.

UPDATE: I’ve updated to Xcode 7.2 today, and suddenly all the plugins stopped to work. There is an update for Alcatraz. See also this tweet.

UPDATE2: There is a new upgrade for Alcatraz for Xcode 7.3. See this tweet. You need to first update it, then “touch” the plugins (see above), execute:

$ defaults delete com.apple.dt.xcodebuild DVTPlugInManagerNonApplePlugIns-xcodebuild-7.3
$ defaults delete com.apple.dt.Xcode DVTPlugInManagerNonApplePlugIns-Xcode-7.3

Additionally, I guess that some plugins need an update, because they are not working (for example CocoaPods).

Easily manage windows in OS X

I’ve been using OS X for many years already, and as my primary computer OS for almost a year. Before that, I used to spend time with Windows (like 90% of it), Linux (for server) and OS X.

There are two things that I missed after switching from Windows (last version I regularly used was 8.1) to OS X (I started to regularly use it on Tiger), being a heavy keyboard user: the way window cycling works on Windows, and Windows snap (available since Windows 7, including shortcuts).

Window switch

Window switch shortcut on Windows (Alt+Tab) cycles through all your windows, in usage order, but on OS X (Cmd+Tab) cycles through applications. There is a second shortcut, which usually is assigned to Cmd+`. This shortcut is quite cumbersome, at least on Spanish keyboard layout (maybe also on English layout too): as soon you enter in a text field of any kind, if you press this shortcut you get the ` character, waiting for you to complete an accented letter (yes, in Catalan and Spanish languages we have such a thing). Additionally you cycle through your windows immediately, without preview, and without remembering your usage order.

There are two solutions here:

  • change the shortcut in System Preferences (preview and usage order still missing here),
  • use Witch (thanks to Jaume Sánchez for pointing me this out).

I prefer using Witch, as it has lots of options, allowing you to use a switcher more like Windows one, making no distinction between windows and apps, or use it the way I do, which is to use it as an improvement to OS X default way of switching between windows inside an application. BTW I use Alt+Cmd+Tab as this shortcut, and doesn’t conflict with any other shortcut, working all the time.

Windows Snap

When working with many windows, sometimes is useful to be able to “snap” windows to one side of the screen or the other. This feature is really useful on Windows (starting from 7), but I’ve been missing it on OS X since the beginning. Also, maximizing not always maximizes in both directions, but only in vertical (depends on the application). Finally, on OS X “El Capitan”, maximize button has changed to fullscreen as the default option, having to press Alt to maximize. This version of OS X also includes a feature like Snap, but only works for fullscreen apps.

So, recently I found a way of overcoming this and having nice shortcuts “a-la-Windows”: Spectacle. This nice app sits in your menu bar and helps you to quickly resize your windows (snap, fullscreen, even quarter of screen snap), move them between screens, even undo and redo this actions!