How to fix SL4A webCamFacade exception

On some phones, if you try starting the webcam using SL4A, you will get the following exception:

java.lang.RuntimeException: setParameters failed

Yuck!

Thankfully, the fix is simple. I found Paola Garcia‘s solution everywhere I looked on the internet. She was cheerfully answering everyone’s questions all over the place. She said she fixed the problem by changing the preview format from JPEG to NV21:

NV21
Thanks Paola!

But while the fix is simple, the hard part is you have to build a new SL4A app (APK) with the fix. Good news! It’s not really that hard because someone was kind enough to leave instructions. It was a good learning experience for me.

First, follow the first 2/3rds of this post:
http://jokar-johnk.blogspot.com.es/2011/02/how-to-make-android-app-with-sl4a.html
Do only the “compile” steps. The last “how to package your app” part doesn’t really apply to you, since you just want to build SL4A.

I’m writing this post because I ran into some problems using the instructions above. I’m sharing my solutions in case anyone else runs into them too. I think most of the problems are because the post was written in 2011, and the latest libraries and SDKs in 2014 don’t play as nicely together.

The step you’ll want to substitute is when you Import your project source code. Instead of the “official” SL4A, Use hg to clone the SL4A repository from Paola Garcia‘s branch:

hg clone https://olapaola@code.google.com/r/olapaola-android-scripting/

(FYI: I used Tortoise Hg on Windows.)

Now here are the problems I ran into and how I fixed them. (Just in case anyone else runs into them too.)

  1. Missing Android SDK files when compiling
    SL4A needs APIs from the older Android SDK platforms. Check C:\Users\yourname\AppData\Local\Android\sdk\platforms. If you’re missing the directories android-3, android-4, android-7, android-8, you need to download/install them.

    In Eclipse: Window -> Android SDK Manager. Select all the Android SDKs til API Level 8 (Android 2.2).

    Download & install
    Download & install
  2. conversion to dalvik format failed with error 1
    I got this when trying to export the APK after compiling. I couldn’t figure out what the problem was for a while because stupid Eclipse just gave me the error message with no console logs. I finally found the problem when I did “Project -> Run As…” It gave me a helpful error message I could debug. Something about the JDK libraries was conflicting. I made two changes:

    Download JDK 1.6.0_26 and select it here
    Download JDK 1.6.0_26 and select it here
    Drop the Java compiler to 1.6
    Drop the Java compiler to 1.6
  3. Export APK
    I’m an Android noob so this step tripped me up too.
    Export signed package
    Export a signed package. Create a new keystore. I filled in blanks with B.S. and set passwords to “android”.

Finally, out pops your fresh APK with WebCamFacade fixed. Transfer the APK to your phone, uninstall the old SL4A app and install this new one.

Happy hacking! If these instructions were helpful, leave a comment below. Let us know what silly things you used your camera for. I know I have my eye on OpenCV 🙂

Leave a comment

Your email address will not be published. Required fields are marked *