花费了一整天时间搞这个,比较习惯用NetBeans,但网上查了一下,Android大多是在Eclipse下开发,好不容易找到个NetBeans的插件,安装时又出了问题,故整理一下资料,希望能用。 Google Android项目的用IDE开发时通常是Eclipse + Android SDK + Android plugin for Eclipse. Eclipse因为有IBM撑腰, 前几年一直是Java IDE的首选。不过现在Sun公司经过多年的摸黑和偷窥, 从NetBeans 5.5开始,就已经让很多的JAVA开发者开始接受Sun自己的Java IDE, 目前又新推出了NetBeans 6.0.1, 无论从哪方面讲, 都已经是可以和Eclipse相提并论甚至很多方面也已经强过了Eclipse (尤其是俺学校做作业开始要求用NetBeans了......) 所以俺一直在找寻在NetBeans下开发Android的方法。写作业用NetBeans , 做Android用Eclipse 那我不是吃饱了没事闲的给自己找罪受么。于是, 答案被俺在NetBeans的wiki上找到。 首先需要下载以下的程序 NetBeans Android SDK Android plugins for NetBeans (Undroid) 运行 jdk-6u14-windows-i586.exe 检查JDK是否安装成功。打开cmd窗口,输入 java –version 查看JDK的版本信息。 Preferred way of installing this plugin is registering nbandroid update center in your NetBeans installation. Address of this update center is http:///downloads/nbandroid/updates.xml In In Press Accept the license Press You're done, you can start Android development. 双击后就可以看到Android SDK and AVD Manager界面,在Installed Packages这样软件会自动刷新Refresh Sources下载源,不知道为什么提示Faild to fetch URL,不过我们手动连接正常,可能Google的这个Eclipse插件处理SSL加密URL存在bug,如图: 注意:这里可能存在,一个问题:SDK Setup.exe运行失败,具体问题可能显示如下: C:\Documents and Settings\Administrator>android Exception in thread "main" java.lang.UnsupportedClassVersionError: com/android/a rchquery/Main (Unsupported major.minor version 49.0) at java.lang.ClassLoader.defineClass0(Native Method) at java.lang.ClassLoader.defineClass(Unknown Source) at java.security.SecureClassLoader.defineClass(Unknown Source) at java.net.URLClassLoader.defineClass(Unknown Source) at java.net.URLClassLoader.access$100(Unknown Source) at java.net.URLClassLoader$1.run(Unknown Source) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) at java.lang.ClassLoader.loadClassInternal(Unknown Source) Exception in thread "main" java.lang.UnsupportedClassVersionError: com/android/a rchquery/Main (Unsupported major.minor version 49.0) at java.lang.ClassLoader.defineClass0(Native Method) at java.lang.ClassLoader.defineClass(Unknown Source) at java.security.SecureClassLoader.defineClass(Unknown Source) at java.net.URLClassLoader.defineClass(Unknown Source) at java.net.URLClassLoader.access$100(Unknown Source) at java.net.URLClassLoader$1.run(Unknown Source) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) at java.lang.ClassLoader.loadClassInternal(Unknown Source) [INFO] Starting Android SDK and AVD Manager 无效路径 系统找不到指定的路径。 系统找不到指定的路径。 系统找不到指定的路径。 系统找不到指定的路径。 系统找不到指定的路径。 系统找不到指定的路径。 系统找不到指定的路径。 系统找不到指定的路径。 系统找不到指定的路径。 系统找不到指定的路径。 系统找不到指定的路径。 ERROR: SWT folder '' does not exist. Please set ANDROID_SWT to point to the folder containing swt.jar for your platfo rm. C:\Documents and Settings\Administrator> 解决办法: 据说原因是:笔记本是32位的,而程序默认指向的是 x-86 64 bit 的swt.jar文件 在环境变量中加个就行了 ANDROID_SWT E:\androiddk\tools\lib\x86 之后,创建模拟器,需要注意: 正确启动模拟器[SDK 1.5] 安装好JDK后,设置好环境变量,即SDK解压出来后,其目录文件夹下的tools文件夹的物理路径。 在命令行管理器下,输入:android create avd -t 1 -n fans,并回车。(注意:这个命令中最后一个fans是可以任意取名的。大家在操作这步的时候,要切记android与create与avd与-t与2与-n与g1之间都是有空格的) 这时又会弹出个新的命令出来!我们只要输入no并回车就可以了。 结束以上的操作之后,打开存放SDK模拟器的文件,找到模拟器的程序右键点击发送——桌面快捷方式。 回到桌面后,发现双击那个小绿人发现还是打不开模拟器!先不要着急、右键点击属性!在快捷方式-目标的路径后面加上 -avd fans (再次注意:这个-前面是要空格一下的,avd后面跟着的fans则要跟你在上一步黑框中所输入的名字是一致的)。 该命令的详细介绍如下: 使用android create avd 命令来创建AVD 行为:"create avd": 创建一个新的Android 虚拟设备。 选项: -t --target 新的AVD 的Target ID(必须) -c --sdcard 指向一个共享的SD 存储卡的路径或是为新的AVD 定制的新SD 存储卡的容量大小 -p --path 新AVD 将被创建的位置路径 -n --name 新AVD 的名称(必须) -f --force 强制创建(覆盖已存在的AVD) -s --skin 新AVD 的皮肤 举例如下: 将建一个名叫GPhone 的AVD,Target ID=6、SD 存储卡容量52M、路径C:\AVD\、皮肤QVGA 开启命令行(开始->运行,键入cmd),进入Android SDK tools 目录 使用android命令列出Target ID值:andriod list target 查看已有的或新创建的AVD:android list avd 创建一个新的AVD:android create avd -n GPhone -t 6 -c 52M -p C:\AVD\ -s QVGA 运行指定的AVD:emulator -avd GPhone Adding the Android platformAfter you have installed the plugins,you have to add your Android platform by going to Tools->Java Platforms: Point it to your Android SDK location: If you're having error "A platform target has to be selected" like on picture below, make sure, that you've downloaded SDKs by running tools/android update tool (see [1] Creating a new Android projectNow, go to File->New Projects. You should now see a new entry for Android: Go ahead with the default application name (or change it!) You should see a new project structure as below: The file MainActivity.java is as shown below: /* * To change this template, choose Tools | Templates * and open the template in the editor. */package org.me.hellodroid;import android.app.Activity;import android.os.Bundle;/** * * @author amit */public class MainActivity extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle icicle) { super.onCreate(icicle); // ToDo add your GUI initialization code here }} As described in the Android SDK documentation Running your projectNow, build and Run your project as you would do with any other NetBeans project. Your project builds successfully and the Android emulator boots up: Where is our Just add setContentView(R.layout.main); to the above file in place of // ToDo add your GUI initialization code here This should have been generated by the plugin, because the main.xml containing the main view was generated. Alternatively we can do the following. We shall now add support to the skeleton code to display the text- TextView tv = new TextView(this);tv.setText("Hello, Android");setContentView(tv); You will notice that the IDE complains- "Cannot find symbol". This is because we need to import the class The file should now look like: package org.me.androidapplication1;import android.app.Activity;import android.os.Bundle;import android.widget.TextView;/** * * @author amit */public class MainActivity extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle icicle) { super.onCreate(icicle); TextView tv = new TextView(this); tv.setText("Hello, Android"); setContentView(tv); }} Now, run the project again |
|