Skip to main content
Inspiring
August 27, 2015
Question

Swift iOS ANE Framework

  • August 27, 2015
  • 6 replies
  • 8817 views

Hey,

Has anybody played with making an iOS ANE using swift?

When using Swift, you can't make a Static Library (.a file). You have to make a framework instead. So in the extension.xml, instead of pointing to a .a file, I'm going to point to the .framework instead.

I'm about to finish up packaging up the ANE to see if this works or not. If anybody have experience in this, share you experience. Thanks.

This topic has been closed for replies.

6 replies

Legend
November 9, 2017

For anyone interested.

I put together a short video tutorial showing the steps to create a Hello World ANE using Swift

SwiftANE- Hello World Example Part 1 - YouTube

Participating Frequently
February 7, 2018

Hello el111

Thanks for such a great FRE swift framework that you put on GitHub.  Now, when adobe has released AIR 28, which supports swift and signing dynamic frameworks, is it helpful to write an ANE without using your FRE framework? 

I have seen all three of your videos on ANEs using swift.  I used your framework and started an ANE. I am using storyboards. 

I am stuck at how can I perform a segue operation to launch a storyboard from SwiftController class. I will appreciate if you could

give me your valuable suggestions or guidance towards right direction.

Thanks.

Warm regards.

Legend
February 7, 2018

FreSwift makes things a lot easier. It is much more complicated to write a Swift based ANE without it.

With FreSwift:

var myString = String(argv[0])

Without FreSwift:

var myString = ""

var len: UInt32 = 0

var valuePtr: UnsafePointer<UInt8>?

let status: FREResult = FREGetObjectAsUTF8(argv[0], &len, &valuePtr)

if FRE_OK == status {

   myString = (NSString(bytes: valuePtr!, length: Int(len), encoding: String.Encoding.utf8.rawValue) as String?)!

}

Storyboards

You need to package the storyboard with your AIR app.

1) Add a new Target of type Cocoa Touch Framework called "Storyboards"

2) Add new Storyboard (Copy Bundle Resources)

3) Build the framework

4) copy Build/Products/Release-iphoneos/StoryBoards.framework/Main.storyboardc to example/ios_dependencies/device

And to reference the viewController in your ANE

// loads Main.storyboardc

let storyboard = UIStoryboard(name: "Main", bundle: nil)

// get UIViewController with id "viewController"

let vc = storyboard.instantiateViewController(withIdentifier: "viewController")

// get AIR view controller

if let rootViewController = UIApplication.shared.keyWindow?.rootViewController {

    // present vewController from storyboard

    rootViewController.present(vc, animated: true, completion: nil)

}

Legend
August 4, 2017

jadams602​ and I have been testing AIR 27 Beta with regards to the signing of AIR apps which include Swift Dynamic frameworks.

There is now no need for workaround tools or resigning scripts to run on an iOS device.

An issue with using Simulator may need to be resolved, but AIR 26 can be used for this.

Adobe notes:

1. You need to keep external Frameworks inside <Root_IPA_PATH>/Frameworks folder to be signed by ADT. Otherwise external framework files will be ingnored for signing.

2. Frameworks folder contains External Framework library as well as Swift dylib dependencies if any.

3. Reference Packaging command for Sample IPA with external framework:

- Using command line:

bin/adt -package -target ipa-app-store -provisioning-profile <Path_To_ProvisiongProfile> -storetype pkcs12 -keystore <Path_To_Certificate> -storepass <Password> new.ipa SwiftSampleiOS-app.xml SwiftSampleiOS.swf Frameworks -extdir .

Inspiring
February 5, 2017

Looks like with the new AIR 25 beta, AIR is using iOS 10 SDK and will support Swift in an ANE.

User Unknow
Legend
February 5, 2017

Correct me if I was wrong, but Swift libs can be used in Swift-only project. You can't use Swift in Objective-C/C++ projects? But you can use Obj-C in Swift.

AIR was done not in Swift.

