To make a build of ANE i.e Adobe native extension first you have to download FlashRuntimeExtension.jar that comes along with Adobe AIR sdk.
you can download from here :
http://www.adobe.com/devnet/air/air-sdk-download.html
We know that its easy to make jar files of your project in eclipse is easy but in Android studio to build ANE first you have to generate .aar Android archive file this is basically type of Zip files you can also extract it like zip ,you can package resources along with your java classes in .aar file.
There are following step to build ANE :
1. Create a new project with textview hello world.
2. Now go to project's libs folder and paste FlashRuntimeExtension there.
3. Now add this jar file as a library in your project
4. Clean and rebuild your project after this as a library
5. Tell gradle to compile this library like this:
compile files('libs/FlashRuntimeExtensions.jar')
6. Comment your application plugin and set your application as a library project
//apply plugin: 'com.android.application'
apply plugin: 'com.android.library'
also comment applicationId because we are not going to make application project so
//applicationId “com.Demo”
To code the Java side of a native extension for Adobe AIR, do the following:
1. Implement the FREExtension interface.
2. Extend the FREContext abstract class with one or more concrete subclasses.
3. Implement the FREFunction interface for each Java function that can be called from the
ActionScript side of the extension.
7. Now create a class that will implement ANE FREEExtension interface like this :
This class should have the methods createContext() , dispose() , and initialize() .
The initialize() method is called when the native extension is ready to be used.
createContext method will return FREExtension class object.
The dispose() method will be called when the native extension is no longer needed by the application.So this is basically for garbage collection of object.
public class DemoExtension implements FREExtension {
@Override
public void initialize() {
}
@Override
public FREContext createContext(String s) {
return new DemoContext();
}
@Override
public void dispose() {
}
}
8. Create class name DemoContext that will extend superclass FREContext like this :
The getFunctions() method will return a collection of FREFunction objects. Here we have to create another calss that will implement FREFunction interface .
public class DemoContext extends FREContext {
@Override
public Map<String, FREFunction> getFunctions() {
Map<String, FREFunction> map = new HashMap<>();
map.put("demo",new DemoFuntion());
return map;
}
@Override
public void dispose() {
}
}
9. Create class name DemoFunction that will implement FREFunction interface like this :
public class DemoFuntion implements FREFunction {
@Override
public FREObject call(FREContext freContext, FREObject[] freObjects) {
Context appContext = freContext.getActivity().getApplicationContext();
Toast.makeText(appContext,"Calling from ANE",Toast.LENGTH_LONG).show();
return null;
}
}
These classes will each have a call() method. This method is invoked when the function is called from the main ActionScript library and it will show this toast on calling call function.
7. Now go to Build option and click on make project then rebuild project.
8. After successfully finish of build do to your project folder and find this file
App\build\outputs\aar\app-debug.aar
9. Now simply open and find classes.jar in it.
Now you can use this jar file to build your ANE .
0 Comment(s)