XCODE快速开发ANE步骤和一些常见错误的解决

使用adobe air制作的移动应用,在对接第三方平台的时候,需要使用ANE来包装本机代码,在对接过程中,我积累了一些打包ANE的经验,记录下来,希望对看到的人有些帮助。 吐槽一下,ANE太难对付了,各种坑,调试也比较麻烦。 1、安装mac版本的AIR SDK 下载地址:http://www.adobe.com/devnet/air/air-sdk-download-mac.html 2、安装xcode的ANE项目模板(好东西~) 下载地址:https://github.com/divijkumar/xcode-template-ane 3、从模板新建项目: snap (2).jpg snap (3).jpg 项目建好了的样子: snap (4).jpg 直接点左上角的小三角形编译,报错如下: snap (5).jpg 提示不支持的编译器 解决:我们点击项目属性,选择 LLVM5.13 snap (6).jpg 继续点编译: snap (7).jpg 成功了,生成的库文件是libhello.a 接下来我们开始生成ane,点击编译目标: snap (8).jpg 选择hello.ane snap (9).jpg 再点小三角编译,成功(在*.ane上右键选Show in Finder可以定位到这个ane文件): snap (10).jpg 如果在项目创建页面没有填写这个个: snap (11).jpg 则会提示错误: snap (12).jpg 解决方法是,在项目属性里设置这个宏参数,填上swc文件所在的全路径: snap (13).jpg 剩下的事情就是增加你自己需要的接口来,在hello.m文件里,可以看到模板示例方法:isSupported,自己写代码可以参照它。 另外如果需要使用C++和objec混编,则需要项目中至少有一个后缀为mm的源文件,你可以创建一个空mm文件即可。


在ios本机库,AIR SDK包含了以下系统库: snap (14).jpg 如果项目依赖了除了上面列表之外的库,需要打开项目下的那个:platformoptions.xml 填上依赖的动态库(*.dylib)或者静态库framework(*.framework) 动态库用-l前缀,framework用-framework前缀 snap (15).jpg 如果不在上面xml中指定,打包ANE是不会报错的,但是在打包ipa的时候,会报类似下面的错:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
Undefined symbols for architecture armv7:
"_crc32", referenced from:
_PyZlib_crc32 in libpython2.7.a(zlibmodule.o)
"_inflateEnd", referenced from:
_Decomp_dealloc in libpython2.7.a(zlibmodule.o)
_PyZlib_decompress in libpython2.7.a(zlibmodule.o)
_PyZlib_unflush in libpython2.7.a(zlibmodule.o)
"_deflateInit_", referenced from:
_PyZlib_compress in libpython2.7.a(zlibmodule.o)
"_inflate", referenced from:
_PyZlib_decompress in libpython2.7.a(zlibmodule.o)
_PyZlib_objdecompress in libpython2.7.a(zlibmodule.o)
_PyZlib_unflush in libpython2.7.a(zlibmodule.o)
"_deflateEnd", referenced from:

在使用该ANE打包ipa的过程中,如果使用了多个ANE,且里面引用了同一个公用类,会提示重复的符号: snap (1).jpg 解决方法是在调用adt打包ipa的时候,增加参数:-hideAneLibSymbols yes


如果打包ipa的出现错误(找不到___divmodsi4符号):

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
Packaging: ../hello.ipa
using certificate: hello.p12...

Warning: Resource zh-Hans.lproj has been skipped because of mismatch with suppor
ted languages information in application descriptor.
Undefined symbols for architecture armv7:
"___divmodsi4", referenced from:
_absc_solve in D:\\mobile\\wow_mobile\\..\\wow_app\\AOTBuildOutput62399389
92767853027.tmp\\com.q1.haima.o
ld: symbol(s) not found for architecture armv7
Compilation failed while executing : ld64

APK setup creation FAILED.

Troubleshooting:
- did you build your project in FlashDevelop?
- verify AIR SDK target version in bat\app-haima.xml

