How to set up android SDK for command line development on linux?

左心房为你撑大大i 提交于 2019-12-03 09:04:14

问题


I'm trying to set up the android SDK to develop a simple program on the command line in Linux (Ubuntu 9.10). I tried eclipse, but it has know problems running on Ubuntu, so I gave up on it. Here's what I've done so far:

  1. downloaded android-sdk_r05-linux_86.tgz from http://developer.android.com/sdk/index.html
  2. tar xvzf android-sdk_r05-linux_86.tgz
  3. ln -s android-sdk-linux_86 android
  4. in .tcshrc added setenv PATH .....:/home/user/android/tools
  5. source .tcshrc
  6. ran 'android'. This opened a gui. Under available packages: I installed everything, and quit the gui.
  7. ran 'android list targets' and It listed these:

Available Android targets:

id: 1 or "android-3" Name: Android 1.5 Type: Platform API level: 3 Revision: 1 Skins: HVGA-P, HVGA (default), QVGA-P, QVGA-L, HVGA-L

id: 2 or "Google Inc.:Google APIs:3" Name: Google APIs Type: Add-On Vendor: Google Inc. Revision: 3 Description: Android + Google APIs Based on Android 1.5 (API level 3) Libraries: * com.google.android.maps (maps.jar) API for Google Maps Skins: QVGA-P, HVGA-L, HVGA (default), QVGA-L, HVGA-P

id: 3 or "android-4" Name: Android 1.6 Type: Platform API level: 4 Revision: 1 Skins: HVGA (default), WVGA800, WVGA854, QVGA

id: 4 or "Google Inc.:Google APIs:4" Name: Google APIs Type: Add-On Vendor: Google Inc. Revision: 2 Description: Android + Google APIs Based on Android 1.6 (API level 4) Libraries: * com.google.android.maps (maps.jar) API for Google Maps Skins: WVGA854, HVGA (default), QVGA, WVGA800

id: 5 or "android-6" Name: Android 2.0.1 Type: Platform API level: 6 Revision: 1 Skins: WQVGA432, HVGA (default), WVGA800, WVGA854, WQVGA400, QVGA id: 6 or "Google Inc.:Google APIs:6" Name: Google APIs Type: Add-On Vendor: Google Inc. Revision: 1 Description: Android + Google APIs Based on Android 2.0.1 (API level 6) Libraries: * com.google.android.maps (maps.jar) API for Google Maps Skins: WQVGA400, WVGA854, HVGA (default), WQVGA432, QVGA, WVGA800

id: 7 or "android-7" Name: Android 2.1 Type: Platform API level: 7 Revision: 1 Skins: WQVGA432, HVGA (default), WVGA800, WVGA854, WQVGA400, QVGA

id: 8 or "Google Inc.:Google APIs:7" Name: Google APIs Type: Add-On Vendor: Google Inc. Revision: 1 Description: Android + Google APIs Based on Android 2.1 (API level 7) Libraries: * com.google.android.maps (maps.jar) API for Google Maps Skins: WQVGA400, WVGA854, HVGA (default), WQVGA432, QVGA, WVGA800

I want to create a simple hello world program for my motorola droid. Which of these targets should I use?

How do I see the Skins?

If I run 'android' from the command line it says that that there are no virtual devices. Is a virtual device the same as a target?

How do I get a droid skin and/or a droid target and/or a droid virtual device?


I THINK that I need to run something like 'android create avd --target 2 --name my_avd', but not sure. Is there a step-by-step list of how to do this somewhere?

thanks, Bob

Later:

I figured out that I had to create targets (=virtual devices) like this:

android create avd -t 1 -n myavd1
.......
android create avd -t 8 -n myavd8

This gave me 8 virtual devices in the gui when I ran 'android' from the command line.

Does anyone know what api level / platform to use for the Droid? And where to get the right skin? Is there anything hardware-specifications, that I need to know for Droid development?

Finally, are there any lists of steps to create a hello world app from the command line (linux) and run it on the emulator and then run it on a real phone?

Bob


回答1:


Though I routinely use an IDE (or a GUI wrapper) for development, I find Android's CLI to be particularly displeasing.

I have recently begun converting all of my Android projects to be Maven manged. There is a growing community around using this method and it can be quite pleasant.

The idea is built around the maven-android-plugin which does all the heavy lifting. There are samples which show various use cases (non-Java languages, multi-module projects, etc.). Tedious CLI tasks such as shrinking the APK size with proguard, signing the APK, and zipaligning the APK have all been automated.