Legend
February 6, 2017

Correct me if I was wrong, but Swift libs can be used in Swift-only project. You can't use Swift in Objective-C/C++ projects?

You can call Swift from Objective C projects and call Objective C from C++ projects. If you are feeling crazy you can even combine all 3.

I've done it on OSX projects.

I did some more playing around today with AIR25 beta. I am able to call Swift code from an ANE.

You can build the Swift code into a dynamic framework and reference that from the static lib that is your main ANE.

However, and to my disappointment, I couldn't reference any "FRE" code in my Swift code 

So passing FREObjects, calling FREDispatchStatusEventAsync etc.

ANEs on iOS are different to OSX in that I believe all the ANE FlashRuntime code gets cross compiled into the main app. I could find no way of referencing the FRE code from the Dynamic Framework.

So it might be somewhat useful, but a large chunk of your ANE code would be Objective C.

Inspiring
September 3, 2015

I can't build the ANE. It's not like a zip when you can zip the necessary files and changing the .zip to .ane. Flash Builder knows this isn't an ane file.

Ok, so here's the set up and I keep getting this error

Missing native library implementation 'myFrame.framework' for platform: iPhone-ARM

File structure.

/DatePickerANE.swc

/extension.xml

/platform.xml

/ios/library.swf

      /myFrame.framework

extension.xml

<extension xmlns="http://ns.adobe.com/air/extension/18.0">

    <id>com.minh.truong.datepicker</id>

    <versionNumber>1.0</versionNumber>

    <platforms>

        <platform name="iPhone-ARM">

            <applicationDeployment>

                <nativeLibrary>myFrame.framework</nativeLibrary>

                <initializer>DatePickerExtensionInitializer</initializer>

            </applicationDeployment>

        </platform>

    </platforms>

</extension>

platform.xml

<platform xmlns="http://ns.adobe.com/air/extension/18.0">

    <description>Date Picker ANE</description>

    <copyright>2015</copyright>

    <sdkVersion>9.0</sdkVersion>

    <linkerOptions>

        <option>-ios_version_min 9.0</option>

        <option>-rpath @executable_path/Frameworks</option>

    </linkerOptions>

    <packagedDependencies>

        <packagedDependency>ios/myFrame.framework</packagedDependency>

    </packagedDependencies>

</platform>


ADT package

adt -package -target ane datePickerANE.ane extension.xml -swc DatePickerANE.swc -platform iPhone-ARM -platformoptions platform.xml -C ios .


I've tried it with the platform.xml and without but same result.

kheftel
Inspiring
September 3, 2015

I was able to make a custom ANE with an obj-c framework, not swift, but it should be similar..... hopefully

Posting this in case it helps.

Here's a build script that I run to build the ANE after building my .a and SWCs.  I have to copy any assets from the .framework manually, and the directory HAS to be named iPhone-ARM.

#clear out iphone-arm folder

