delin17的笔记 https://bbs.21ic.com/?467504 [收藏] [复制] [RSS]

日志

Android第二天--基于Snake的示例建立和运行程序

已有 990 次阅读2012-2-7 14:36 |系统分类:嵌入式系统| Android, Snake

第一步:简单创建工程;File->NewProject->Other跳出对话框,选择Android后,Next。选择Create Project from existing sourc. 然后选择SDK下Sample下对应的Snake目录。然后点Next到完成。


第二步:创建AVD(Android Virtual Device)。windows->AVD Manager。跳出对话框后添加,然后在中间选择相应的选项来对应你将来真实的产品。完成后点击Create AVD.这个需要一定的时间。注意:系统默认AVD是存放在C:\Documents and Settings\WindowsUserName\.android下面。如需要修改:请在windows中添加环境变量:ANDROID_SDK_HOME = 你要保存的目录。


第三步:运行配置参数。Run->Run configuration->Run/Debug Configuration会跳出一个对话框。根据自己的需要对其进行配置。


第四步:运行程序。 注意运行和启动模拟器的时间有点长,在我机器上感觉是这样。我在运行程序中遇到两个问题。


1  提示API版本不对。


问题原因是在AndroidManifest.xml中没有对版本定义。请通过eclipse将Min SDk version改成你对应的Version就好了,另也可以通过编辑这个文件来实现:在文件中添加下一行。添加在application对的前面。


<uses-sdk android:minSdkVersion="15"/>   15为我所对应的版本号


 


我修改后整个文件如下:


<!-- Declare the contents of this Android application.  The namespace
     attribute brings in the Android platform namespace, and the package
     supplies a unique name for the application.  When writing your
     own application, the package name must be changed from "com.example.*"
     to come from a domain that you own or have control over. -->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.android.snake">
    <uses-sdk android:minSdkVersion="15"/>
    <application android:label="Snake on a Phone">
      <activity android:name="Snake"
        android:theme="@android:style/Theme.NoTitleBar"
        android:screenOrientation="portrait"
        android:configChanges="keyboardHidden|orientation">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>
</manifest>


2: 由于先前版本不对,导致安装未完全,修改好后没有办法再安装同一个apk。需要将先前的完全卸载。于是需要进入shell模式。怎么进入shell。我在模拟上没有找到。我是这样实现的:在windows的命令行中转入到android SDK对应的目录下运行相应的可执行文件。例如运行adb devices可以查询到模拟器。adb uninstall 应用程序(adb uninstall com.example.android.snake)   可以删除模拟器中的应用程序。  注意:这些操作都必须在模拟器运行时才有效。


路过

鸡蛋

鲜花

握手

雷人

评论 (0 个评论)