ツムラ_メモ

大失敗を繰り返す。

Androidの開発環境の導入 Mac OSX編

Android.com http://www.android.com/
全ての基本、Androidの全てがここに!


基本的なインストール方法はこのページを見るだけでOK!
Installing the SDK | Android Developers http://developer.android.com/sdk/installing.html

Eclipseのダウンロード

For Eclipse 3.5 or newer, the "Eclipse Classic" version is recommended. Otherwise, a Java or RCP version of Eclipse is recommended.

とあるので、Eclipseの最新版のClassicをダウンロード。
Androidのサンプルが全部x86っぽいので、32bitにした方が無難そう。(実は一回64bitでサンプルのビルドしようと思って怒られた。)
Eclipse Downloads http://www.eclipse.org/downloads/

Eclipseも.appになてほしいなぁ。あぁ、Javaか…)
解凍して生成されたフォルダを~/Applicationsの下にコピー。

ADT(Android Developer Tools)のインストール

ADT Plugin for Eclipse | Android Developers http://developer.android.com/sdk/eclipse-adt.html#installing
を参考にしながらインストール。
Eclipse.appを起動。Help->Install New Software
Work withの横にあるAddボタンを押し、表示されたダイアログにADTのダウンロード元を設定する。

Name: ADT(適当)
Location: https://dl-ssl.google.com/android/eclipse/

SDKのダウンロード

ここのTopから辿れるDevelopers ページからSDKのダウンロードページへ移動。
Android SDK | Android Developers http://developer.android.com/sdk/index.html


Mac OS X (intel) android-sdk_r10-mac_x86.zip をダウンロード。
zipを解凍すると、フォルダが展開される。
まずは、Readme.txtを読んでみる。

Welcome to the Android SDK!

The Android SDK archive initially contains only the basic SDK tools. It does
not contain an Android platform or any third-party libraries. In fact, it
doesn't even have all the tools you need to develop an application.

In order to start developing applications, you must install the Platform-tools
and at least one version of the Android platform, using the SDK Manager.

Platform-tools contains build tools that are periodically updated to support new
features in the Android platform (which is why they are separate from basic
SDK tools), including adb, dexdump, and others.

To install Platform-tools, Android platforms and other add-ons, you must
have an Internet connection, so if you plan to use the SDK while
offline, please make sure to download the necessary components while online.

To start the SDK Manager, please execute the program "tools/android".

From the command-line you can also directly trigger an update by
executing:
tools/android update sdk

For more information, please consult the Android web site at
http://developer.android.com/sdk/

解凍したフォルダのToolsにはAndroid開発で必要なツールのバイナルが置かれているので、他のサイトで言われているパスを通してうんちゃらかんちゃらは、要はこのバイナリを使いたいっていうお話。
このフォルダを何処に置くべきかは結構悩みどころ。Macの宗教だと何処に置くのが正しいのでしょうね?
何も考えずに、~/Libraryの下にコピーしてみます。
MacのTerminal.appのパスを通す設定を何処に記述すべきかも結構悩みどころ。
一番最後に読み込む ~/.profileに下記の内容を書けばいいんじゃないかなと個人的には思っている。

export PATH=~/Library/android-sdk-mac_x86/tools:$PATH platform-toolsに移動したっぽい。
export PATH=~/Library/android-sdk-mac_x86/platform-tools$PATH

Terminal.appを再度立ち上げ、androidコマンドが立ち上がることを確認。
readme.txtにあるように、コマンドラインからアップデートを実行してみる。

tools/android update sdk

これで新しいAndroidの標準ライブラリなんかを整えてくれるっていう便利コマンド。最初しか使わないかもしれないが。

以下、アップデートの結果。
時間掛かるので、当面自分の端末で動かすだけならば、必要ないものは除いてもいいのかもしれない。

