Android Studio で簡単に jar をつくる手順はないのかと

ふと, こんな.

https://twitter.com/malcheese2/status/457027182133387264

Android Studio 最新版 0.5.5 でどうしたらいいのだろうか.

Create a standalone library with Android Studio | Geek Garage

apply plugin: ‘android'

apply plugin: 'android-library’

./gradlew clean
./gradlew aR

aR=assembleRelease

build/libs/ 以下に .aar ファイルが作成される.

このファイルを別プロジェクトの libs/ 以下にコピーして,依存の記述をすればよし.

Referencing a local aar file in Android Studio | Geek Garage

dependencies {
    compile files('libs/mylib.aar')
}

で「aar」とは何なのか.

Building Android applications with Gradle - Tutorial

Gradle supports a format called Android ARchive (AAR) . An AAR is similar to a JAR file, but it can contain resources as well as compiled bytecode. This allows that an AAR file is included similar to a JAR file

.aar ファイルは zip 圧縮されたファイルで以下が含まれている.

/AndroidManifest.xml (mandatory)
/classes.jar (mandatory)
/res/ (mandatory)
/R.txt (mandatory)
/assets/ (optional)
/libs/*.jar (optional)
/jni//*.so (optional)
/proguard.txt (optional)
/lint.jar (optional)

AAR Format - Android Tools Project Site

Gradle 本家サイトドキュメントなどを見てると広く深いのですが
Android Studio 関連のそこらの話を含め, 以下が一番わかりやすい.

Library projects - Android Tools Project Site

Gradle Plugin User Guide - Android Tools Project Site

で思うのが, .aar から .jar に変換できないか.

java - How to convert AAR to JAR - Stack Overflow

The AAR file consists of a JAR file and some resource files. Here are the steps to convert:

1. Extract the AAR file using standard zip extract
2. Find the classes.jar file in the extracted files
3. Rename it to your liking and use the wanted jar file in your project

Android Studio 左のツリービューからは見えない.

build_libs

ので, ターミナルから確認する.

~/AndroidStudio/SampleProject/volley/build/libs $ unzip -Z volley.aar
Archive:  volley.aar   80932 bytes   5 files
-rw-r--r--  2.0 unx      460 b- defN 23-Mar-14 22:33 AndroidManifest.xml
-rw-r--r--  2.0 unx    89580 b- defN 23-Mar-14 22:33 classes.jar
drwxr-xr-x  2.0 unx        0 b- defN 23-Mar-14 22:33 assets/
drwxr-xr-x  2.0 unx        0 b- defN 13-Feb-14 13:55 jni/
drwxr-xr-x  2.0 unx        0 b- defN 23-Mar-14 22:33 res/
5 files, 90040 bytes uncompressed, 80440 bytes compressed:  10.7%

.aar ファイルは zip 形式なので展開して class.jar をリネームすればよし, と.


関連ワード:  AndroidAndroidStudioGradleライブラリ今さら聞けない初心者開発