Things you will need.
- A copy of Flash CS5 or CS5.5 (I’m using 5.5 but 5 should work just as well)
- Project Files (Available here)
- Adobe Air 3.0 SDK installed
- Flash Develop
- recommended A copy of secureSWF Pro
You DO NOT need Flash Builder using this example.
Ok let me start by saying that the tutorial made available by adobe available here has a few mistakes in it that will stop your project from working. I’ve posted comments on the article but I have a feeling no one is reading them or cares.
The big mistake mistake is the ADT command to create your APK that includes your Native Extensions.
This is what is posted there.
Full Path to adt.bat> -package -storetype PKCS12 -keystore <path to Certificate for Native Extension> -storepass <password> -target ane com.adobe.air.sampleextensions.android.licensing.ane extension.xml -swc AndroidLicensingLib.swc -platform Android-ARM -C .\Android-ARM\.
At the end of the line you see “
.\Android-ARM\.“ this should actualy be “
.\Android-ARM\ .“. You need a space before the last period or you will get the “Missing implementation for platform: Android-ARM” error.
What I don’t understand is why Adobe didn’t just provide the ANE file and just allow you to send your public key to it like I’ve done. Oh well doesn’t matter.
Lets create a project that uses the Adobe Air 3.0 Android Licensing Native Extension.
Here is a link to what the final app will look like in the Android Market. First download the project files I have made available here. Second you will need a few things that I will not provide with the example.
- You will need to create a Secure Certificate (.p12 file)
- You will need to aquire your Andoid developer Public Key. You can get this from your edit profile page on your Android developer account.
- I also highly recommend you get a copy of secureSWF. If you are selling an app on the Market Place you really don’t want people decompiling your source code and modifying stuff like the License calls. Also you will want to encrypt your Public Key.
So the zip file provided has 2 folders in it.
- ADT_AddNativeExtensions – this folder you will use to compile your final APK using ADT.
- FlashProject – this folder is home to your actual flash project.
- Also we have out SecureCert.p12 at the root of our project. This is because both folder will be using it so its just easier to have it there.
Create your secure certificate. And replace SecureCert.p12 with the one you’ve created. Just rename your certificate to SecureCert.p12 and replace the one in the example to make it easier on yourself.
Get your Android Public Key and and paste it into doLicenceCheck() in AndroidLicenseCheck.as. In the example provided I only use 1 variable. I personally break it into about 7. This just makes it easier for me on the screen and makes it a bit more unconventional when decompiling. We are also going to encrypt this later.
Make sure all your library paths are correct in your ActionScript 3.0 settings.
- You should have a link to your Air3.0 flex SDK
- AndroidLicensingLib.swc in your project library folder
- com.adobe.air.sampleextensions.android.licenseing.swc in your project extension folder. Make sure the link type is set to “external” because this is your ANE file renamed to SWC in order to compile it into your project.
Now try building your project. If everything is setup correctly you should now have airAndroidLicenseExample.apk in your project folder. This APK will not actually link to your native extension unfortunately. We now have to rename and unzip this into our ADT_AddNativeExtensions folder.
Rename airAndroidLicenseExample.apk in your flashProject folder to airAndroidLicenseExample.zip then extract everthing to the “airAndroidLicenseExample” folder that already exists in the “ADT_AddNativeExtensions” folder. The contents of the folder should look like the screenshot.
Make sure the “adt-app.xml” information matches the your project if you made any changes to the name, version number etc. Don’t just replace this file though. You need the <extensions> tags as well as user permissions this one has. Feel free to add any other permissions your project uses.
Step 8 HIGHLY RECOMMENDED
Now we are going to encrypt a few things using secureSWF. I’ve included a project file you can use (secureSWF_Project.sspj) in the “ADT_AddNativeExtensions” folder. In the screen-shots you can see a few classes and variables you should encrypt. Make sure to not encrypt the other variables inside the any of the license classes or your project will not be able to communicate with the licensing service. The most important thing you encrypt is your Public key and the string “cLNative” in your “Protection Options“. I have obviously blurred out my public key in the screen-shots. NOTE: This will not 100% stop anyone from getting your public key. There is no way to 100% prevent anyone from de-compiling your project and getting it no matter what language your program is in. If someone is willing to invest the time they will be able to hack the licensing system. Unfortunately no DRM will prevent people from stealing your apps no matter what you do :S.
Ok so we have project unzipped into the provided folder, your encrypted your SWF and you’re running on 3 hours of sleep. Now we have to edit the “Create_APK_File.bat” file in the “ADT_AddNativeExtensions” folder. If you have kept the names of the swf, p12 and xml files the same you should only have to change one line in here before running it successfully.
java -jar "F:\Program Files\Adobe\Adobe Flash CS5.5\AIR2.6\lib\adt.jar" -package -target apk -storetype pkcs12 -keystore ..\SecureCert.p12 -storepass rybram123 airAndroidLicenseExample.apk adt-app.xml airAndroidLicensingExample.swf AppIconsForPublish -extdir ..\flashProject\extension
“F:\Program Files\Adobe\Adobe Flash CS5.5\AIR2.6\lib\adt.jar” is the location of ADT. You will have to update this to the location of ADT in your AIR3.0 SDK. Usually it is in the “lib” folder.
The batch file does a few other things as well. It makes copies of all the files and folders that ADT needs and puts them in the same directory and then deletes them. This is easiest way to do it that I have found. Otherwise you have to copy and rename all the files yourself.
Install the apk on your android device and hopefully it works without a hitch. The final app should look like this.
I will hopefully add to and edit the tutorial/example to make it easier to understand. I have spend many late nights figuring out how to use the Android Licensing Native Extension provided by Adobe and hopefully now you wont have to. Also you don’t have to go through the pain of using Flash Builder to create your ANE file. I personally think its a little silly that Adobe doesn’t actually support the Licensing system nativly. I hope they do in the future so we don’t have to go through this hack inorder to get it to work.
Please if you find this information helpful please leave a comment and plug my website if possible if you decide to use this for your project 🙂 This will motivate me to release more open source projects and code examples.
I also need to find the time to bring back all the open source projects from the old Rybram website.