How to Make an Android Application on Mac OS X

How to Make an Android Application on Mac OS X

INSTALLATION

After the installation of Eclipse IDE, install the Android SDK.

Download from here: http://developer.android.com/

And install them somewhere on your machine. For example, now I'll install it on ~/android-sdk-mac_x86-1.5_r2 .

Config your system environment by the following command:

export PATH=$PATH:~/android-sdk-mac_x86-1.5_r2/tools/

And then install the ADT: Android Development Tools plugin for Eclipse.

Help > Install New Software...

(I don't know why the plugin adding dialog is located in "Help" menu. I wonder what did the Eclipse developper thing about it.)

And input it: https://dl-ssl.google.com/android/eclipse/

1

Now you have Android plugin. Before you would create a new Android app, you have to set a setting on your Eclipse Preferences.

2

Input the SDK Location and Apply it.

Hello, World with Eclipse

$ android create avd --target 2 --name my_avd # Initial setting

And then make a new Project with your Eclipse.

3

4

5

And run it.

6

OK. Now let's try to show "Hello, world" on the Android emulator window.

The initial src/com.example.hw/hw.java is:

package com.example.hw;

import android.app.Activity;
import android.os.Bundle;

public class hw extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
}

Fix it like below:

package com.example.hw;

import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;

public class hw extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
TextView tv = new TextView(this);
tv.setText("Hello, Android");
setContentView(tv);
}
}

And then run the Android Application by Eclipse.

a

It took very long time to show the result. After you clicked the run botton, you should drink a cup of coffee.

Hello, World without Eclipse

It is very difficult for us to use Eclipse every time. Now I'll show how to build and run an Android application without using Eclipse.

$ mkdir hw-vim && cd hw-vim
$ android create project --package com.example.hwvim --activity HW --target 2 --path .
(...fix src/(snip)/HW.java like the previous code...)
$ ant debug
$ emulator -avd my_avd
$ adb -s emulator-5554 install bin/HW-debug.apk

It did:

  1. Create a new Android Application Project
  2. Build
  3. Boot the Android emulator
  4. Install the application into the emulator

You may see the following error:

error: device not found

Unfortunately this error is undocumented here . The solution how to avoid it is to restart adb server.

$ ps aux | grep adb
$ kill -HUP {the process id}

Now you must be able to see the new app:

HW there

I don't know why, but I cannot boot the application. An error occurred.

error

;-(

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值