解决方案: 1、目标系统版本需要高一些,比如5.1或者6.0以上,在platformoptions.xml 文件的linkerOptions指定参数:-ios_version_min,如下:

1
2
3
4
5
6
7
8
9
10
11
<platform xmlns="http://ns.adobe.com/air/extension/3.1">
<sdkVersion>5.0</sdkVersion>
<description > An optional description</description>
<copyright>2012 (optional)</copyright>
<linkerOptions>
<option>-ios_version_min 5.1</option>
<option>-framework AdSupport</option>
<option>-framework AudioToolbox</option>
<option>-lstdc++.6</option>
</linkerOptions>
</platform>

2、如果改sdk版本还不行,则使用下面方案,在.h头文件里增加下面的函数:

1
2
3
4
5
6
7
unsigned long ___udivmodsi4(unsigned long num, unsigned long den, int modwanted)
{
if (modwanted)
return num % den;
else
return num / den;
}

另外,引起APP闪退的可能原因: 1、调用API函数的参数类型不正确,objc的参数为NSString类型,但是传int类型,在编译时也不会报错,但是在手机运行时会崩溃!!!需要仔细检查是否有该问题 作者:YoYo,原文地址:http://yoyo.play175.com/p/xcode-ane.html

64-bit requirements for iOS apps

本文系转载:http://easynativeextensions.com/making-your-ios-apps-universal/   At the end of last year Apple announced their new requirements for submitting apps to the app store:

This doesn’t pose much of a problem for native apps, but we AIR developers were stranded… Until last week, when Adobe released AIR 16 beta in Adobe Labs. Let us go through the steps necessary for rebuilding your apps and ANEs to support 64 bits.

Step 1: Update your AIR SDK

1.1. Download AIR SDK 16 beta from Adobe Labs: http://labs.adobe.com/downloads/air.html

Note: if you use Flash Builder and/or the Flex SDK, you need the last download link, AIR 16 SDK for Flex Developers.

1.2. Make a backup copy of your AIR SDK folder. 1.3. Overlay the new SDK over the old one: 1.3.1 If you are a Windows user, unzip the download and copy the contents over your AIR SDK. 1.3.2. On Mac you can do the same and ask Finder to merge folders or, you can copy the archive in the root of your AIR SDK and run the following command in the Terminal:

1

sudo tar jxvf air16_sdk_sa_mac.tbz2

Step 2: Update your app descriptor

If you are a veteran AIR developer, you are used to this, but here it is just in case. Open your app descriptor file – usually named your-app-name-app.xml and found in your project’s src/ folder and make sure the namespace at the top of the file points to 16.0:

1

<application xmlns=“http://ns.adobe.com/air/application/16.0"\>

Step 3: Rebuild your iOS ANEs

Any native extensions for iOS that your app uses will also need to be built with 64-bit support. If you have the source code for these ANEs, this is what you do: 3.1. Make sure you are using Xcode 6 and iOS SDK 8. 3.2. In your Xcode project, go to Build Settings > Architectures and first make sure that Architecturesis set to Standard architectures (armv7, arm64), then set Build Active Architecture Only toNo. Without the last change the compiler will default to building a binary that supports only one architecture, which matches the device that you have connected at the moment or the simulator version you have made active – good idea for a debug build, but not for release. Xcode 64bit architecture setting   Now make a clean build of your ANE.

Here are a couple of resources that will help you automate your ANE building and packaging:

Step 4: How do you know if your app is now universal/64-bit?

… before submitting it to the Apple App Store, that is. There are a couple of things you can check. First, if you build your app with AIR 16, you should NOT get an error message like this:

Error: Apple App Store allows only universal applications. “libMultiplatformANETemplateLib.a” is not a universal binary. Please change build settings in Xcode project to “Standard Architecture” to create universal library/framework.

Or like this:

[exec] Error: libCameraLibiOS.a are required to have universal iOS libraries. Please contact the ANE developer(s) to get the same.[exec] Result: 12

