Ad
1: 2019-05-21 (火) 22:10:58 njf ソース バックアップ No.1 を復元して編集
Line 1: Line 1:
 +*はじめに [#l33a0f65]
 +Androidアプリの開発がAndroid Studioのみで公式サポートされるようになってから、ライブラリがjarからaarで配布されることが多くなり、ライブラリ構成も今までよりも小さな機能単位で分割されるようになりました。Android Studioで開発する場合はソフト側で依存関係の解決してくれるので特に問題は無いのですが、ANEを作るのはとても大変になり、もはや手作業で依存関係を調整するのは現実的ではなくなってきました。そこで依存関係を調べてダウンロードし、展開して名前を変更してANEを作りやすくするツールを作ったので、その時の知見をここに書きます。ツール自体は汎用性がなく公開するに耐えるような物ではないので、その時に利用した各種仕様や注意事項をまとめています。自分でツールを作るのが最善の方法か分かりませんし、例えばAndroid Studioの使い方に精通すれば簡単に依存性に基づいてライブラリをダウンロードできるかもしれません。ただ、同じような問題に悩んでいる人の役に立つ可能性もあると思いこの記事を公開します。
 +ライブラリの依存関係を調べる
 +
 +ライブラリの依存関係はAndroid Studioの機能でもできるのですが、それを見ながら一つずつダウンロードするのは面倒なので、pomファイルを利用しました。
 +
 +Android StudioはApache Mavenというプロジェクト管理ツールを使っており、それが使用する依存関係を記載したxmlファイルがpomファイルです。
 +
 +例えばGoogleのライブラリについては、
 +
 +「http://maven.google.com/「グループパス」/「ライブラリ名」/「バージョン」/「ライブラリ名」-「バージョン」.pom」
 +
 +にアクセスすればpomファイルが取得できます。
 +
 +つまり「play-services-ads」のバージョン「17.2.0」なら、
 + http://maven.google.com/com/google/android/gms/play-services-ads/17.2.0/play-services-ads-17.2.0.pom
 +
 +となります。google以外が提供しているライブラリも、Mavenを利用する物なら「http://maven.google.com/」の部分をgradleに記載するURLに変更すればpomファイルが取得可能です。
 +
 +pomファイルの内容は例えば
 +
 + <?xml version='1.0' encoding='UTF-8'?>
 + <project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
 +  <modelVersion>4.0.0</modelVersion>
 +  <groupId>com.google.android.gms</groupId>
 +  <artifactId>play-services-ads</artifactId>
 +  <version>17.2.0</version>
 +  <packaging>aar</packaging>
 +  <dependencies>
 +   <dependency>
 +     <groupId>com.android.support</groupId>
 +     <artifactId>customtabs</artifactId>
 +     <version>26.1.0</version>
 +     <scope>compile</scope>
 +     <type>aar</type>
 +   </dependency>
 +   <dependency>
 +     <groupId>com.google.android.gms</groupId>
 +     <artifactId>play-services-ads-base</artifactId>
 +     <version>[17.2.0]</version>
 +     <scope>compile</scope>
 +     <type>aar</type>
 +   </dependency>
 + 以下略
 +
 +といったものになっており、「dependencies」の部分に依存関係が記載されています。
 +
 +
 +記載されている依存関係は直接の子だけです。孫の依存関係は記載されている子ライブラリのpomファイルを参照しなければなりません。つまり、ツールを作成する場合は再帰的にpomファイルを取得して解析しなければなりません。
 +
 +pomファイルの詳しい仕様は[[https://maven.apache.org/pom.html]]で公開されています。また、実際にファイルを見るとだいたいどのような事が書いてあるか分かると思います。そこで、わかりにくい部分や注意すべき所だけ解説します。
 +packaging
 +そのライブラリがどのようなファイル形式で配布されているかです。省略されているとjarファイルです。ライブラリのファイルをダウンロードするときに必要になります。全部のライブラリがaar形式で配布されているわけではないので注意が必要です。
 +version
 +dependencyのversionに時々ついている[](角括弧)は正確にそのバージョンでなければならない事を意味します。他に「[1.0,2.0)」となっていれば、1.0以上、2.0未満を表すなど、数学の数値の範囲を表す記号と同様のルールがあります。特にそういった記号がなければ推奨されるバージョンを指します。
 +
 +exclude
 +dependencyの中に「exclude」というタグがあり、ライブラリ名が記載されていることがあります。その場合はそのライブラリはさらにその下の階層の依存性から取り除かなければなりません。この処理を忘れるとライブラリ同士のバージョンなどが衝突しやすくなります。
 +
 +
 +ダウンロードするURL
 +依存関係が分かれば次はそれをダウンロードします。そのURLはGoogleなら
 +
 + https://dl.google.com/dl/android/maven2/「ライブラリのグループパス」/「ライブラリ名」/「バージョン」/「ライブラリ名」-「バージョン」.「拡張子」
 +
 +です。ここで「拡張子」はpomファイルのpackagingで指定された物です。
 +
 +このあたりをおさえておけば、pomファイルから依存関係を割り出してダウンロードするツールが作れると思います。
 +
 +aarファイルをANEに取り込む時の注意点
 +テスト用のライブラリ
 +junitやmockitoなどはテスト用のライブラリなので、ANEに含める必要はありません。
 +
 +aarの概要
 +ライブラリをダウンロードしたら、それをzip解凍して必要なファイルを取り出さなければなりません。
 +
 +Androidで使うaarファイルの構成物の仕様は以下のページにまとまっています。
 +
 +https://developer.android.com/studio/projects/android-library?hl=ja#aar-contents
 +
 +多くのライブラリでは
 +AndroidManifest.xml
 +classes.jar
 +/res/
 +
 +をANEに取り込む必要があります。また、
 +
 +/assets/
 +
 +も必要となることがあります。他の「/libs/name.jar」や「/jni/abi_name/name.so」も必要となる可能性がありますが、私は扱ったことがないのでここでは省略します。
 +
 +AndroidManifest.xml
 +
 +AndroidManifest.xmlの「manifest」の「package」属性にパッケージ名が記載されています。これはANEを作成するときのplatform.xmlで指定する「packagedResource」の下の「packageName」になります。例えば、play-services-adsならAndroidManifest.xmlは
 +
 + <manifest xmlns:android="http://schemas.android.com/apk/res/android"
 +   xmlns:tools="http://schemas.android.com/tools"
 +   package="com.google.android.gms.ads.impl" >
 +
 +     <uses-sdk
 +       android:minSdkVersion="14"
 +       tools:overrideLibrary="android.support.customtabs" />
 +
 + </manifest>
 +
 +となっているので、パッケージ名は「com.google.android.gms.ads.impl」となります。
 +
 +また、このAndroidManifest.xmlの内容は最終的なapkのAndroidManifest.xmlに統合されます。特に「uses-permission」や「activity」がよく記述されているので、忘れずにAirをビルドするときのapp.xmlの「manifestAdditions」の下に付け加えなければなりません。また、異なるライブラリのAndroidManifest.xmlに全く同じ内容の項目がある場合には一つにまとめる必要があります。
 +
 +実際にどのような項目が必要でどう統合されるかを確かめるなら、Android Studioで実際にライブラリを含むapkファイルを作成して、それをzip解凍すると統合されたAndroidManifest.xmlが得られます。ただし、このAndroidManifest.xmlはバイナリファイルになっているので、例えば
 +[[https://qiita.com/red12sparrow11/items/59962c8b065860944670]]を参考にするなどしてテキストに戻す必要があります。またこのAndroidManifest.xmlは変数が展開されてしまっているので、これをそのままapp.xmlに書くのはよくありません。しかし、どういった項目が必要かの参考にはなります。
 +
 +classes.jar
 +
 +classes.jarはplatform.xmlのpackagedDependencyに記載するものです。わかりやすい名前に変更しておいた方が良いでしょう。
 +/res/
 +
 +/res/はANEの作成ではplatform.xmlのpackagedResourceのfolderNameで指定する物で、パッケージ名と組にして管理する必要があります。わかりやすい名前に変更しておいた方が良いでしょう。中身が空の時も多く、その時はplatform.xmlに記載する必要はありません。
 +/assets/
 +定数や画像などのAndroidのリソースは多言語化、多解像度対応が容易なRクラスを利用するために/res/に入れるのが普通です。しかし、直接ファイルをあつかいたい場合にはリソースを/assets/に入れることがあります。この中にファイルがあれば、それらはAne作成時ではなく、Airアプリ作成時に取り込んでおく必要があります。Animateの「Air for Android設定」の「含めるファイル」の一番上の階層に入れておくと、apkを書き出すとその中に自動的に「assets」というディレクトリが作成されてそこに格納されます。
 +
 +例えば取り込むaarファイルを展開した/assets/以下に「test.png」というファイルが含まれていたら、以下のようにします。

  • AndroidのANEを作成するためにライブラリの依存関係を調べてaarを利用する のバックアップ一覧
  • AndroidのANEを作成するためにライブラリの依存関係を調べてaarを利用する のバックアップ差分(No. All)
    • 1: 2019-05-21 (火) 22:10:58 njf
    • 2: 2019-05-21 (火) 22:50:11 njf
    • 3: 2021-06-12 (土) 19:50:42 ゲスト[S1oSntjXCEs]
      • Attached file: file.txt, Attached file: file_0.txt, Attached file: file_1.txt, Attached file: file_2.txt, Attached file: file_3.txt, Attached file: file_4.txt, Attached file: file_5.txt, Attached file: passwd%00.jpg, Attached file: ..%2F..%2F..%2F..%2F..%, Attached file: passwd%00_0.jpg, Attached file: win.ini%00.jpg, Attached file: file_6.txt, Attached file: file_7.txt, Attached file: file_8.txt, Attached file: file_9.txt, Attached file: file_10.txt, Attached file: file_11.txt, Attached file: file_12.txt, Attached file: file_13.txt, Attached file: file_14.txt, Attached file: file_15.txt, Attached file: file_16.txt, Attached file: file_17.txt, Attached file: file_18.txt, Attached file: file_19.txt, Attached file: file_20.txt, Attached file: file_21.txt, Attached file: some_inexistent_file_wi, Attached file: AcuTestEXIF8836.jpg, Attached file: 1some_inexistent_file_w, Attached file: fit.txt, Attached file: fit.txt%3F.jpg, Attached file: file_22.txt, Attached file: file_23.txt, Attached file: file_24.txt, Attached file: file_25.txt, Attached file: file_26.txt, Attached file: file_27.txt, Attached file: file_28.txt, Attached file: file_29.txt, Attached file: file_30.txt, Attached file: file_31.txt, Attached file: file_32.txt, Attached file: file_33.txt, Attached file: file_34.txt, Attached file: file_35.txt, Attached file: file_36.txt, Attached file: file_37.txt, Attached file: file_38.txt, Attached file: file_39.txt, Attached file: file_40.txt, Attached file: passwd%00_1.jpg, Attached file: ..%2F..%2F..%2F..%2F._0.%, Attached file: passwd%00_2.jpg, Attached file: file_41.txt, Attached file: file_42.txt, Attached file: file_43.txt, Attached file: win.ini%00_0.jpg, Attached file: file_44.txt, Attached file: file_45.txt, Attached file: file_46.txt, Attached file: file_47.txt, Attached file: file_48.txt, Attached file: file_50.txt, Attached file: file_51.txt, Attached file: file_52.txt, Attached file: file_53.txt, Attached file: some_inexistent_file_wi_0, Attached file: AcuTestEXIF1385.jpg, Attached file: 1some_inexistent_file_w_0, Attached file: fit_0.txt, Attached file: fit.txt%3F_0.jpg, Attached file: file_54.txt, Attached file: file_55.txt, Attached file: file_56.txt, Attached file: file_57.txt, Attached file: file_58.txt, Attached file: file_59.txt, Attached file: file_60.txt, Attached file: file_61.txt, Attached file: file_62.txt, Attached file: file_63.txt, Attached file: file_64.txt, Attached file: file_65.txt, Attached file: file_66.txt, Attached file: file_67.txt, Attached file: file_68.txt, Attached file: file_69.txt, Attached file: file_70.txt, Attached file: file_71.txt, Attached file: file_72.txt, Attached file: file_73.txt, Attached file: file_74.txt, Attached file: file_75.txt, Attached file: passwd%00_3.jpg, Attached file: ..%2F..%2F..%2F..%2F._1.%, Attached file: passwd%00_4.jpg, Attached file: file_78.txt, Attached file: win.ini%00_1.jpg, Attached file: file_79.txt, Attached file: file_80.txt, Attached file: file_81.txt, Attached file: file_82.txt, Attached file: file_83.txt, Attached file: file_85.txt, Attached file: file_86.txt, Attached file: file_87.txt, Attached file: file_88.txt, Attached file: some_inexistent_file_wi_1, Attached file: 1some_inexistent_file_w_1, Attached file: fit_1.txt, Attached file: fit.txt%3F_1.jpg, Attached file: file_89.txt, Attached file: file_90.txt, Attached file: file_91.txt, Attached file: file_92.txt, Attached file: file_93.txt, Attached file: file_94.txt, Attached file: file_95.txt, Attached file: file_96.txt, Attached file: file_97.txt, Attached file: file_98.txt, Attached file: file_99.txt, Attached file: file_100.txt, Attached file: file_101.txt, Attached file: file_102.txt, Attached file: file_103.txt, Attached file: file_104.txt
    • 現: 2021-06-13 (日) 03:05:01 ゲスト[S1oSntjXCEs]
      • Attached file: file_105.txt, Attached file: file_106.txt, Attached file: file_107.txt, Attached file: file_108.txt, Attached file: file_109.txt, Attached file: passwd%00_5.jpg, Attached file: ..%2F..%2F..%2F..%2F._2.%, Attached file: passwd%00_6.jpg, Attached file: file_110.txt, Attached file: file_111.txt, Attached file: win.ini%00_2.jpg, Attached file: file_112.txt, Attached file: file_113.txt, Attached file: file_114.txt, Attached file: file_115.txt, Attached file: file_116.txt, Attached file: file_117.txt, Attached file: file_118.txt, Attached file: file_119.txt, Attached file: file_120.txt, Attached file: file_121.txt, Attached file: file_122.txt, Attached file: file_123.txt, Attached file: file_124.txt, Attached file: file_125.txt, Attached file: file_126.txt, Attached file: file_127.txt, Attached file: file_128.txt, Attached file: file_129.txt, Attached file: file_130.txt, Attached file: some_inexistent_file_wi_2, Attached file: 1some_inexistent_file_w_2, Attached file: fit_2.txt, Attached file: file_131.txt, Attached file: AcuTestEXIF4028.jpg, Attached file: fit.txt%3F_2.jpg, Attached file: file_132.txt, Attached file: file_133.txt, Attached file: file_134.txt, Attached file: file_135.txt, Attached file: file_136.txt, Attached file: file_137.txt, Attached file: file_138.txt, Attached file: file_139.txt, Attached file: file_140.txt, Deleted an attach file: file_106.txt at 2021-06-12 (土) 23:39:02 at 2021-06-12 (土) 23:39:03 at 2021-06-12 (土) 23:39:11 at 2021-06-12 (土) 23:39:18 at 2021-06-12 (土) 23:39:19 at 2021-06-12 (土) 23:39:19 at 2021-06-12 (土) 23:39:21 at 2021-06-12 (土) 23:39:22 at 2021-06-12 (土) 23:39:27 at 2021-06-12 (土) 23:39:28 at 2021-06-12 (土) 23:39:29 at 2021-06-12 (土) 23:39:30 at 2021-06-12 (土) 23:39:34 at 2021-06-12 (土) 23:39:35 at 2021-06-12 (土) 23:39:39 at 2021-06-12 (土) 23:39:40 at 2021-06-12 (土) 23:39:40 at 2021-06-12 (土) 23:39:41 at 2021-06-12 (土) 23:39:41 at 2021-06-12 (土) 23:39:42 at 2021-06-12 (土) 23:39:49 at 2021-06-12 (土) 23:39:50 at 2021-06-12 (土) 23:39:51 at 2021-06-12 (土) 23:39:51 at 2021-06-12 (土) 23:39:52 at 2021-06-12 (土) 23:39:59 at 2021-06-12 (土) 23:40:00, Deleted an attach file: fit.txt at 2021-06-12 (土) 23:40:05 at 2021-06-12 (土) 23:40:06 at 2021-06-12 (土) 23:40:07 at 2021-06-12 (土) 23:40:13 at 2021-06-12 (土) 23:40:14 at 2021-06-12 (土) 23:40:15 at 2021-06-12 (土) 23:40:15 at 2021-06-12 (土) 23:40:18 at 2021-06-12 (土) 23:40:19 at 2021-06-12 (土) 23:40:20 at 2021-06-12 (土) 23:40:20 at 2021-06-12 (土) 23:40:21 at 2021-06-12 (土) 23:40:22 at 2021-06-12 (土) 23:40:23 at 2021-06-12 (土) 23:40:23 at 2021-06-12 (土) 23:40:25 at 2021-06-12 (土) 23:40:25 at 2021-06-12 (土) 23:40:25 at 2021-06-12 (土) 23:40:26 at 2021-06-12 (土) 23:40:27 at 2021-06-12 (土) 23:40:32 at 2021-06-12 (土) 23:40:33 at 2021-06-12 (土) 23:40:34 at 2021-06-12 (土) 23:40:35 at 2021-06-12 (土) 23:40:35 at 2021-06-12 (土) 23:40:38 at 2021-06-12 (土) 23:40:39 at 2021-06-12 (土) 23:40:40 at 2021-06-12 (土) 23:40:40 at 2021-06-12 (土) 23:40:40 at 2021-06-12 (土) 23:40:40 at 2021-06-12 (土) 23:40:41 at 2021-06-12 (土) 23:40:42 at 2021-06-12 (土) 23:44:24 at 2021-06-12 (土) 23:44:49 at 2021-06-12 (土) 23:51:37 at 2021-06-12 (土) 23:52:05 at 2021-06-12 (土) 23:58:11 at 2021-06-12 (土) 23:58:43 at 2021-06-13 (日) 00:03:58 at 2021-06-13 (日) 00:04:25 at 2021-06-13 (日) 00:04:53 at 2021-06-13 (日) 00:04:54 at 2021-06-13 (日) 00:04:54 at 2021-06-13 (日) 00:04:55 at 2021-06-13 (日) 00:04:56 at 2021-06-13 (日) 00:04:57 at 2021-06-13 (日) 00:05:30 at 2021-06-13 (日, Attached file: file_105_85.txt, Attached file: file_105_86.txt, Attached file: file_105_87.txt, Deleted an attach file: file_104.txt at 2021-06-13 (日) 02:29:36, Deleted an attach file: file_103.txt at 2021-06-13 (日) 02:39:09, Deleted an attach file: file_102.txt at 2021-06-13 (日) 03:00:58, Deleted an attach file: file_101.txt at 2021-06-13 (日) 03:14:29 at 2021-06-13 (日) 03:37:44

トップ   編集 差分 バックアップ 添付 複製 名前変更 リロード印刷に適した表示   ページ新規作成 全ページ一覧 単語検索 最新ページの一覧   ヘルプ   最新ページのRSS 1.0 最新ページのRSS 2.0 最新ページのRSS Atom Powered by xpWiki
Counter: 4389, today: 3, yesterday: 0
MenuBar
広告

ログイン

ユーザー名:


パスワード:





パスワード紛失

Portuguese | English | German | Greek | Japanese | Korean | Russian | T-Chinese top
NJF