Wednesday, 10 October 2012

Error: Could not find class 'com.woodenhero.android.core.CoreClass', referenced from method com.woodenhero.android.cafebabe.MainActivity.onCreate

Has it happened to you? You're building an Android app with another project on the build path and the app crashes with a stack trace like this:


Could not find class 'com.woodenhero.android.core.CoreClass', referenced from method com.woodenhero.android.cafebabe.MainActivity.onCreate
VFY: unable to resolve new-instance 426 (Lcom/woodenhero/android/core/CoreClass;) in Lcom/woodenhero/android/cafebabe/MainActivity;
VFY: replacing opcode 0x22 at 0x0008
DexOpt: unable to opt direct call 0x0bd5 at 0x0a in Lcom/woodenhero/android/cafebabe/MainActivity;.onCreate


This is how you fix it.


Select your referenced project in Package Explorer and go Project -> Properties

Select Android on the left hand pane

In the Library section, check "Is Library"


Select your app project in Package Explorer and go Project -> Properties

Select Android on the left hand pane

In the Library section, click Add...

Select the app of your referenced project

Click OK then OK again to close the Properties dialog



Clean, compile and run again. You should be good to go.

Monday, 2 July 2012

How to debug on an Android device in Eclipse

 You have your application written and it works great on the emulator, but you want to try it on a real device. Here's how. The original article is here.

Install the Google USB Driver

Open the Android SDK Manager (from Eclipse, select Window > Android SDK Manager)

Make sure that the Sort By: radio selection is set to API Level and the Updates/New option is selected.

The last folder in the Packages tree view should be titled Extras. In that folder is an item called Google USB Driver. Check that and select "Install packages...". Agree to the terms and conditions and select Install.

Once that's complete, close the Android SDK Manager window.

Set up your Device for Development

Turn on USB Debugging on your device.
For Android versions less than 4.0, the setting is in Settings > Applications > Development
For 4.0 and above it lives in Settings > Developer Options

Install the OEM USB Driver

Here comes the tricky part.

Connect your device over USB.

Open up Computer (Start > Computer in Windows 7)

Right click Computer in the left pane and click Manage in the context menu.

A Computer Management window will appear. Click on Device Manager in the tree view in the left pane. It's under the System tools item.

Your device should be in this list, under Other. Right click it and select Update Drivers. From here you need to manually navigate to the <android-sdk-root>/extras/google/usb_driver folder.

Once selected the driver will install and you'll be able to debug using your device! 

How to update to Android API 16, Jelly Bean 4.1

What's in Android 4.1 Jelly Bean

There's a lot in the new update. Here's a selection of the goodies available.

  • Live wallpapers - users can select a live wallpaper directly from your app
  • More powerful App stack navigation
  • Gapless playback on separate MediaPlayer objects
  • Android Beam supports large file transfers
  • Copy and Paste with Intents
  • Notifications are more customisable
  • Roboto has more font style variants

If you want to see the whole list, check out the the official version page.

How to update Android for API 16


Grab the Android API 16 by running the Android SDK Manager.
For Windows users, run <android install directory>/tools/android.bat.

Make sure to Sort by API Level and check the Updates/New and Installed boxes.


Download all updates you need from the Tools and Extras directories. Make sure you get the Google USB Driver so you can continue to debug on device.

Once the Tools and Extras have been updated and installed, check the Android 4.1 (API 16) box and hit "Install [x] packages..."

Select the radio button "Accept All" then hit Install.

Nearly there! Once the packages are installed, close the Android SDK Manager window and open up Eclipse.

Open the Help menu and select Check for Updates. This should always be done after updating the Android SDK so Eclipse can run smoothly with Android.

Once all your modules are up to date, restart Eclipse for good measure and continue developing for Android!

How to debug extras from an Activity Bundle.

As far as I can tell, there's no simple call in Intent or Bundle to easily debug an Intent's extras.

Here's a bit of code you can use to get the list of extras you've passed to the Activity.

public String debugIntent()
{
    Intent intent = getIntent();

    String result = "";

    Bundle extras = intent.getExtras();
    if (extras == null)
    {
        return "no extras";
    }
    else
    {
        result += "key count: " + extras.keySet().size();
        for (String key : extras.keySet())
        {
            result += "\n" + key;
        }
    }

    return result;
}

This will give you a String that will list each of the extras you have supplied to the current Activity.