好不容易找到的资料,老外写的,有兴趣的朋友可以翻译一下。
Step 1: youneed a new projectWhen you run AndroidStudio, you will find a welcome screen and you need to create a new androidstudio project. every project you create can have one or more modules. everymodule has a job. for example, when you create a new project, the first defaultmodule named “app” will be created for you automatically. This module will helpyou write java code and build it to output .apk files. you can also create newmodules in your project. a librarymodule for instance and the job of a library module would beto generate .aar file fromyour project. (I found this procedure similar to how xcode works togenerate library .a files andI loved it to see it in Android Studio too) Saying that, I decided not to create two separated modules in myproject! I will show you how to create an application module first so you cantest your extension logic as an .apk while developing, and then I will show youhow to apply a little hack to this module to make it export the ANE required.aar file! using this approach, you will have only one module to deal with. Creating a new project in Android Studio isvery similar to how you used to do it in eclipse. while looking at thefollowing screenshots, create your own project and we’ll continue from there…just consider the following setup. it’s not necessary, but I think it’s a goodidea… 1) use API 10 as your minimum sdk version. in your project, depending onwhat kind of extension you are building, you may be required to change this butit’s a good idea to start with this min at the beginning. 2) Create a “BlankActivity” option. this will help you create the minimum setup you would need torun your extension as an .apk while developing the Android side.
Step 2: Add FlashRuntimeExtensions.jar to Android StudioRight after the first step, you can start building yourextension logic and do your tests in a runable .apk like any Android developerwould do. but after you are finished with your java coding, it’s time to addthe ANE bridge to your project. to do that, just copy theFlashRuntimeExtensions.jar file from your AdobeAir SDK and paste it into thelib folder of your Android Studio project… seems an easy and straight work,right? but make sure you are checking the below screenshots to know where tofind the “libs” folder!
After adding the .jar file to your module, the Gradle build willrun automatically and as you can see in the last screenshot, if everything hasgone smoothly, the Gradle build log window will show no error. Alright, nowthat you have successfully added the FLashRuntimeExtensions.jar to yourproject, switch back to the “Android” view and start writing the extensionbridge classes for your extension.
Step 3: TellGradle to export to .aar
from your Android view windowdouble click on build.gradle (Module: app) to have it open on the right side asseen in the below screenshot.
The first thing to notice is that at the verybottom of your build.gradle file, this line has been added: - compile files('libs/FlashRuntimeExtensions.jar')
复制代码
gradle script determines the rules for buildingyour project. so if you are adding a .jar file, it will be shown here also.now, what you need to do is to tell Gradle to build your project as an .aar.change the current code to following and it’s done.
- //apply plugin: 'com.android.application'
- apply plugin: 'com.android.library'
-
- android {
- compileSdkVersion 22
- buildToolsVersion "22.0.1"
-
- defaultConfig {
- //applicationId "com.doitflash.myFirstANE"
- minSdkVersion 10
- targetSdkVersion 22
- versionCode 1
- versionName "1.0"
- }
- buildTypes {
- release {
- minifyEnabled false
- proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
- }
- }
- }
-
- dependencies {
- compile fileTree(dir: 'libs', include: ['*.jar'])
- compile 'com.android.support:appcompat-v7:22.1.1'
- compile files('libs/FlashRuntimeExtensions.jar')
- }
复制代码
As you see, we havecommented out //applicationId “com.doitflash.myFirstANE” andhave replaced ‘com.android.application’ to ‘com.android.library’ Now, from the buildmenu, hit Make Project or Rebuild Project andwait until Android Studio finishes its job. when it’s done, go to the folderwhere you saved your project and find this file: app\build\outputs\aar\app-debug.aar andsimply open it with any zip software and find “classes.jar” in it. use this jarfile to build your ANE with it. I hope you have foundthis little note helpful.
MyFlashLabs Team.
|