第二章 工程结构(本章由同学lzm翻译)------------The Busy Coder's Guide to Android Development

第二章       工程结构

Android工程像普通的 JAVA工程一样,被组织成明确的树状目录结构。但其目录结构内容又不同于 JAVA工程,这种改变是为了生成真正的 Android应用程序而做准备,以使其能在设备或者模拟器上运行。下面具体讲解一下 Android目录结构,可以帮助你理解这种目录结构安排,更好的学习本书中提到的一些样例。

 

基本内容

当你创建一个新的 Android工程后,在工程的根目录下,有七个重要的条目。

l  AndroidManifest.xml,是一个 xml文件,符合 xml基本规范。它有两方面的内容,一是描述应用程序,二是描述应用程序包含的组件,如 activites services

l  build.xml,它是 Ant脚本,描述编译程序和安装程序的规则

l  bin/,它包含编译后的应用程序,如 class文件

l  libs/,它包含你的程序使用的第三方 java jar

l  src/,应用程序的 java源代码

l  res/,它包含图标、界面布局之类的资源文件,这些资源文件会与编译后的 java文件一块打包到应用程序中。

l  assets/,一些文件,会打包到应用程序中,并发布到设备上

 

擦一把汗

当你创建工程时,你为应用程序的主 activity选择合法的类名(例如: com.commonsware.android.SomeDemo),然后你会在你的工程 src目录下看到相应的目录树结构已被创建,还有一个代表主 activity Activity子类桩被创建(例如: src/com/commonsware/android/SomeDemo.java),你可以改变这个 java文件,或者在 src下添加其它 java文件来实现你的应用程序。

 

第一次编译工程时,在主 activity目录树下, Android编译工具会生成 R.java文件。这个文件包含许多常数,每一个常数都与 res/目录下的相应资源文件相关联,这些资源文件是按你需要你放进去的。你不能手动去修改 R.java文件,让 Android工具帮你修改。在许多样例中,你都可以看到,我们引用 R.java中的标识符(例如:引用布局标识符 R.layout.main

 

现在,讲解余下的部分

你会注意到,在你的工程下有一个 res/目录树,它里面包含了应用程序的资源-静态文件,这些文件会被原样打包到你的 application中,或者被预处理后再打包。在 res/下面,会有一些子目录,它们可能自动生成,也可能是你手工建的:

l  res/drawable/ 图片目录( PNG JPEG,等等)

l  res/layout/ 基于 xml的界面布局说明

l  res/menu/  基于 xml 的菜单说明

l  res/raw/  普通文件(例如 联系人信息 CSV 文件)

l  res/values/  字符串、标尺等类似数据

l  res/xml/  其它目的 xml 文件,你希望它们被打包到 application

在接下来的章节,我们会涉及所有的这些文件,甚者更多。

 

你学到了什么

当你编译工程时(通过 Ant 或者编译环境),编译结果会放在 bin/ 目录下。更具体些:

l  bin/classes/  编译过的 Java 类, class 文件

l  bin/classes.dex  可执行的文件,由编译好的 class 文件生成

l  bin/yourapp.ap_  你的应用程序的资源,被打包成 zip 文件( yourapp 是你的应用程序的名称)

l  bin/yourapp-debug.apk or bin/yourapp-unsigned.apk 是真正的 Android 应用程序( yourapp 是你的应用程序的名称)

.APK 文件是一个 zip 包,包含 .dex 文件 编译后的资源文件( resources.arsc 未编译的资源文件(在 res/raw/ 下的文件)和 AndroidManifest.xml 文件。它也可以数字签名,如果文件名字包含 -debug 串,表明该 APK 文件已经用调试密钥签名过,可以在模拟器下使用;如果文件名字包含 -unsigned 串,表明你想发布你的应用程序( ant 发布),但 APK 仍需要数字签名,你可以使用 jarsigner 工具和一个官方的密钥签名。

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
The Busy Coder's Guide to Android Development: Version 8.2 Supports Through Android 7.1 2017 | English | ASIN: B06Y4TCV7F | 756 pages | PDF + EPUB (conv) | 63 Mb Do you want current information about how to develop Android apps? This book covers the latest Android Studio version and the latest version of Android, plus all the information you need to get your apps working on older devices. And, with updates coming every couple of months via the Warescription, you will keep up to date. What’s New in Version 8.2? For those of you who have read previous editions of this book, here are some of the highlights of what is new in the prose in Version 8.2: Added a chapter on the basics of using RxJava Added a chapter on viewing PDFs, including embedding PDF viewers in your app Added a chapter on advanced RecyclerView techniques, starting with using RecyclerView to replace a ViewPager for page-at-a-time user interfaces Removed the appendix focusing on Android 7.0’s changes, with that material being moved into appropriate chapters of the book Various miscellaneous improvements and errata fixes This update also uses two different font sizes for code listings, employing a larger font for listings whose lines are all fairly short, to help improve readabililty. Due to a change in the publication process, links between chapters are showing up with changebars in this version. This should be a one-time issue, not affecting future versions of the book. Also, the APK edition of the book has a new appinar on Android 7.0’s changes to notifications.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值