Native extension on Mac OS X (Air 3)
Hi
I have a blocking issue for native extensions when targetting the MacOS-x86 platform. (in my case Snow Leopard)
I succeded in packaging the ANE file, but I have this error when using it in my test app:
[SWF] tekhnia.simpleAirNativeExtension - 2 871 octets après la décompression
[SWF] simpleAirNativeExtensionTest.swf - 2 119 250 octets après la décompression
Context: [object ExtensionContext] in /Users/vandrito/Documents/Projets/o3sui/.metadata/.plugins/com.adobe.flexbuilder.project.ui/ANEFiles/simpleAirNativeExtensionTest/macosx/simpleAirNativeExtension.ane
ArgumentError: Error #3500: The extension context does not have a method with the name isSupported.
at flash.external::ExtensionContext/_call()
at flash.external::ExtensionContext/call()
at tekhnia.org.simpleAirNativeExtension::simpleAirNativeExtension/isSupported()[/Users/vandrito/Documents/Projets/o3sui/simpleAirNativeExtension/src/tekhnia/org/simpleAirNativeExtension/simpleAirNativeExtension.as:16]
at simpleAirNativeExtensionTest/init()[/Users/vandrito/Documents/Projets/o3sui/simpleAirNativeExtensionTest/src/simpleAirNativeExtensionTest.mxml:15]
at simpleAirNativeExtensionTest/___simpleAirNativeExtensionTest_WindowedApplication1_creationComplete()[/Users/vandrito/Documents/Projets/o3sui/simpleAirNativeExtensionTest/src/simpleAirNativeExtensionTest.mxml:5]
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at mx.core::UIComponent/dispatchEvent()
at mx.core::UIComponent/set initialized()
at mx.managers::LayoutManager/doPhasedInstantiation()
at mx.managers::LayoutManager/doPhasedInstantiationCallback()
In fact it seems that the initializer is not executed. This is my extension declaration file:
<extension xmlns="http://ns.adobe.com/air/extension/3.1">
<id>tekhnia.simpleAirNativeExtension</id>
<versionNumber>1.0.0</versionNumber>
<name>tekhnia.simpleAirNativeExtension</name>
<copyright>@17369164 OpenTekhnia, Techniware</copyright>
<platforms>
<platform name="MacOS-x86">
<applicationDeployment>
<nativeLibrary>simpleAirNativeExtension.framework</nativeLibrary>
<initializer>initNativeExtension</initializer>
<finalizer>doneNativeExtension</finalizer>
</applicationDeployment>
</platform>
</platforms>
</extension>
That's my *.m file in the xcode framework project:
#import "simpleAirNativeExtension.h"
FREObject isSupported(FREContext ctx,
void *functionData,
uint32_t argc,
FREObject argv[]) {
FREObject retObj;
FRENewObjectFromBool(1, &retObj);
return retObj;
}
// contextInitializer()
//
// The context initializer is called when the runtime creates the extension context instance.
void contextInitializer(void* extData, const uint8_t* ctxType, FREContext ctx,
uint32_t* numFunctions, const FRENamedFunction** functionsToSet) {
*numFunctions = 1;
FRENamedFunction* func = (FRENamedFunction*)malloc(sizeof(FRENamedFunction) * (*numFunctions));
func[0].name = (const uint8_t*) "isSupported";
func[0].functionData = NULL;
func[0].function = &isSupported;
*functionsToSet = func;
}
// contextFinalizer()
//
// The context finalizer is called when the extension's ActionScript code
// calls the ExtensionContext instance's dispose() method.
// If the AIR runtime garbage collector disposes of the ExtensionContext instance, the runtime also calls
// contextFinalizer().
void contextFinalizer(FREContext ctx) {
// Nothing to clean up.
return;
}
// initMulticastSocket()
//
// The extension initializer is called the first time the ActionScript side of the extension
// calls ExtensionContext.createExtensionContext() for any context.
void initNativeExtension(void** extDataToSet, FREContextInitializer* ctxInitializerToSet,
FREContextFinalizer* ctxFinalizerToSet) {
*ctxInitializerToSet = &contextInitializer;
*ctxFinalizerToSet = &contextFinalizer;
}
// done()
//
// The extension finalizer is called when the runtime unloads the extension. However, it is not always called.
void doneNativeExtension(void* extData) {
// Nothing to clean up.
return;
}
and that's my .h:
//
// simpleAirNativeExtension.h
// simpleAirNativeExtension
//
// Created by Victor Andritoiu on 17/10/11.
// Copyright (c) 2011 OpenTekhnia. All rights reserved.
//
#import <Foundation/Foundation.h>
#include "Adobe Air/FlashRuntimeExtensions.h"
void initNativeExtension(void** extDataToSet, FREContextInitializer* ctxInitializerToSet,
FREContextFinalizer* ctxFinalizerToSet);
void doneNativeExtension(void* extData);
FREObject isSupported(FREContext ctx,
void *functionData,
uint32_t argc,
FREObject argv[]);
void contextInitializer(void* extData, const uint8_t* ctxType, FREContext ctx,
uint32_t* numFunctions, const FRENamedFunction** functionsToSet);
void contextFinalizer(FREContext ctx);
@Interface simpleAirNativeExtension : NSObject
@8978565
And finally my AS3 code for the lib:
package tekhnia.org.simpleAirNativeExtension
{
import flash.external.ExtensionContext;
public class simpleAirNativeExtension {
/** extension context */
protected var context: ExtensionContext;
public function simpleAirNativeExtension() {
context = ExtensionContext.createExtensionContext("tekhnia.simpleAirNativeExtension", "");
trace("Context: " + context + " in " + ExtensionContext.getExtensionDirectory("tekhnia.simpleAirNativeExtension").nativePath);
}
public function isSupported(): Boolean {
return context.call("isSupported") as Boolean;
}
}
}
and for the app using it:
<?xml version="1.0" encoding="utf-8"?>
<s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
creationComplete="init()">
<fx:Script>
<![CDATA[
import mx.events.FlexEvent;
import tekhnia.org.simpleAirNativeExtension.simpleAirNativeExtension;
protected function init(): void {
var sane: simpleAirNativeExtension = new simpleAirNativeExtension();
trace(sane.isSupported());
}
]]>
</fx:Script>
<fx:Declarations>
<!-- Placer ici les éléments non visuels (services et objets de valeur, par exemple). -->
</fx:Declarations>
</s:WindowedApplication>
If anybody succeeded in using extensions on MacOS, please first tell me that s possible then, maybe help me on getting the error that I make.
Thanks a lot
Victor
