Tools:
1.flash Builder
2.adt Packaging Tools
3. Digital certificates
I. Creating a JAR file
1. Open Flash Builder and create a new Java project.
2. Click on the project properties, select the Java build path, select the library, then add the external jar, select the path, add Flashruntimeextension.jar
3. Build a package under the project src file, package name custom, and then build 3 Java classes under this package.
The Java code is as follows:
Extension.java class:
1 Package Com.three;2 ImportCom.adobe.fre.*;3 4 //extension This class is the most basic portal for AS and Java interaction5 Public classExtensionImplementsfreextension {6 7 8 @Override9 Publicfrecontext Createcontext (String arg0) {Ten //new threeextensioncontext come out; One return NewThreeextensioncontext (); A } - - @Override the Public voidDispose () { - //This method of destroying resources, for the time being no use, empty - - } + - @Override + Public voidInitialize () { A //initialization method, temporarily no need, empty first at - } - -}
Test.java class:
1 Package Com.three;2 3 ImportCom.adobe.fre.FREContext;4 Importcom.adobe.fre.FREFunction;5 Importcom.adobe.fre.FREInvalidObjectException;6 ImportCom.adobe.fre.FREObject;7 Importcom.adobe.fre.FRETypeMismatchException;8 Importcom.adobe.fre.FREWrongThreadException;9 Ten Public classTestImplementsfrefunction { One A @Override
The function of this class is that as invokes the call method to pass a freobject parameter group to Java, and then Java returns a Freobject
- PublicFreobject Call (Frecontext arg0,freobject[] arg1) - { theint a=0; -Freobject B =NULL; - Try{ -A=arg1[0].getasint (); + -}Catch(illegalstateexception e) + { A e.printstacktrace (); at -}Catch(fretypemismatchexception e) - { - e.printstacktrace (); -}Catch(freinvalidobjectexception e) - { in e.printstacktrace (); -}Catch(frewrongthreadexception e) to { + - e.printstacktrace (); the } * $ Try{Panax NotoginsengB=freobject.newobject (a*100)///Call Freobject's static method to write the integer variable A to B; - the}Catch(frewrongthreadexception e) + { A e.printstacktrace (); the } + - returnb; $ $ } - -}
Threeextensioncontext.java:
Package Com.three; import java.util.*; Import Com.adobe.fre.FREContext; Import com.adobe.fre.FREFunction; Public class extends frecontext{ public Threeextensioncontext () { } @Override Public void Dispose () { } @Override
The key to this is to define an important interface between AS and Java-specific methods of communication
Public Map<string,frefunction> getfunctions () { Mapnew hashmap<string,frefunction> (); Functionmap.put ("test"new test ()); return Functionmap;} }
If there is no error, right-click Export Java-jar file.
Two. Create a SWC file
1. Create a new Flex library project with Flash Builder (Flex libraries).
Note: This option, including the Adobe Air Library, must be selected.
Additionally: Additional compiler parameters to add-swf-version-13
Add the ActionScript class again with the following code:
1 Package Com.three2 {3 ImportFlash.external.ExtensionContext;4 5 Public classCalljava6 {7 varContext:extensioncontext;8 Public functionCalljava ()9 {TenContext=extensioncontext.createextensioncontext ("Com.three.Extension",""); One } A - Public functioncalljavatest (value:int): int{ - the varA:int; -A=context.call ("Test", value) as int; - returnA; - + } - } +}
Project structure
Right click on MYEXTENSION.SWC, copy it out, and put it together with the jar file just now. Then copy a copy of the MYEXTENSION.SWC and change its suffix to. zip and unzip it into the current directory.
Three. Create a extension.xml file
1 <extensionxmlns= "http://ns.adobe.com/air/extension/2.5">2 <ID>Com.three.Extension</ID>3 <versionnumber>1</versionnumber>4 <Platforms>5 <Platformname= "Android-arm">6 <applicationdeployment>7 <nativelibrary>Testairjava01.jar</nativelibrary>8 <initializer>Com.three.Extension</initializer>9 <Finalizer>Com.three.Extension</Finalizer>Ten </applicationdeployment> One </Platform> A </Platforms> - </extension>
Four. Visa Documents (P12)
You can build one with Flash Builder.
Five. Packaging
Put the above file in the same folder, enter the CD folder path in the command line
And then
Java-jar Adt.jar-package-tsa none-storetype pkcs12-keystore grq186key.p12-storepass 125521-target ane m.ane extensi ON.XML-SWC myextensionas.swc-platform android-arm library.swf Testairjava01.jar
You can generate the M.ane file.
Flash Air packaged with Android ane