How-to debug native code with Android

This is a step by step guide for executing and debugging native code on Android with Eclipse.

1. Prerequisites

The SDK version used for this guide is Froyo with the NDK r4b ( crystax release ).
Also Eclipse CDT plugin it’s very useful for our purposes, so install it.
Last plugin to install it’s the Sequoyah plugin for Eclipse.

2. Project setup

At this point let’s create a new Android project, name it “Example” and use the “com.darkwavegames.com” package name, add also an Activity name of your choice.
Select Android 2.2 as base SDK version and complete the project wizard.

Now you need to add the native support for the newly created project. Just right click on the project root element in the package explorer and select “add native support”.

In the next dialog write the path of your NDK folder and give also name for your library.
After this operation a new folder “jni” will be created with a .cpp file, header filer and an Android makefile, Android.mk, which can be edited to modify all the includes, linker and compiler options. In the Android.mk file you also need to specify all the source file you want to use within the LOCAL_SRC_FILE directive.

3. Debug

In order to enable debug of native code in Android you have to face different problems, based also on the device and the firmware version, and if the native code is multi thread or single thread.
First of all you need to mofify the AndroidManifest.xml file adding the attribute “debuggable” to true ( remember also to enable the “Debug USB” option under the Application device menu ).
At this point you can debug all the java code within your eclipse debugger, for for the native C debug you need more steps.

Continue reading

Flex sdk 3.5.0 problem with ternary operators

I’ve got problems to isolate the problem into a very big project with many linked sources. After hours inspecting and commenting lines of code trying to figure out the reason why flex gave me an “internal error” I found the problem.
This very simple script was crashing the flex compiler if using the 3.5.0 sdk ( revision 3.5.0.12683 ).
Fortunately the 4.0.0 compiler works fine. At the end it seems to be the combination of “+” and “-” and the ternary operator.
package
{
   import flash.display.Sprite;
   public class ternary_test extends Sprite
   {
      public function ternary_test()
      {
         var n: Number = 0;
         var d: int = 3;
         var k: int = 5;
         var j: int = 10;
         n = 1 + ( -( d == 0 ? k : j ) );
         trace( "n=" + n );
      }
   }
}

will cause the compiler to crash with the following stack trace:

compile:

    [mxmlc] Loading configuration file /Applications/Adobe Flash Builder 4 Plug-in/sdks/3.5.0/frameworks/flex-config.xml

    [mxmlc] Error: null

    [mxmlc] java.lang.NullPointerException

    [mxmlc] 	at macromedia.asc.semantics.ConstantEvaluator.evaluate(ConstantEvaluator.java:1290)

    [mxmlc] 	at macromedia.asc.parser.UnaryExpressionNode.evaluate(UnaryExpressionNode.java:51)

    [mxmlc] 	at macromedia.asc.semantics.ConstantEvaluator.evaluate(ConstantEvaluator.java:2153)

    [mxmlc] 	at macromedia.asc.parser.ListNode.evaluate(ListNode.java:44)

    [mxmlc] 	at macromedia.asc.semantics.ConstantEvaluator.evaluate(ConstantEvaluator.java:1497)

    [mxmlc] 	at macromedia.asc.parser.BinaryExpressionNode.evaluate(BinaryExpressionNode.java:56)

    [mxmlc] 	at macromedia.asc.semantics.ConstantEvaluator.evaluate(ConstantEvaluator.java:2124)

    [mxmlc] 	at macromedia.asc.parser.ArgumentListNode.evaluate(ArgumentListNode.java:45)...

Apple is evil and developers are not stupid

If you’re an iPhone developer probably you have been involved in the messy App Store publishing process.
Here there is a very interesting post about the Apple’s mistakes: http://www.paulgraham.com/apple.html
More or less I’m completely agree with the author, especially about the app store policies, because I tested in first person. There would be dozen of other topics I can found about it, but the app store is the perfect example.
But yesterday I discovered this post: “Apple is not evil. iPhone developers are stupid“.
After reading that post I realized that developers are stupid because they pretend to publish their applications on the App Store! Wow, I never thought about this! When I signed the iphone sdk I didn’t read anywhere that I should publish my applications on the web because the app store is a mess!
I don’t question the fact that many applications could be published on the web, but that’s is another thing. The point is: I have the choice and I want to choose.
So the conclusion is that we are stupid because we don’t understand how much Apple is evil and we don’t publish applications on the web instead of trying to publish them on the App Store!
The assumption is that I have an application that could be either published on the app store as standalone application and on the web, and is my mistake if I want to publish on the app store.
So why apple simply doesn’t close the App Store for us poor developers and keeps it only for the big companies which pay in order to be in the front page?

