java.lang.UnsatisfiedLinkError workaround

If you ever worked with native shared libraries in Android you’ve probably already faced the “java.lang.UnsatisfiedLinkError” java exception which randomly seems to happen on certain devices ( actually it’s happening on xperia phones mostly, based on my reports ).
There are a bunch of bug reports in the android project like this: https://code.google.com/p/android/issues/detail?id=35962 or this https://code.google.com/p/android/issues/detail?id=64111.
The problem is that Google basically marked all of them as “resolved”, even if developers are still complaining about it.

Continue reading

Playing with a LocalActivityManager bug

If you already used the ActivityGroup class you probably used also the LocalActivityManager instance to manage your group’s activities. I was creating my activity which should also manages its internal history ( using a ViewFlipper for animating the activity views ).
The problem came out once I tried to destroy an activity from the history using the LocalActivityManager destroy method. After an activity was removed from both my internal history and from the local activity manager I was unable to create a new instance of the same activity.

After googling for my problem I found that it was because a bug in the LocalActivityManager class: http://code.google.com/p/android/issues/detail?id=12359
This is exactly my problem! In fact, debugging the android code ( see this post for debugging android code ) at that point it was clear that the record it’s not removed from the internal mActivities map.

Fortunately there are Reflections which can help me! I added this piece of code after the call to the destroy method:


Field mActivitiesField = getLocalActivityManager().getClass().getDeclaredField( "mActivities" );
mActivitiesField.setAccessible( true );
((Map) mActivitiesField.get( getLocalActivityManager() )).remove( id );

and that trick does the job

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)...

Vector.splice bug

Usually people complain about opensource projects because they lack of documentation ( that’s true most of the times.. ), but this doens’t happen only there…

Today I’ve spent a lot of time trying to understand why I was so stupid because I wasn’t able to concatenate 2 vectors of int using splice.
But for what you can read from the *official* Adobe documentation, which says (about the third parameter for the splice method):

… items — An optional list of one or more comma-separated values, **or a Vector**, to insert into the Vector at the position specified in the startIndex parameter.

Ok, that’s why I didn’t know why I couldn’t manage to make it work! This simple code gives wrong results:


var v1: Vector. = new Vector.();
v1.push(1);
v1.push(2);
v1.push(3);
v1.push(4);

var v2: Vector. = new Vector.();
v2.push(100);
v2.push(200);
v1.splice( 1, 1, v2 );

// Expected result: [1,100,200,3,4]
// Actual result: [1,0,3,4]

It seems that the third parameter is being casted into int and so only ‘0’ has been inserted into the first Vector!

I tried to look into Adobe jira bugbase and what I’ve found there is that it was a known bug since long time and it has been also moved to the tamarin bugbase.

The problem is that at the end they simply closed the bug as invalid bug because the documentation was wrong!

Funny

Java 6 Update 10 breaks Flex compiler!

I just want to share this problem I found so maybe someone can save some time..

Today while surfing the net I received a notification of an update of my Java installation to the Update 10 in order to see correctly the contents of that site.. bla bla bla..

