Creating an Android Project

本文指导您如何使用Eclipse IDE及其ADT插件或仅使用命令行工具创建Android应用项目。步骤包括设置项目名称、包名、构建目标等关键参数,并提供图标定制和活动模板选择指南。

An Android project contains all the files that comprise the source code for your Android app. The Android SDK tools make it easy to start a new Android project with a set of default project directories and files.

This lesson shows how to create a new project either using Eclipse (with the ADT plugin) or using the SDK tools from a command line.

Note: You should already have the Android SDK installed, and if you're using Eclipse, you should also have the ADT plugin installed (version 20.0.0 or higher). If you don't have these, follow the guide to Installing the Android SDK before you start this lesson.

Create a Project with Eclipse

  1. In Eclipse, click New Android App Project in the toolbar. (If you don’t see this button, then you have not installed the ADT plugin—see Installing the Eclipse Plugin.)


  2. Fill in the form that appears:
    • Application Name is the app name that appears to users. For this project, use "My First App."

    • Project Name is the name of your project directory and the name visible in Eclipse.
    • Package Name is the package namespace for your app (following the same rules as packages in the Java programming language). Your package name must be unique across all packages installed on the Android system. For this reason, it's generally best if you use a name that begins with the reverse domain name of your organization or publisher entity. For this project, you can use something like "com.example.myfirstapp." However, you cannot publish your app on Google Play using the "com.example" namespace.
    • Build SDK is the platform version against which you will compile your app. By default, this is set to the latest version of Android available in your SDK. (It should be Android 4.1 or greater; if you don't have such a version available, you must install one using the SDK Manager). You can still build your app to support older versions, but setting the build target to the latest version allows you to enable new features and optimize your app for a great user experience on the latest devices.
    • Minimum Required SDK is the lowest version of Android that your app supports. To support as many devices as possible, you should set this to the lowest version available that allows your app to provide its core feature set. If any feature of your app is possible only on newer versions of Android and it's not critical to the app's core feature set, you can enable the feature only when running on the versions that support it.

      Leave this set to the default value for this project.

    Click Next.

  3. The following screen provides tools to help you create a launcher icon for your app.

    You can customize an icon in several ways and the tool generates an icon for all screen densities. Before you publish your app, you should be sure your icon meets the specifications defined in the Iconography design guide.

    Click Next.

  4. Now you can select an activity template from which to begin building your app.

    For this project, select BlankActivity and click Next.

  5. Leave all the details for the activity in their default state and click Finish.

Your Android project is now set up with some default files and you’re ready to begin building the app. Continue to the next lesson.

Create a Project with Command Line Tools

If you're not using the Eclipse IDE with the ADT plugin, you can instead create your project using the SDK tools from a command line:

  1. Change directories into the Android SDK’s tools/ path.
  2. Execute:
    android list targets

    This prints a list of the available Android platforms that you’ve downloaded for your SDK. Find the platform against which you want to compile your app. Make a note of the target id. We recommend that you select the highest version possible. You can still build your app to support older versions, but setting the build target to the latest version allows you to optimize your app for the latest devices.

    If you don't see any targets listed, you need to install some using the Android SDK Manager tool. See Adding Platforms and Packages.

  3. Execute:
    android create project --target <target-id> --name MyFirstApp \
    --path <path-to-workspace>/MyFirstApp --activity MainActivity \
    --package com.example.myfirstapp
    

    Replace <target-id> with an id from the list of targets (from the previous step) and replace <path-to-workspace> with the location in which you want to save your Android projects.

Your Android project is now set up with several default configurations and you’re ready to begin building the app. Continue to the next lesson.

Tip: Add the platform-tools/ as well as the tools/ directory to your PATH environment variable.

### 如何在 Android Studio 中创建或打开项目 当没有可用的项目时,在 Android Studio 中可以通过以下方式来创建或打开一个新的项目: #### 创建新项目 通过启动 Android Studio 并进入欢迎界面,可以轻松创建新的应用程序项目。具体操作如下: - 启动 Android Studio 如果尚未开启。 - 在主窗口 **Welcome to Android Studio** 中点击 **Start a new Android Studio project**[^1]。 - 进入到 **Create Android Project** 窗口后,输入应用名称为 `Hello World` 或者其他自定义名称。 此过程会引导开发者完成一系列配置选项,例如目标设备、编程语言以及项目的最低兼容版本等设置。 #### 打开现有项目 如果之前已经存在某些保存过的项目,则可以选择将其导入当前工作环境之中: - 在 Android Studio 的初始页面上选择 **Open an existing Android Studio project**。 - 浏览至存储旧项目的文件夹位置并选中它加载进来即可。 对于日志查看工具 Logcat 而言,通常情况下它是绑定于特定类型的工程之下的;比如有时会在原生安卓工程项目里正常显示而到了跨平台框架(如Flutter)构建出来的方案里面就可能找不到其踪影了[^2]。 另外一种情况涉及到向已有解决方案添加额外模块或者子项的操作流程说明也可以作为参考依据之一:执行添加新组件的动作,并按照提示命名该实例对象为例来说叫做 RibbonDemo 就好[^3]。 ```java // Example Java Code Snippet for Creating New Activity in Android Studio public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); TextView textView = (TextView)findViewById(R.id.textView); textView.setText("Project Created Successfully!"); } } ``` 以上代码片段展示了如何在一个典型的Android活动中初始化UI元素并将文本更新为确认消息。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值