Copy link to clipboard
Copied
My company is developing a game for the iPhone and iPad devices using Flash cs5.5 and Air3.0
The client requires that certain features be supported - such things like GameCenter, Rating system, etc... none of which is currently supported by flash for the iOS.
However, they did provide us with a bunch of xCode sample files on how they want things to work.
My idea was to bridge the gap in functionality by creating a native exention that utilized the xcode source that was given to me, thus giving me the functionality that is required.
But first, I need to actually CREATE a native extension, even just a basic echo/hello world... I have followed all the steps from various guides and tutorials and I have managed to create an ipa and put it on my iPad2 to test, but when the program starts up, nothing happens, I am left with a black screen. When I comment out the lines of code that intialize the extension, it fires up just fine.
(and yes, I even tried to put things in try blocks in case there was an error - no luck)
So I am hoping that someone can read through the process of what I am doing below and point out what I am doing wrong, or what I am missing.
What I am using:
Mac Mini running OSX 10.7.2 - this is used to run xCode 4.1 build 4B110
PC - Windows 7 home 64bit - Running Flash CS5.5 (version 11.5.1.3469) with the AIR 3.0 SDK inside it. I also have the AIR 3.0 sdk in a seperate folder for command line running. (This is my primary developement platform)
The PC does have flash builder installed, but I have never really used it, nor do I know how to use it... everything that has been built to date has been done using Flash CS5.5
So, this is what I have done.
The first thing I do is create a .a static library on the mac.
I open xcode and create a new project.
//
// EchoExtension.m
// EchoExtension
//
#include "FlashRuntimeExtensions.h"
FREObject echo(FREContext ctx, void* funcData, uint32_t argc, FREObject argv[]) {
return argv[0];
}
//----------- Extention intializer and finalizer ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
// A native context instance is created
void ContextInitializer(void* extData, const uint8_t* ctxType, FREContext ctx, uint32_t* numFunctionsToTest, const FRENamedFunction** functionsToSet) {
// setup the number of functions in this extention
// for easy reference, set the number of function that this extention will use.
int FunctionCount = 1;
// set the pointer reference to the number of function this extention will use.
*numFunctionsToTest = FunctionCount;
// create an array to store all the functions we will use.
FRENamedFunction* func = (FRENamedFunction*)malloc(sizeof(FRENamedFunction)*FunctionCount);
// create an array entry for each function
func[0].name = (const uint8_t*)"echo"; // the name of the function
func[0].functionData = NULL; // the data type
func[0].function = &echo; // reference to the actual function
// save the array in a pointer.
*functionsToSet = func;
}
// A native context instance is disposed
void ContextFinalizer(FREContext ctx) {
return;
}
// Initialization function of each extension
void ExtInitializer(void** extDataToSet, FREContextInitializer* ctxInitializerToSet, FREContextFinalizer* ctxFinalizerToSet) {
*extDataToSet = NULL;
*ctxInitializerToSet = &ContextInitializer;
*ctxFinalizerToSet = &ContextFinalizer;
}
// Called when extension is unloaded
void ExtFinalizer(void* extData) {
return;
}
I am now finish with that god foresaken mac (*shudders*)
Back on my PC, I create a folder for my test project. For all intents an purposes, let's call this "D:\src\EchoExtension" I then create 2 folders, one called "lib" and one called "app". Lib is where I will create the actionscript source for my extension.
package com.extensions.EchoExtension
{
import flash.events.EventDispatcher;
import flash.events.IEventDispatcher;
import flash.external.ExtensionContext;
public class EchoExtension extends EventDispatcher
{
protected var _extensionContext:ExtensionContext;
/**
* Constructor.
*/
public function EchoExtension()
{
super();
// Initialize extension.
_extensionContext = ExtensionContext.createExtensionContext( "com.extensions.EchoExtension", "main" );
}
public function echo(Prompt:String):String
{
return _extensionContext.call( "echo" ) as String;
}
}
}
import com.extensions.EchoExtension.EchoExtension;
var ext:EchoExtension = new EchoExtension();
stop();
<extension xmlns="http://ns.adobe.com/air/extension/2.5">
<id>com.extensions.EchoExtension</id>
<versionNumber>1</versionNumber>
<platforms>
<platform name="iPhone-ARM">
<applicationDeployment>
<nativeLibrary>libEchoExtension.a</nativeLibrary>
<initializer>ExtInitializer</initializer>
<finalizer>ExtFinalizer</finalizer>
</applicationDeployment>
</platform>
</platforms>
</extension>
D:\SDKs\AirSDK30\bin\adt -package -target ane EchoExtension.ane extension.xml -swc EchoExtension.swc -platform iPhone-ARM library.swf libEchoExtension.a
Now that I have my swc, ane, and all that, it's time to create my sample application that will be used to test my new extension.
// basic imports.
import flash.desktop.NativeApplication;
import flash.events.MouseEvent;
import flash.text.TextField;
// import the extension from our swc.
import com.extensions.EchoExtension.EchoExtension;
// set our input text field to need the softkeyboard
txtInput.needsSoftKeyboard = true;
// add the event handlers to our buttons.
btnEcho.addEventListener(MouseEvent.CLICK, btnEcho_Click);
btnClear.addEventListener(MouseEvent.CLICK, btnClear_Click);
btnRunTime.addEventListener(MouseEvent.CLICK, btnRunTime_Click);
// create our extension variable.
var ext:EchoExtension;
try
{
// initialize our echo extension.
ext = new EchoExtension();
} catch (e:Error) {
txtEcho.text = "Error trying to create new EchoExtension:\n\n" + e;
}
stop();
// clear the echo text field
function btnClear_Click(e:MouseEvent):void
{
txtEcho.text = "";
}
// just for testing, put the current version of air runtime into our text field so we can make sure we are running air 3.0
function btnRunTime_Click(e:MouseEvent):void
{
txtEcho.text += "\nRuntime version = " + NativeApplication.nativeApplication.runtimeVersion;
}
// call the extension, passing it whatever is in the input text field and have it return it and place it in our echo text field
function btnEcho_Click(e:MouseEvent):void
{
txtEcho.text += "\n";
try
{
txtEcho.text += ext.echo(txtInput.text);
} catch (e:Error) {
txtEcho.text += "\nError calling ext.echo: " + e;
}
}
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<application xmlns="http://ns.adobe.com/air/application/3.0">
<extensions>
<extensionID>com.extensions.EchoExtension</extensionID>
</extensions>
<id>EchoExtensionTester</id>
<versionNumber>1.0</versionNumber>
<filename>EchoExtensionTester</filename>
<description/>
<!-- To localize the description, use the following format for the description element.<description><text xml:lang="en">English App description goes here</text><text xml:lang="fr">French App description goes here</text><text xml:lang="ja">Japanese App description goes here</text></description>-->
<name>EchoExtensionTester</name>
<!-- To localize the name, use the following format for the name element.<name><text xml:lang="en">English App name goes here</text><text xml:lang="fr">French App name goes here</text><text xml:lang="ja">Japanese App name goes here</text></name>-->
<copyright/>
<initialWindow>
<content>EchoExtensionTester.swf</content>
<systemChrome>standard</systemChrome>
<transparent>false</transparent>
<visible>true</visible>
<fullScreen>true</fullScreen>
<aspectRatio>landscape</aspectRatio>
<renderMode>gpu</renderMode>
<maximizable>true</maximizable>
<minimizable>true</minimizable>
<resizable>true</resizable>
<autoOrients>false</autoOrients>
</initialWindow>
<icon/>
<customUpdateUI>false</customUpdateUI>
<allowBrowserInvocation>false</allowBrowserInvocation>
<iPhone>
<InfoAdditions>
<![CDATA[<key>UIDeviceFamily</key><array><string>1</string><string>2</string></array>]]>
</InfoAdditions>
<requestedDisplayResolution>high</requestedDisplayResolution>
</iPhone>
</application>
Error creating files.
An implmentation for native extension 'com.extensions.EchoExtension' required by the application was not found for the target platform.
cls
"D:\SDKs\AirSDK30\bin\adt" -package -target ipa-ad-hoc -storetype pkcs12 -keystore "D:\src\mycert.p12" -storepass MYPASSWORD -provisioning-profile "D:\src\myprovfile.mobileprovision" "EchoExtensionTester.ipa" "EchoExtensionTester-app.xml" "EchoExtensionTester.swf" -extdir ../lib/Build
set /p dummy=
echo done
hrm. Time to do a little trial and error to see if I can figure out where the break down is.
And here I am stuck.
Can anyone tell me what I am doing wrong or what I have forgotten to do?
Thanks.
Hi Can you check if the SWC of the native extension is linked as external?
Following image can help locate and change the SWC link type.
The issue that many people face here (i.e. extension works in fast/interpreter mode and doesnt when packaged as standard mode) happens only when the SWC of the NE is not externally linked.
I hope this helps.
Regards,
Saumitra Bhave
AIR iOS
Copy link to clipboard
Copied
Hi rusty:
Can send us the projects which can reproduce the issue on sbhave [at] adobe [ dot ] com.
Copy link to clipboard
Copied
Finally update. So reverting to XCode 4.1 and iOS SDK 4.3 fixed the problem. I am now able to link against the Security framework as a shared library. Not sure if the problem was due to the compilers in XCode 4.2, building against 5.0 SDK (using the -platformsdk option), or something else. I'll pass more info on to Adobe to see if they can get help get to the bottom of it. At least I'm up and running now, I don't really need any features from 5.0.
Copy link to clipboard
Copied
Hello
Is there any update? I have exactly the same problem with the security Framework.
I'm using Xcode 4.2 and AIR 3.1 and need to write a native Extension with keychain group access.
Thank you
Christoph
Copy link to clipboard
Copied
Putting this up here, the suggestions on this site helped me fix my problem
http://www.liquid-photo.com/2011/10/30/common-native-extension-issues/
Hope it can help someone
Copy link to clipboard
Copied
I got the same problem when trying to make a extensions that use a AVAssetWriter... any update on this problem ? we will install xcode 4.1 to see if this solution work but i hope something else is possible.
EDIT : i got the same problem as rusty ...
compile with shared library YES return type 9 error
Shared library to NO return
"ld: absolute addressing (perhaps -mdynamic-no-pic) used
We use Xcode 4.3, Air 3.2 , all the latest sdk and i don't use -platformsdk as i work on a pc.
other important notice... if i try to set shared librarie to NO while targeting IOS 4.0... it make a build fail! if i target IOS 4.1 it work.. with error absolute addressing (perhaps -mdynamic-no-pic) used ......
We are kind of lost with this bug.... we tried every solution giving on the subject.
Last solution is Xcode 4.1 just like rusty said... i'll write if it work.
Copy link to clipboard
Copied
Same Problem for me:
Error occurred while packaging the application:
ld: absolute addressing (perhaps -mdynamic-no-pic) used in _ASDemoGetStringLength from /var/folders/5f/3xcbv8v96gd6_rq6kbmj13900000gp/T/aa9bb7be-0f0e-4e79-85df-cc835b7dc2cf/libde.das3.ane.CalendarANE.a(CalendarANE.o) not allowed in slidable image. Use '-read_only_relocs suppress' to enable text relocs
Compilation failed while executing : ld64
Build stops completly with this warning.
Flash Buidler 4.7 on Mac OS 10.7.5
Tried with AIR SDK 3.5 and AIR SDK 3.7.
Called Function:
FREObject ASDemoGetStringLength( FREContext ctx, void* funcData, uint32_t argc, FREObject argv[])
{
NSLog(@"+++ ASDemoGetStringLength +++" );
const uint8_t * stringArgument = NULL;
uint32_t strLength = 0;
FREResult status = FREGetObjectAsUTF8(argv[ 0 ], &strLength, &stringArgument);
int32_t value = [ [NSString stringWithUTF8String:(char *) &stringArgument] length ];
FREObject intValue = NULL;
status = FRENewObjectFromInt32(value, &intValue);
return intValue;
}
( line which is reponsible for the error is bold and this demo-code is no vodoo magic ).
"Enabled Linking with shared Libraries" is set to no in XCode.
Any solution from Adobe for this?
This "bug" occurs since 10 months for many devs, like we can see with in this thread.
The problem behind is also known.
But there is no fix for this?
Copy link to clipboard
Copied
Okay,
I've found a fix for this "error/warning":
In Flash Builder 4.7 update the embedded AIRSDK to version 3.5 or greater like described here:
http://helpx.adobe.com/flash-builder/kb/overlay-air-sdk-flash-builder.html
ADDITIONAL:
Replace the embedded AIR SDK in the linked Flex-SDK like described under this link:
http://helpx.adobe.com/x-productkb/multi/how-overlay-air-sdk-flex-sdk.html
Hint: The AIR SDK version for step 1 and step 2 should be exactly the same.
Now update the plattform namespace in your an descriptor files (ANE_NAME-platformoptions.xml and ANE_NAME-extension.xml) to:
<platform xmlns="http://ns.adobe.com/air/extension/3.5">
(Should be the same like AIR SDK version)
And last but not least update your "app-description-XML" (APPNAME-app.xml) to the used AIR SDK version:
<application xmlns="http://ns.adobe.com/air/application/3.5">
That should fix the problems ...
Hope that helps someone.
Happy Cooding!
Copy link to clipboard
Copied
When i try to use command line terminal, using Xcode 5.1 with AIR 14 SDK , i find that embedded.mobileprovision doesnot get included in the final IPA. Is there any fix to this ? Appstore rejects submission over this issue. ( However embedded.mobileprovision can be found in the IPA, created by Flash CS6 or Flash CC IDE )
When i try to inject it manually, the appstore then gives Apple submission certificate signing error.
Copy link to clipboard
Copied
rusty was right.. the only solution found was re-installing xCode 4.1... now it work
Hope adobe come soon with better solution.
Copy link to clipboard
Copied
We've had a similar issue to the original post.
Implementing the Correct Answer from this post partially sorted out our problem, but we seem to run to another issue on the top of it when using more than one ANE.
ip-ad-hoc freezes AIR Application when using ANE
Any help would be very appreciated.