Sometime later I switched to Flex and at the first execution of my ant script for compiling a flex project I suddenly received this beautiful error:
[exec] Error: java/security/MessageDigest
[exec] java.lang.NoClassDefFoundError: java/security/MessageDigest
[exec] at java.io.ObjectStreamClass.computeDefaultSUID(Unknown Source)
[exec] at java.io.ObjectStreamClass.access$100(Unknown Source)
[exec] at java.io.ObjectStreamClass$1.run(Unknown Source)
[exec] at java.security.AccessController.doPrivileged(Native Method)
[exec] at java.io.ObjectStreamClass.getSerialVersionUID(Unknown Source)
[exec] at java.io.ObjectStreamClass.initNonProxy(Unknown Source)
[exec] at java.io.ObjectInputStream.readNonProxyDesc(Unknown Source)
[exec] at java.io.ObjectInputStream.readClassDesc(Unknown Source)
[exec] at java.io.ObjectInputStream.readNonProxyDesc(Unknown Source)
[exec] at java.io.ObjectInputStream.readClassDesc(Unknown Source)
[exec] at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)
[exec] at java.io.ObjectInputStream.readObject0(Unknown Source)
[exec] at java.io.ObjectInputStream.readObject(Unknown Source)
[exec] at flex.util.SerializedTemplateFactory.load(SerializedTemplateFactory.java:30)
[exec] at flex2.compiler.util.VelocityManager.getTemplate(VelocityManager.java:162)
[exec] at flex2.compiler.util.VelocityManager.getTemplate(VelocityManager.java:151)
[exec] at flex2.compiler.util.VelocityManager.getTemplate(VelocityManager.java:137)
[exec] at flex2.compiler.as3.genext.GenerativeSecondPassEvaluator.generateSupportCode(GenerativeSecondPassEvaluator.java:256)
[exec] at flex2.compiler.as3.genext.GenerativeSecondPassEvaluator.modifySyntaxTree(GenerativeSecondPassEvaluator.java:355)
[exec] at flex2.compiler.as3.binding.BindableSecondPassEvaluator.evaluate(BindableSecondPassEvaluator.java:102)
[exec] at macromedia.asc.parser.ClassDefinitionNode.evaluate(ClassDefinitionNode.java:106)
[exec] at flash.swf.tools.as3.EvaluatorAdapter.evaluate(EvaluatorAdapter.java:338)
[exec] at macromedia.asc.parser.StatementListNode.evaluate(StatementListNode.java:60)
[exec] at flash.swf.tools.as3.EvaluatorAdapter.evaluate(EvaluatorAdapter.java:923)
[exec] at macromedia.asc.parser.ProgramNode.evaluate(ProgramNode.java:80)
[exec] at flex2.compiler.as3.genext.GenerativeExtension.parse2(GenerativeExtension.java:114)
[exec] at flex2.compiler.as3.Compiler.parse2(Compiler.java:386)
[exec] at flex2.compiler.API.parse2(API.java:2390)
[exec] at flex2.compiler.API.parse2(API.java:2348)
[exec] at flex2.compiler.API.batch2(API.java:375)
[exec] at flex2.compiler.API.batch(API.java:1117)
[exec] at flex2.compiler.API.compile(API.java:1290)
[exec] at flex2.compiler.API.compile(API.java:1210)
[exec] at flex2.tools.Compc.compc(Compc.java:158)
[exec] at flex2.tools.Compc.main(Compc.java:41)

so I tried also to compile another project before go crazy, but I got this another java funny error, which was more or less unreadable as the previous one!

Fortunately I remembered the update I did of Java! And in fact after remove that update everything worked again!

cacheAsBitmap hell

Last week I spent a whole day trying to solve an issue in Phoenix due to a strange problem which comes up suddenly after some code changes.
The problem was that now using the transformation tool the bounds of the selected bitmap were not detected correctly and the tool itself didn’t work.
So I spent a lot of time in checking out all the recent code changes ( and they were a lot! ) to find out the possible cause…
Anyway, I was lucky to figure out the problem by accident and the problem was cacheAsBitmap!

The problem with the tool is because in order to find the correct bounds of any element on the stage it use the .concatenatedMatrix property of the element itself ( which represents the combined transformation matrixes of the display object and all of its parent objects, back to the root level ).
BUT if any of its parent display object ( not the root itself ) has the cacheAsBitmap property set to true then the concatenatedMatrix returns a wrong value!

I put a real simple flash example of what I mean. Just click on any of the 2 colored objects to activate the transform tool, then click on the “cache” button and click again on those objects to see the difference.