There has also been a custom format, .apklib, developed for distributing Android library projects via Maven repositories.

When you couple all these features with the already existing advantaged Maven affords (automated testing, module support, dependency management, automated release, maven site generation, etc.) you really get a very streamlined workflow.

Oh, and it can control and deploy the emulator, too!




回答2:


want to create a simple hello world program for my Motorola droid. Which of these targets should I use?

Droid was by stock a 2.0 (API 6) but as of 14th March 2011 its 2.2.2 (FRG83G). You Should target for 2.0 because not all droids are 2.2.2.

How do I see the Skins?

How do I get a droid skin and/or a droid target and/or a droid virtual device?

You need to install Skins for Motorola Droid. Check the MotoDev Website here..

http://developer.motorola.com/docstools/tools/

If I run 'android' from the command line it says that that there are no virtual devices. Is a virtual device the same as a target?

No targets and virtual Devices are different. You need to create a Virtual Device from a Target.

Does anyone know what api level / platform to use for the Droid? And where to get the right skin? Is there anything hardware-specifications, that I need to know for Droid development?

API Level: 6 or Higher should Do because not all devices are updated.

Specifications: See here http://developer.motorola.com/products/droid/

Finally, are there any lists of steps to create a hello world app from the command line (Linux) and run it on the emulator and then run it on a real phone?

Go for Eclipse + Ubuntu.. Its easier to setup Skins and addons as well. Addons best match the physical device. Other options would be to use tedious for development(for a beginner like yourself). Ask you doubts here or post as a separate question. You would definitely get a respose.

HTC recently made a small guide for developers to help in command-line tools. Please take a look at it here http://htcdev.com/devcenter/opensense-sdk/quick-guide#building

You can also use Eclipse+ MotoDev studio...

http://developer.motorola.com/docstools/motodevstudio/




回答3:


Use android list target to list the available targets. This will contain following information :
-Target ID : Each target will have a different id and it should be used in all other commands.
-Skin : Each target contains the list of skins supported
-API Level : API level for particular target

Creating avd:

android create avd --target 8 --name DROID_EMULATOR --sdcard 128M --skin WVGA854

Creating a HelloWorld project :

android create project --name "HelloWorld" --target 8 --package com.test.helloworld --activity HelloWorld --path HelloWorld

This will create a HelloWorld directory in current directory. It will also create a build.xml in current directory.

You can use ant compile to compile the project and ant install to compile and install the project. This will install the app on available emulator or device. You can use ant to see the different build targets available.

HTH!

PS : I'm using Android SDK Tools, revision 9 and Platform-tools, revision 3.




回答4:


Once you've got the AVDs built, then as far as building from the command line goes, these two links I found the most useful:

http://developer.android.com/guide/developing/projects/projects-cmdline.html

http://developer.android.com/guide/developing/building/building-cmdline.html

If you create the sample project as described in 'Creating an Android Project', then it makes the directory structure for you and most usefully the build.properties and the build.xml. Even if you are not familiar with Ant, building it with Ant is dead easy and it pretty much does it all for you with the build.xml it made automatically. The procedure is described in detail in the second link. The only tedious bit is the signing of the apps. One thing the link doesn't tell you is that if you add two lines to the build.properties like:

key.store.password=YourPassword
key.alias.password=YourOtherPassword

then the signing is done automatically as well.

The sample app is very nearly a Hello World in itself. You only need to sign the app if you want to push it on to a real device. For the emulator you can just invoke the Ant 'debug' and 'install' targets which will build and push the app on to the emulator




回答5:


Try to stick with eclipse, if you're having problems there, it will be worse trying to do things on the command line. The built in tools like log cat and the debugger are of great value.




回答6:


I'm running eclipse for android dev on ubuntu 10.10 and I don't have any trouble at all. Don't give up on eclipse. I'd recommend asking questions about the stuff you have trouble with in eclipse.

If the problem is that in eclipse you're getting "?????????" as the device ID when you try run it on your phone, you just need to run sudo adb kill-server and sudo adb start-server in your terminal while eclipse is open. You might possibly also need to log in as root to add adb (from your android sdk) to your PATH environment variable.




回答7:


Sorry for not answering your question directly but what problems with Eclipse on Ubuntu do you have? I've been running Ubuntu for years, am heavy Eclipse user and haven't had any problems with this setup.

Edit: This asks for clarification and therefore should have been a comment but I didn't have enough rep at the time to post comments so there.



来源:https://stackoverflow.com/questions/2432812/how-to-set-up-android-sdk-for-command-line-development-on-linux

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!