Showing posts with label class. Show all posts
Showing posts with label class. Show all posts

Monday, 12 November 2012

How to attach Android source to Eclipse

Don't you hate it when you hit F3 on an Android class and you get Eclipse's ugly class viewer instead of Android's actual source for that class?



There's an easy way to fix it.


In Package Explorer expand your Android library entry (in the case above it's Android 4.1) and right click the android.jar file.

Select Properties...

Fill out the information like I've done here.


In summary, select Java Source Attachment in the left pane.
Mark the External location radio button.
Enter the path of the Android source you've downloaded through the Android SDK Manager.

If you don't have the contents of <android_sdk_location>/sources/<android_version> then you'll need to open your Android SDK Manager and download the source for the appropriate version.

Now next time you want to Open Declaration for an Android class, it'll be in a format that's not going to burn out your eyes. :]

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.