Then,  to double-check, do the following: 4.1. Rename your .ipa file to .zip and unzip it. 4.2. Use lipo in the Mac Terminal:

1

lipo path_to_your_unzipped_ipa/Payload/your_app_name.app/your_app_name -info

You want to see a message like this:

1

Architectures in the fat file: your_app_name are: armv7 arm64

4.3. You can also use the file command on Mac:

1

file path_to_your_unzipped_ipa/Payload/your_app_name.app/your_app_name

This should result in a message like this one:

1

2

3

Mach-O universal binary with 2 architectures

your_app_name (for architecture armv7): Mach-O executable arm

your_app_name (for architecture arm64): Mach-O 64-bit executable

Ta-da! Your app is now up to date with the 64-bit requirements.

QQ聊天框自动发消息

[codesyntax lang=”php”]

Set WshShell= WScript.CreateObject(“WScript.Shell”)
WshShell.AppActivate “聊天框名字”
for i=1 to 50
WScript.Sleep 500
WshShell.SendKeys “^v”
WshShell.SendKeys “%s”
next

[/codesyntax] 存为vbs文件,先复制到剪切板,执行程序,会自动发送!可设置次数和间隔等

Bitmap残影练习

有点空,写下效果练习下。 效果截图: shadow     [codesyntax lang=”actionscript3”]

package com.shadow
{
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.display.Sprite;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.events.Event;
import flash.geom.ColorTransform;
import flash.geom.Matrix;
import flash.geom.Rectangle;

[SWF(width=”800”,height=”600”)]
public class Shadow extends Sprite
{

[Embed(source=”../../../assets/phone.png”)]
private var Phone:Class;

private var bgbmd:BitmapData;
private var phone:Bitmap;

private const WIDTH:int = 800;
private const HEIGHT:int = 600;
private var speedX:int;
private var speedY:int;

public function Shadow()
{
super();
this.addEventListener(Event.ADDED_TO_STAGE,addToStage);
}

protected function addToStage(event:Event):void
{

stage.align = StageAlign.TOP_LEFT;
stage.scaleMode = StageScaleMode.NO_SCALE;

phone = new Phone() as Bitmap;
bgbmd = new BitmapData(WIDTH,HEIGHT);
var bg:Bitmap = new Bitmap(bgbmd);
addChild(bg);

this.speedX = 20;
this.speedY = 10;

this.addEventListener(Event.ENTER_FRAME,loop);
}

protected function loop(event:Event):void
{

phone.x += speedX;
phone.y += speedY;
if(phone.x > WIDTH phone.x < 0) speedX*=-1;
if(phone.y > HEIGHT phone.y < 0) speedY*=-1;

bgbmd.draw(phone,new Matrix(1,0,0,1,phone.x,phone.y));
bgbmd.colorTransform(new Rectangle(0,0,WIDTH,HEIGHT),new ColorTransform(1,1,1,0.8));

}
}
}

[/codesyntax]

AS3中的Inline(内联函数)

内联函数

是将在函数被调用的地方使用替换成该函数实际的代码,这样就少了一次函数调用,也就少了很多地址查找,入栈出栈的操作,对于频繁调用的函数,就会有明显的性能提升。

Flash Builder 4.7设置

1、AIR SDK 3.4以上版本才附带ASC 2.0。

2、在“项目属性——ActionScript编译器——附加的编译器参数”中填写“-inline”。

函数成为内联函数的前提条件

1、只有标记为 final、static 的函数或全局函数才能嵌入[Inline]。

2、函数不能报考任何Activation Object(包括…参数和arguments对象)。

3、函数不能包含任意try catch或width语句。

4、函数不能包含任何函数闭包。

5、函数体不能超过50条语句。

测试结论

1、final或static的getter和setter函数会自动成为内联函数,不需要[Inline]元数据,且在未开启“-inline”参数时,已默认为内联函数。

2、闭包(function内含function)不能成为内联函数,且自身效率非常低。

延伸阅读:http://gotoandlearn.com/play.php?id=170(gotoandlearn的视频)