[kml_flashembed publishmethod=”static” fversion=”10.0.22″ movie=”http://blog.sephiroth.it/wp-content/uploads/2008/03/cacheasbitmap_hell.swf” width=”450″ height=”450″ targetclass=”flashmovie” bgColor=”#ffffcc”]

Get Adobe Flash player

[/kml_flashembed]

P.S. I’ve reported the bug in the flash player bugbase, if anyone is interested in watch or vote for it.

Flex Canvas bug when it is zoomed in and “horizontalCenter = 0”

Recently I came across a Flex bug when working on canvas. If you have a canvas with an object centered inside ( horizontal or vertical, it’s the same ) and scale this object the result is that the canvas will clip left and top its contents!
To understand what I mean see this example and try to scale the image:

[kml_flashembed publishmethod=”static” fversion=”10.0.22″ movie=”http://blog.sephiroth.it/wp-content/uploads/2007/11/canvas_bug.swf” width=”250″ height=”290″ targetclass=”flashmovie”]

Get Adobe Flash player

[/kml_flashembed]

And this is the code used:


< ?xml version="1.0" encoding="utf-8"?>

1









As you can see once the image is scaled and it’s bigger that its parent, you wont be able to see it top left corner anymore. This is an annoying bug for me!

Later I found that someone opened a ticket in the Flex bug management system here: http://bugs.adobe.com/jira/browse/SDK-13009
A couple of days ago I received a notification that the bug has been closed… and incredible they closed it as NOT A BUG!
I can understand that finding the bug in a file with 5000 and more lines of code it’s not easy and can cause horrible headache, but the reason they gave it’s nosense! It’s completely a different thing that the reason of this bug.

Moreover what’s the connection between flash and html?

Flex have been designed since the 1.0 version as a framework for building RIA (Rich Internet Applications).
A RIA have to behave as a desktop application that runs using the web browser. One of the advantages of Flex agains Ajax is that the first technology provide to the user a behaviour which is much more similar to desktop applications that the one provided using HTML+Javascript. And so my questions is: why should Flex behave like HTML when one of its most important features is to be different from HTML ?
Flex behaves like other SDKs used to develop desktop apps in many situations which are much less important than the one hilighted above. So why close this bug (yes. it is a bug) providing as explanation that it is correct because it behaves like HTML ?

SharedObject reader plugin for FD3

In the past week I was working on the SharedObject plugin for FlashDevelop 3.
First I just made a port of my previous sepy sharedobject reader python code into C#, but then for the new AMF3 sharedobject encoding I found this java class very useful.
By the way, after coding and coding.. I finally managed to create a good solution (ok, I have to test it a lot again…).
You can find the plugin here: http://code.google.com/p/fdplugins

But the interesting thing I found was another!
Flash does not read the sharedojects correctly (at least the amf0 ones)!

To reproduce this bug follow these steps:

Create a new document (flash8 / as2)
– Add this code in the timeline:
var so:SharedObject = SharedObject.getLocal("flash8", "/");
so.clear();
so.data.obj1 = new XML("");
so.data.obj2 = new Date();
so.data.obj3 = so.data.obj2;
so.data.obj4 = {a:1, b:so.data.obj1, c:[1,2,3], d:so.data.obj2};
so.data.obj5 = so.data.obj4.c;
so.flush();

you will see this in the debug view variables:
Variabile _level0.so = [oggetto #1, classe 'SharedObject'] {
data:[oggetto #2, classe 'Object'] {
obj1:[oggetto #3] {
;
},
obj2:[oggetto #4, classe 'Date'] {Sat Sep 22 19:31:31 GMT+0200 2007},
obj3:[oggetto #4, classe 'Date'],
obj4:[oggetto #5, classe 'Object'] {
d:[oggetto #4, classe 'Date'],
c:[oggetto #6, classe 'Array'] [
0:1,
1:2,
2:3
],
b:[oggetto #3],
a:1
},
obj5:[oggetto #6, classe 'Array']
}
}

ok, now remove all the code you just written and leave just this line:
var so:SharedObject = SharedObject.getLocal("flash8", "/");
and see the variables list again, you will see this:
Variabile _level0.so = [oggetto #1, classe 'SharedObject'] {
data:[oggetto #2, classe 'Object'] {
obj1:[oggetto #3] {
;
},
obj2:[oggetto #4, classe 'Date'] {Sat Sep 22 19:31:31 GMT+0200 2007},
obj3:[oggetto #5, classe 'Date'] {Sat Sep 22 19:31:31 GMT+0200 2007},
obj4:[oggetto #6, classe 'Object'] {
d:[oggetto #7, classe 'Date'] {Sat Sep 22 19:31:31 GMT+0200 2007},
c:[oggetto #8, classe 'Array'] [
0:1,
1:2,
2:3
],
b:[oggetto #6, classe 'Object'],
a:1
},
obj5:non definito
}
}

they are different! (both data.obj5 and data.obj4.b changed)

For what I understand during my experiments it seems that flash does not write into its internal references table the XML objects while reading back the file and so next time it open the sharedobject all the references after the xml are broken or just they point to a different object.