New Flash player 9,0,45 & Flex patch

If you’re a Flex 2 developer you should download the newly released Flash player 9.0.r45 debug version.

Once installed the new player remember to apply also this patch to Flex builder 2, otherwise it will throw you an error every time debugging an app (expecially if you’re using Firefox).
This patch also does the following:

“This patch allows the Flex SDK and Flex Builder to use SWFs and SWCs created by Flash CS3 Professional. After applying the patch you should be able to take classes and symbols compiled with Flash CS3 Professional and compile them into a Flex application. You should also be able to take classes and libraries compiled with Flex and use them in a Flash CS3 Professional project.

In addition, this patch allows the Flex debugger (fdb) to function correctly with Flash Player 9 (9.0.45.0) in the Mozilla browser.”

Flex 2.0.1 SDK Hotfix 1 (bug fix)

Adobe just released an update for Flex 2.0.1 SDK, download it from http://www.adobe.com/cfusion/knowledgebase/index.cfm?id=kb401224

Flex 2.0.1 SDK hotfix 1 (build 159086) is a collection of bug fixes that have been completed since the Flex 2.0.1 release on January 5, 2007. This hotfix release is being made available to Flex customers who are experiencing any of the issues described in this document and require the provided bug fixes. Installation of this hotfix release is not recommended for customers who are not experiencing one of the described issues.

Cell Renderers
192854 itemEditors on DataGrid don’t correctly commit data when dragEnable=true
192558 Combo renderer in a DataGrid causes problems on the DataGrid scroll
DataGrid
193316 DataGrid with headerRenderer and selectedIndices becomes uneditable
194284 DataGrid incorrectly focuses hScrollbar
194311 After clearing data from DataGrid, RTE occurs
183325 When set verticalScrollPolicy=”off” in datagrid, can’t move up/down to show more rows
192117 DataGrid whose width depends on the size change of Browser gets RTE
196149 DataGrid with lockedColumnCount incorrectly displays using vScrollbar
193106 Horizontal scrolling DataGrid cannot display the updated width
194972 DataGridColumn visibility=false doesn’t work (when set in mxml)
192466 The width of the last 2 columns is displayed narrower after horizontal scrolling
193641 If you resize the player window with a DataGrid with width=100%, the DataGrid’s last column continues to grow rather than showing more columns
192695 After horizontal scrolling, changing the width of DG updates the width of incorrect column
192694 Changing the width of DataGrid that is disappeared gets error (RTE)
192728 Using an itemRenderer as an editor may not update the dataProvider
195589 DataGrid with horizontalScrollPolicy cell and width behavior changed
193319 Change event doesn’t occur when moving the line using Enter and Tab key on DataGrid
195389 Tab key is functional even if scrollbar is focused
Debugging (Macintosh only)
193086 Once RTE is thrown and debug session is selected to be terminated, closing browser window does not let FB release debug session
Other
193354 CollectionChangeEventKind in CollectEvent.COLLECTION_CHANGE incorrect
192765 If you use MenuBar.dataDescriptor.setEnabled(…) on a top level item of a MenuBar, the item is not changed
126610 Binding to a static variable gives warning Unable to detect changes to ‘var’ and does not show changes
193102 Parent window becomes available after close grandchild Popup
194872 Update PhotoViewer sample README.html file with the additional compiler arguments needed to compile
Tree
192365 Selecting a node then collapsing its grandparent doesn’t move selection up to the grandparent
192347 RTE when tweening occurred while opening nodes in Tree (in Flex Explorer sample)

BTW, it seems they haven’t fixed the Nullpointer exception caused by invalid xmllists..

Flash 9 Preview & Flex 2

On Adobe Labs (http://labs.adobe.com) it’s finally available a preview version of Flash 9. described as “A preview of the next release of the Flash authoring tool, scheduled for release in 2007, extends the capabilities of Flash Professional 8 to include support for the new ActionScript 3.0 language in Flash Player 9.”

To download the preview it’s necessary an Adobe account (you can create one, it’s free) while the installation needs a licensed copy of Flash Professional 8 or Studio 8, because a serial number will be asked during the software setup.
Finally, after Flex 2 Betas, we’ll try also the new Flash IDE!

By the way, Flex 2 seems available at http://www.adobe.com/products/flex/ !
As promised the Flex 2 SDK is available for free:
Download Flex 2 SDK