Downloading Android SDK Platform-tools, revision 3
Installing Android SDK Platform-tools, revision 3
'adb kill-server' failed -- run manually if necessary.
Installed Android SDK Platform-tools, revision 3
Downloading Documentation for Android SDK, API 11, revision 1
Installing Documentation for Android SDK, API 11, revision 1
Installed Documentation for Android SDK, API 11, revision 1
Downloading SDK Platform Android 3.0, API 11, revision 1
Installing SDK Platform Android 3.0, API 11, revision 1
Installed SDK Platform Android 3.0, API 11, revision 1
Downloading SDK Platform Android 2.3.3, API 10, revision 1
Installing SDK Platform Android 2.3.3, API 10, revision 1
Installed SDK Platform Android 2.3.3, API 10, revision 1
Downloading SDK Platform Android 2.3.1, API 9, revision 2 (Obsolete)
Installing SDK Platform Android 2.3.1, API 9, revision 2 (Obsolete)
Installed SDK Platform Android 2.3.1, API 9, revision 2 (Obsolete)
Downloading SDK Platform Android 2.2, API 8, revision 2
Installing SDK Platform Android 2.2, API 8, revision 2
Installed SDK Platform Android 2.2, API 8, revision 2
Downloading SDK Platform Android 2.1, API 7, revision 2
Installing SDK Platform Android 2.1, API 7, revision 2
Installed SDK Platform Android 2.1, API 7, revision 2
Downloading SDK Platform Android 1.6, API 4, revision 3
Installing SDK Platform Android 1.6, API 4, revision 3
Installed SDK Platform Android 1.6, API 4, revision 3
Downloading SDK Platform Android 1.5, API 3, revision 4
Installing SDK Platform Android 1.5, API 3, revision 4
Installed SDK Platform Android 1.5, API 3, revision 4
Downloading Samples for SDK API 11, revision 1
Installing Samples for SDK API 11, revision 1
Installed Samples for SDK API 11, revision 1
Downloading Samples for SDK API 10, revision 1
Installing Samples for SDK API 10, revision 1
Installed Samples for SDK API 10, revision 1
Downloading Samples for SDK API 8, revision 1
Installing Samples for SDK API 8, revision 1
Installed Samples for SDK API 8, revision 1
Downloading Samples for SDK API 7, revision 1
Installing Samples for SDK API 7, revision 1
Installed Samples for SDK API 7, revision 1
Downloading Android Compatibility package, revision 1
Installing Android Compatibility package, revision 1
Installed Android Compatibility package, revision 1
Downloading Google Market Licensing package, revision 1
Installing Google Market Licensing package, revision 1
Installed Google Market Licensing package, revision 1
Downloading Google Market Billing package, revision 1
Installing Google Market Billing package, revision 1
Installed Google Market Billing package, revision 1
Downloading Google APIs by Google Inc., Android API 11, revision 1
Installing Google APIs by Google Inc., Android API 11, revision 1
Installed Google APIs by Google Inc., Android API 11, revision 1
Downloading Google APIs by Google Inc., Android API 10, revision 1
Installing Google APIs by Google Inc., Android API 10, revision 1
Installed Google APIs by Google Inc., Android API 10, revision 1
Downloading Google APIs by Google Inc., Android API 9, revision 2
Installing Google APIs by Google Inc., Android API 9, revision 2
Installed Google APIs by Google Inc., Android API 9, revision 2
Downloading Google APIs by Google Inc., Android API 8, revision 2
Installing Google APIs by Google Inc., Android API 8, revision 2
Installed Google APIs by Google Inc., Android API 8, revision 2
Downloading GALAXY Tab by Samsung Electronics., Android API 8, revision 1
Installing GALAXY Tab by Samsung Electronics., Android API 8, revision 1
Installed GALAXY Tab by Samsung Electronics., Android API 8, revision 1
Downloading Google APIs by Google Inc., Android API 7, revision 1
Installing Google APIs by Google Inc., Android API 7, revision 1
Installed Google APIs by Google Inc., Android API 7, revision 1
Downloading Google APIs by Google Inc., Android API 4, revision 2
Installing Google APIs by Google Inc., Android API 4, revision 2
Installed Google APIs by Google Inc., Android API 4, revision 2
Downloading Google APIs by Google Inc., Android API 3, revision 3
Installing Google APIs by Google Inc., Android API 3, revision 3
Installed Google APIs by Google Inc., Android API 3, revision 3
Updated ADB to support the USB devices declared in the SDK add-ons.
'adb kill-server' succeeded.
ADB: * daemon not running. starting it now on port 5037 *
'adb start-server' succeeded.
ADB: * daemon started successfully *

Eclipseの設定とコンパイルのテスト

Eclipseの設定

Android SDKの場所をEclipseで設定する必要がある。
設定を行わないと、プロジェクトを開く時などに、

An SDK Target must be specified

などと怒られることになる。
Preferences -> Android -> SDK Location
に先程コピーしたAndroidSDKのフォルダを設定する。
今回の場合は

~/Library/android-sdk-mac_x86 (Browseで選択した方が確実。)

Sample Source Code の コンパイル

Eclipseandroidのサンプルソースをコンパイルしてみる。
File -> New -> Other -> Android -> Android Project