Android2.33 应用程序工程目录分析

来源:互联网 发布:tbi 淘宝助理 编辑:程序博客网 时间:2024/05/04 08:14
 HelloWorld程序工程目录结构

1)     src目录

2)     gen目录

3)     Android 2.3.3

4)     assets目录

5)     res/drawable目录

6)     res/layout目录

7)     res/values

8)     AndroidManifest.xml

9)     default.properties

10)        proguard.cfg

 

HelloWorld程序工程目录结构

1)        src目录

本目录下存放的Android应用程序的Java源代码,HelloWorldActivity类继承了Activity类,并覆盖onCreate()方法,在该方法中调用父类的构造方法,然后调用setContentView()方法展示视图界面。R.layout.main是R.java资源类中的布局属性。

package com.test; import android.app.Activity;import android.os.Bundle;import android.view.Gravity;import android.view.View;import android.widget.Button;import android.widget.TextView;import android.widget.Toast; public class HelloWorldActivity extends Activity {    /** Called when the activity is first created. */    @Override    public void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.main);    }}


2)        gen目录

本目录存放的是工程资源索引文件 R.java,该类由系统自动生成,根据不同的资源类型又包含了不同的静态内部类。

a)         attr静态类声明属性;

b)        drawable静态类声明图片资源;

c)         layout静态类声明布局文件;

d)        string静态类声明字符串;

e)         id静态类声明界面中使用的组件;

/* AUTO-GENERATED FILE.  DO NOT MODIFY. * * This class was automatically generated by the * aapt tool from the resource data it found.  It * should not be modified by hand. */ package com.test; public final class R {    public static final class attr {    }    public static final class drawable {        public static final int clwf=0x7f020000;        public static final int icon=0x7f020001;    }    public static final class id {        public static final int btn=0x7f050001;        public static final int textview1=0x7f050000;    }    public static final class layout {        public static final int main=0x7f030000;    }    public static final class string {        public static final int app_name=0x7f040001;        public static final int hello=0x7f040000;    }}


 

3)        Android 2.3.3

该目录存放的是Android SDK jar包(android.jar),包含构建应用程序所需的所有的Android SDK 库(如Views、Controls)和APIs。通过android.jar将自己的应用程序绑定到Android SDK和Android Emulator,这允许你使用所有Android的库和包,且使你的应用程序在适当的环境中调试。

android.app :提供高层的程序模型、提供基本的运行环境

android.content :包含各种的对设备上的数据进行访问和发布的类

android.database :通过内容提供者浏览和操作数据库

android.graphics :底层的图形库,包含画布,颜色过滤,点,矩形,可以将他们直接绘制到屏幕上.

android.location :定位和相关服务的类

android.media :提供一些类管理多种音频、视频的媒体接口

android.net :提供帮助网络访问的类,超过通常的java.net.* 接口

android.os :提供了系统服务、消息传输、IPC 机制

android.opengl :提供OpenGL 的工具

android.provider :提供类访问Android 的内容提供者

android.telephony :提供与拨打电话相关的API 交互

android.view :提供基础的用户界面接口框架

android.util :涉及工具性的方法,例如时间日期的操作

android.webkit :默认浏览器操作接口

android.widget :包含各种UI 元素(大部分是可见的)在应用程序的屏幕中使用

4)        assets目录

本目录存放应用程序需要使用到的诸如mp3、视频类的文件。

5)        res/drawable目录

本目录存放工程所使用的图片资源

6)        res/layout目录

本目录存放工程的布局文件 main.xml,该文件中声明了程序中使用到的视图组件。

LinearLayout:线性布局方式申明,该节点为xml文件的根节点。

TextView:定义一个文本视图组件

Button:定义一个按钮组件

<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:orientation="vertical"    android:layout_width="fill_parent"    android:layout_height="fill_parent"    android:weightSum="1"><TextView      android:id="@+id/textview1"    android:layout_width="fill_parent"     android:layout_height="wrap_content"     android:text="Hello World!"/><Button     android:layout_height="wrap_content"     android:text="Button"     android:id="@+id/btn"     android:layout_width="124dp"     android:layout_gravity="top"></Button></LinearLayout>


7)        res/values

本目录存放的是工程所使用的字符串产量定义文件:strings.xml。

这样定义,一是降低了程序的耦合性;二是Android通过一种特殊方式来使用字符串,提高了程序的运行效率。

<?xml version="1.0" encoding="utf-8"?><resources>    <string name="hello">Hello World, HelloWorldActivity!</string>    <string name="app_name">HelloWorld</string></resources>


8)        AndroidManifest.xml

该文件为工程所使用的全局配置文件。

所有Android中使用到的组件(如Activity、Service、ContentProvider和Broadcast Receiver)都要在该文件中声明,并且该文件中还可以声明一些权限以及SDK的最低版本信息。

<manifest>:根节点,指定了命名空间、包名称、版本代码号和版本名称等信息;

<uses-sdk>:申明工程所使用的SDK最低版本号;

<application>:定义程序所使用图标和名称;

<activity>:定义activity的类名称和标题

<intent-filter>: <activity>的子节点,是找到该activity的过滤器,action属性表明该activity是程序的入口,category属性声明在加载程序运行。

<?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android"      package="com.test"      android:versionCode="1"      android:versionName="1.0">    <uses-sdk android:minSdkVersion="8" />     <application android:icon="@drawable/icon" android:label="app_name">        <activity android:name=".HelloWorldActivity"                  android:label="app_name">            <intent-filter>                <action android:name="android.intent.action.MAIN" />                <category android:name="android.intent.category.LAUNCHER" />            </intent-filter>        </activity>    </application></manifest>


 

9)         default.properties

记录项目中所需要的环境信息,比如Android的版本等。

# This file is automatically generated by Android Tools.# Do not modify this file -- YOUR CHANGES WILL BE ERASED!## This file must be checked in Version Control Systems.## To customize properties used by the Ant build system use,# "build.properties", and override values to adapt the script to your# project structure. # Project target.target=android-10


 

10)      proguard.cfg

工程自动创建,定义了混淆器,防止apk文件被反汇编。

-optimizationpasses 5-dontusemixedcaseclassnames-dontskipnonpubliclibraryclasses-dontpreverify-verbose-optimizations !code/simplification/arithmetic,!field/*,!class/merging/* -keep public class * extends android.app.Activity-keep public class * extends android.app.Application-keep public class * extends android.app.Service-keep public class * extends android.content.BroadcastReceiver-keep public class * extends android.content.ContentProvider-keep public class * extends android.app.backup.BackupAgentHelper-keep public class * extends android.preference.Preference-keep public class com.android.vending.licensing.ILicensingService -keepclasseswithmembernames class * {    native <methods>;} -keepclasseswithmembers class * {    public <init>(android.content.Context, android.util.AttributeSet);} -keepclasseswithmembers class * {    public <init>(android.content.Context, android.util.AttributeSet, int);} -keepclassmembers class * extends android.app.Activity {   public void *(android.view.View);} -keepclassmembers enum * {    public static **[] values();    public static ** valueOf(java.lang.String);} -keep class * implements android.os.Parcelable {  public static final android.os.Parcelable$Creator *;}

 

 

 

原创粉丝点击