rm -fR iPhone-ARM/*

# copy swc to build folder

cp ../as3/MyANEAS3Lib/bin/MyANEAS3Lib.swc .

# extract main library.swf, copy to ios folder

cp MyANEAS3Lib.swc tmp.zip

unzip tmp.zip

rm catalog.xml

rm tmp.zip

mv library.swf iPhone-ARM

# copy .a to ios folder

cp ../ios/Build/Products/Release-iphoneos/libMyANE.a iPhone-ARM

# copy framework to build folder

rm -fR MyObjCFramework.framework

cp -R ../ios/Build/Products/Release-iphoneos/MyObjCFramework.framework .

# copy ios framework assets to ios folder

# add or remove lines here as needed - we have a bunch of asset files, a storyboard, etc

cp ../ios/Build/Products/Release-iphoneos/MyObjCFramework.framework/*.png iPhone-ARM/

cp ../ios/Build/Products/Release-iphoneos/MyObjCFramework.framework/*.wav iPhone-ARM/

cp ../ios/Build/Products/Release-iphoneos/MyObjCFramework.framework/*.ttf iPhone-ARM/

cp ../ios/Build/Products/Release-iphoneos/MyObjCFramework.framework/*.xml iPhone-ARM/

cp -R ../ios/Build/Products/Release-iphoneos/MyObjCFramework.framework/MyStoryboard.storyboardc iPhone-ARM/

# extract default library.swf, copy to default folder

cp ../default/MyANEDefaultLib/bin/MyANEDefaultLib.swc ./tmp.zip

unzip tmp.zip

rm catalog.xml

rm tmp.zip

mv library.swf default

# compile ANE

adt -package -target ane MyANE.ane extension.xml -swc MyANEAS3Lib.swc \

  -platform iPhone-ARM -platformoptions platform-ios.xml MyObjCFramework.framework -C iPhone-ARM/ . \

  -platform default -C default/ .

And here's the platform-ios.xml file. it includes my .framework and a couple of  frameworks I need and a .dylib I use.

<platform xmlns="http://ns.adobe.com/air/extension/16.0">

    <description>My ANE with a custom framework</description>

    <copyright>2015</copyright>

    <sdkVersion>8.1</sdkVersion>

    <linkerOptions>

        <option>-ios_version_min 6.1</option>

        <option>-framework CoreData</option>

        <option>-framework StoreKit</option>

        <option>-weak_library /usr/lib/libsqlite3.dylib</option>

    </linkerOptions>

    <packagedDependencies>

        <packagedDependency>MyOBJCFramework.framework</packagedDependency>

    </packagedDependencies>

</platform>

And here's the extension.xml:

<extension xmlns="http://ns.adobe.com/air/extension/16.0">

  <id>com.luckykatworld.LKWAuthentication</id>

  <versionNumber>0.0.2</versionNumber>

  <platforms>

  <platform name="iPhone-ARM">

  <applicationDeployment>

  <nativeLibrary>libMyANE.a</nativeLibrary>

  <initializer>MyInitializer</initializer>

  <finalizer>MyFinalizer</finalizer>

  </applicationDeployment>

  </platform>

  <platform name="default">

  <applicationDeployment/>

  </platform>

  </platforms>

</extension>

Hope that helps!

Inspiring
September 8, 2015

I got the ANE to build but when I go to run the APP, I keep getting packaging error from Flash Builder.

ld: embedded dylibs/frameworks are only supported on iOS 8.0 and later (@rpath/myFrame.framework/myFrame) for architecture arm64 ld: embedded dylibs/frameworks are only supported on iOS 8.0 and later (@rpath/myFrame.framework/myFrame) for architecture armv7 Compilation failed while executing : ld64

I've built everything for iOS 9 but I keep getting this. What is this?

kheftel
Inspiring
August 28, 2015

I haven't made an ANE with swift but I HAVE made an ANE with a custom .framework.

Once you've made your .framework (ours was made with Obj-c but Swift should work as well, assuming both languages output the same format of .framework), you make ANOTHER project, which is where you make a .a file.  In the second project, you reference and use the .framework as necessary, and also put all your ANE interface code.  The .a gets included into the ANE like normal.  It must be a static library.

You also have to add the .framework as a <packagedDependency> in your platform.xml file, and if your .framework includes any resources, copy them into the iPhone-ARM directory when you build the ANE.

Inspiring
August 28, 2015

‌yeah. I was wondering if I can skip the static library altogether .a file and just use the framework. If not, I guess I would have to build a static library in objective c that calls the swift framework.

I'm hoping it would work  since they're both libraries Of sorts.

kheftel
Inspiring
August 28, 2015

I don't know of any way of creating an ANE using anything other than a static, .a library as the interface between AS3 and Obj-C.  I originally tried to use a dynamic library and that didn't work either.

Of course, just cuz I haven't gotten it to work, doesn't mean it can't be done.........

User Unknow
Legend
August 27, 2015

it's impossible because AIR developed not using swift