Building and Running

本文详细介绍了Android应用从源代码到apk文件的构建全过程,包括编译、打包及签名步骤。阐述了Eclipse环境下如何自动构建apk,以及非Eclipse环境下使用Ant构建脚本的实现方式。同时,强调了应用程序在模拟器或设备上运行前的签名必要性,以及不同开发模式(debug vs. release)下的具体操作。

Building and Running

构建和运行

During the build process, your Android projects are compiled and packaged into an .apk file, the container for your application binary. It contains all of the information necessary to run your application on a device or emulator, such as compiled .dex files (.class files converted to Dalvik byte code), a binary version of the AndroidManifest.xml file, compiled resources (resources.arsc) and uncompiled resource files for your application.

在整个编译过程中,你的安卓工程将会打包成一个.apk 文件,它是你的程序的二进制代码容器。他包含了在设备或者模拟器上运行你的应用程序的所有必要的信息,例如编译过的.dex文件(.class文件转化形成的Dalvik字节码),一个二进制版本的AndroidManifest.xml文件,编译过的资源文件(resources.arsc)以及其他未编译的资源文件。

If you are developing in Eclipse, the ADT plugin incrementally builds your project as you make changes to the source code. Eclipse outputs an .apk file automatically to the bin folder of the project, so you do not have to do anything extra to generate the .apk.

如果你在Eclipse中进行开发,那么ADT插件将会增量的构建你的应用程序中源码改变的部分。Eclipse自动在你工程的bin目录下,输出了一个.apk文件,所以你无需做其他任何额外的操作。

If you are developing in a non-Eclipse environment, you can build your project with the generated build.xml Ant file that is in the project directory. The Ant file calls targets that automatically call the build tools for you.

如果你在非Eclipse环境中开发,你可以使用Ant的build.xml来编译你的工程。Ant文件能够自动的为你调用编译工具。

To run an application on an emulator or device, the application must be signed using debug or release mode. You typically want to sign your application in debug mode when you develop and test your application, because the build tools use a debug key with a known password so you do not have to enter it every time you build. When you are ready to release the application to Google Play, you must sign the application in release mode, using your own private key.

为了在模拟器或者设备上运行你的应用程序,你的应用程序必须使用调试(debug)或者发布(release)模式进行签名。当你开发和测试你的应用程序的时候,你可能希望用调试模式进行签名,因为构建工具使用的是已知的调试签名,所以你在每次编译时无需键入密码。当你准备在谷歌市场上发布时,你必须使用你的私钥以发布模式进行签名。

Fortunately, Eclipse or your Ant build script signs the application for you in debug mode when you build your application. You can also easily setup Eclipse or your Ant build to sign your application in release mode as well. For more information on signing applications, see Signing Your Applications.

幸运的是,Eclipse或者你的Ant构建脚本能够以调试或者发布模式签名你的应用程序。更多信息,请看Signing Your Applications.

The following diagram depicts the components involved in building and running an application:

下面的图表描述了如何编译和运行:

A Detailed Look at the Build Process


The build process involves many tools and processes that generate intermediate files on the way to producing an .apk. If you are developing in Eclipse, the complete build process is automatically done periodically as you develop and save your code changes. If you are using other IDEs, this build process is done every time you run the generated Ant build script for your project. It is useful, however, to understand what is happening under the hood since much of the tools and processes are masked from you. The following diagram depicts the different tools and processes that are involved in a build:

构建程序包含了很多程序和过程,他们在产生.apk文件的过程中产生了很多中间中间。如果你在Eclipse中开发,在你保存改变的代码之后,完整的编译工具将会周期性的进行。如果你使用其他的IDE工具,构建过程会在你每次执行Ant编译脚本时执行。这很有意义,然而,为了理解构建工具隐藏背后发生了什么事情。下面这张图表将会描述不同的工具在你的构建过程中所进行的操作。

The general process for a typical build is outlined below:

一个典型的程序通过下面这些步骤生成:

  • The Android Asset Packaging Tool (aapt) takes your application resource files, such as the AndroidManifest.xmlfile and the XML files for your Activities, and compiles them. An R.java is also produced so you can reference your resources from your Java code.
  • 安卓资源打包工具(aapt)获取你的应用程序的资源文件,例如AndroidManifest.xml文件,XML等,编译他们。一个R.java也是产品,以至于你能够通过Java代码引用他们。
  • The aidl tool converts any .aidl interfaces that you have into Java interfaces.
  • aidl个工具用于转化任何的.aidl接口为Java接口
  • All of your Java code, including the R.java and .aidl files, are compiled by the Java compiler and .class files are output.
  • 所有的Java代码,包括R.java以及.aidl文件,将会通过Java编译器,以.class文件类型输出。
  • The dex tool converts the .class files to Dalvik byte code. Any 3rd party libraries and .class files that you have included in your project are also converted into .dex files so that they can be packaged into the final .apk file.
  • dex工具将会把.class文件转化为Dalvik字节码。任何第三方的.class文件也会转化为.dex文件,以便能够打包到.apk文件中。
  • All non-compiled resources (such as images), compiled resources, and the .dex files are sent to the apkbuilder tool to be packaged into an .apk file.
  • 所有的非编译资源(例如图像),编译资源,以及.dex文件都会发送给apkbuilder工具,以便于打包成为你个.apk文件。
  • Once the .apk is built, it must be signed with either a debug or release key before it can be installed to a device.
  • 一旦.apk包构建后,你必须使用debug或者release进行签名,然后才能安装到设备上面。
  • Finally, if the application is being signed in release mode, you must align the .apk with the zipalign tool. Aligning the final .apk decreases memory usage when the application is running on a device.
  • 最终,如果应用程序以release进行了签名,你需要使用zipalign工具进行对齐。对齐的.apk将会在运行时节省内存开销。
