ANE from getting started to mastering---simple whatever

Source: Internet
Author: User

Flash is still very good, but no one in the country. It's whatever. The following is a bit of note sharing in the ANE production to be kept as a backup

Step1 Writing As3 Library

Package Com.eran {ImportFlash.external.ExtensionContext; Importflash.system.Capabilities;  Public classWhatevernameas {Private Static varMinstance:whatevernameas;  Public Static function Getinstance (): Whatevernameas {if(Minstance = =NULL) {minstance=NewWhatevernameas (); }            returnminstance; }        Private varMextcontext:extensioncontext; Private varMismobile:Boolean;  Public functionWhatevernameas () {initialize (); }        Private functionInitialize ():void{mismobile= Capabilities.manufacturer.indexOf ("IOS")! =-1 | | Capabilities.manufacturer.indexOf ("Android")! =-1; if(mismobile) {Mextcontext= Extensioncontext.createextensioncontext ("Hereisextensionid","Hereiscontexttype"); if(Mextcontext! =NULL) {Mextcontext.call ("Initme")                } Else{Trace ("Error:can ' t create context"); }            }        }         Public functionCALLFUN1 ():void {            if(mismobile) {if(Mextcontext! =NULL) {Mextcontext.call ("Fun1"); } Else{Trace ("Error:context is null"); }            }        }    }}

After writing to generate *.SWC, here I named ANESWC.SWC, first put in a directory to stay in the next step with

STEP2 write Java Export jar package

Main entrance

 PackageCom.eran;ImportCom.adobe.fre.FREContext;Importcom.adobe.fre.FREExtension; Public classHereismainentryImplementsfreextension {@Override Public voidInitialize () {} @Override PublicFrecontext Createcontext (String s) {if(S.equals ("Hereiscontexttype")) {            return NewWhatevernamecontext (); }        return NULL; } @Override Public voidDispose () {}}

Context class

Package Com.eran;ImportCom.adobe.fre.FREContext;Importcom.adobe.fre.FREFunction;Importcom.eran.fun.WhateverFun1;ImportCom.eran.fun.WhateverInitFun;ImportJava.util.HashMap;ImportJava.util.Map; Public classWhatevernamecontextextendsFrecontext {@Override PublicMap<string, frefunction>getfunctions () {Map<string, frefunction> functionmap =NewHashmap<string, frefunction>(); Functionmap.put ("Initme",NewWhateverinitfun ()); Functionmap.put ("Fun1",NewWhateverFun1 ()); returnFunctionmap; } @Override Public voidDispose () {}}

Fun1

 PackageCom.eran.fun;ImportAndroid.widget.Toast;ImportCom.adobe.fre.FREContext;Importcom.adobe.fre.FREFunction;ImportCom.adobe.fre.FREObject; Public classWhateverFun1Implementsfrefunction {@Override PublicFreobject Call (Frecontext frecontext, freobject[] freobjects) {Toast.maketext (Frecontext.getactivity (),"WhateverFun1 called", Toast.length_short). Show (); return NULL; }}

Init Fun

 PackageCom.eran.fun;ImportAndroid.widget.Toast;ImportCom.adobe.fre.FREContext;Importcom.adobe.fre.FREFunction;ImportCom.adobe.fre.FREObject; Public classWhateverinitfunImplementsfrefunction {@Override PublicFreobject Call (Frecontext frecontext, freobject[] freobjects) {Toast.maketext (Frecontext.getactivity (),"Whateverinitfun called", Toast.length_short). Show (); return NULL; }}

Package jar process, Intellij idea 13~15 process is the same

Artifacts Select from modules

Select the Java project you just wrote

Get rid of the exported jar name and remove the import Flashruntimeextensions.jar

This file I was directly from the air SDK directory directly copied to the project Lib directory and set a reference

The final

After you run the package, you should generate the *.jar file, where my jar file is called Whateverjar.jar

STEP3 Creating a packaged Directory

Create a folder in any location, such as the internal structure. which

The Adt.jar file is copied directly from the Air SDK.

ANESWC.SWC is generated in STEP1

Unzip the ANESWC.SWC with the Unzip tool and place the library.swf into the Android-arm directory and the default directory respectively.

Whateverjar.jar the jar package generated by STEP2 into the Android-arm directory

Extension.xml file contents are as follows

<extensionxmlns= "http://ns.adobe.com/air/extension/20.0">  <ID>Hereisextensionid</ID>  <versionnumber>1</versionnumber>  <Platforms>    <Platformname= "Android-arm">      <applicationdeployment>        <nativelibrary>Whateverjar.jar</nativelibrary>        <initializer>Com.eran.HereIsMainEntry</initializer>        <Finalizer>Com.eran.HereIsMainEntry</Finalizer>      </applicationdeployment>    </Platform>    <Platformname= "Default">         <applicationdeployment/>     </Platform>   </Platforms></extension>

Where http://ns.adobe.com/air/extension/20.0 is the version number of the air SDK I used (I'm using air SDK20 all versions are 20.0)

The ID field is the first parameter that is filled in the context created in STEP1

Mextcontext = Extensioncontext.createextensioncontext ("Hereisextensionid""hereiscontexttype");

Also note that this field is also the name used to refer to the current ANE in the *-app.xml of the test project

    < Extensions >        < Extensionid > Hereisextensionid</extensionid>    </Extensions >

The second field of the function, "Hereiscontexttype", is the parameter to the Hereismainentry.java of the ingress file for Java in STEP2

    @Override    public  frecontext createcontext (String s) {        if (s.equals ("Hereiscontexttype")) {            returnnew  whatevernamecontext ();        }         return NULL ;    }

Edit BUILD.bat

@echo offCD/D%~dp0SetAdt=java-jar ADT.JarSetAne=anet1.AneSetTarget=ane%ane%. \extension.XMLSetSWC=./ANESWC.SWCSetPlatform-android=-platform android-arm-c./android-arm.SetPlatform-default=-platform default-c./default.EchoPackaging ...if exist%ane%del%ane% >nul%adt%-package-target%target%-swc%swc%%platform-ios-arm%%platform-ios-x86%%platform-android%% platform-default%Echofinish!Pause

Run BUILD.bat to generate final Anet1.ane, export test engineering

The resulting ANE structure is as follows:

Summarize:

The default platform is generated so that the ANE is only suitable for Android and cannot be run by the PC emulator when debugging on the PC

At the same time, the SWC interior of Ane

Mismobile = Capabilities.manufacturer.indexOf ("IOS")! =-1 | | Capabilities.manufacturer.indexOf ("Android")! =-1;

Make sure that its ane must be running in the mobile environment, and that the PC environment is just an empty implementation

ANE from getting started to mastering---simple whatever

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.