本研究基于扩展卡尔曼滤波(EKF)方法,构建了一套用于航天器姿态与轨道协同控制的仿真系统。该系统采用参数化编程设计,具备清晰的逻辑结构和详细的代码注释,便于用户根据具体需求调整参数。所提供的案例数据可直接在MATLAB环境中运行,无需额外预处理步骤,适用于计算机科学、电子信息工程及数学等相关专业学生的课程设计、综合实践或毕业课题。 在航天工程实践中,精确的姿态与轨道控制是保障深空探测、卫星组网及空间设施建设等任务成功实施的基础。扩展卡尔曼滤波作为一种适用于非线性动态系统的状态估计算法,能够有效处理系统模型中的不确定性与测量噪声,因此在航天器耦合控制领域具有重要应用价值。本研究实现的系统通过模块化设计,支持用户针对不同航天器平台或任务场景进行灵活配置,例如卫星轨道维持、飞行器交会对接或地外天体定点着陆等控制问题。 为提升系统的易用性与教学适用性,代码中关键算法步骤均附有说明性注释,有助于用户理解滤波器的初始化、状态预测、观测更新等核心流程。同时,系统兼容多个MATLAB版本(包括2014a、2019b及2024b),可适应不同的软件环境。通过实际操作该仿真系统,学生不仅能够深化对航天动力学与控制理论的认识,还可培养工程编程能力与实际问题分析技能,为后续从事相关技术研究或工程开发奠定基础。 资源来源于网络分享,仅用于学习交流使用,请勿用于商业,如有侵权请联系我删除!
### 解决 Bash 脚本中 `set` 命令的无效选项错误并优化 CppUTest 构建流程与覆盖率报告生成 #### 1. 分析 `set` 命令无效选项错误 在运行 Bash 脚本时,如果出现 `'invalid option'` 错误,通常是因为传递给 `set` 的选项不符合其预期格式或规则。`set` 命令用于设置 shell 的环境变量和选项[^2]。例如,以下代码展示了如何正确使用 `set` 命令来启用调试模式(`-x`)并打印位置参数: ```bash set -x set -- "arg1" "arg2" "arg3" echo $1 $2 $3 ``` 如果脚本中存在类似以下的无效命令,则会引发错误: ```bash set -o invalidoption ``` #### 2. 解决方案:修复 `set` 命令中的无效选项 为解决 `'invalid option'` 错误,可以采取以下措施: - **检查脚本中的 `set` 命令**:确认传递给 `set` 的选项是否正确。例如,常见的有效选项包括 `-e`(遇到错误退出)、`-u`(禁止未定义变量)、`-x`(调试模式)等[^3]。 - **分离选项和参数**:如果脚本中需要同时指定选项和参数,应使用连字符将两者分隔开。例如: ```bash set -o errexit - "param1" "param2" ``` #### 3. 优化 CppUTest 构建流程 CppUTest 是一个轻量级的单元测试框架,适用于 C 和 C++ 项目。为了优化构建流程,可以采用以下方法: - **使用 Makefile 自动化构建**:通过编写 Makefile 文件,简化构建过程。例如: ```makefile CC = g++ CFLAGS = -Wall -g -O0 LDFLAGS = -lcpputest SOURCES = $(wildcard *.cpp) OBJECTS = $(SOURCES:.cpp=.o) EXECUTABLE = test_executable all: $(EXECUTABLE) $(EXECUTABLE): $(OBJECTS) $(CC) $(OBJECTS) -o $@ $(LDFLAGS) %.o: %.cpp $(CC) -c $< -o $@ $(CFLAGS) clean: rm -f *.o $(EXECUTABLE) ``` - **集成 Gcov 和 Lcov 工具**:通过 Gcov 和 Lcov 工具生成覆盖率报告。以下是配置示例: ```makefile CFLAGS += --coverage LDFLAGS += --coverage coverage: lcov --capture --directory . --output-file coverage.info genhtml coverage.info --output-directory coverage_report ``` #### 4. 示例脚本:结合 CppUTest、Gcov 和 Lcov 以下是一个完整的示例脚本,展示如何修复 `set` 命令错误并生成覆盖率报告: ```bash #!/bin/bash # 启用调试模式并设置严格选项 set -euo pipefail # 定义变量 SOURCE_DIR="src" TEST_DIR="tests" COVERAGE_REPORT="coverage_report" # 构建步骤 make clean make all # 运行测试 ./test_executable # 生成覆盖率报告 lcov --capture --directory . --output-file coverage.info genhtml coverage.info --output-directory ${COVERAGE_REPORT} # 输出结果路径 echo "Coverage report generated at: ${COVERAGE_REPORT}/index.html" ``` #### 5. 注意事项 - 确保安装了必要的工具(如 Gcov、Lcov 和 CppUTest),并通过包管理器安装缺失的依赖项。 - 如果脚本需要兼容多个 Bash 版本,建议使用 POSIX 兼容的语法[^4]。 ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值