`
gemantic
  • 浏览: 336017 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

Android介绍

 
阅读更多

[img][/img]

 

1. 概述

 

       Android is a mobile operating system that is based on a modified version of Linux.

1.1     优势

      . 源代码完全开放

 

      . 采用了对有限内存、电池和CPU 优化过的虚拟机Dalvik

1.2     版本

 

3.0 版本  --- 仅仅针对于平板电脑

In February 2011 , Google released Android 3.0, a tablet-only release supporting widescreen devices.

4.0 版本  ----  同时支持平板电脑和智能手机

In October 2011, Google released Android 4.0, a version that brought all the features introduced in Android 3.0 to smartphones, along with some new features such as facial recognition unlock

一个Android平台提供的框架API,被指定一个整数标识符,称为“API级别”。每一个版本的Android平台只支持有一个API级别


1.3 应用程序框架

• 丰富而又可扩展的视图(Views)
  
    可以用来构建应用程序, 它包括列表(lists),网格(grids), 文本框(text boxes),按钮( buttons),

    甚至可嵌入的web 浏览器。

• 内容提供器(Content Providers)
 
    使得应用程序可以访问另一个应用程序的数据(如联系人数据库), 或者共享它们自己的数据

• 资源管理器(Resource Manager)
 
   提供非代码资源的访问,如本地字符串,图形,和布局文件( layout files )

• 通知管理器(Notification Manager)
 
   使得应用程序可以在状态栏中显示自定义的提示信息。

• 活动管理器( Activity Manager)
 
   用来管理应用程序生命周期并提供常用的导航回退功能。

1.4 ANDROID运行库

1.4.1 DALVIK虚拟机


         Android 包括了一个核心库,该核心库提供了JAVA 编程语言核心库的大多数功能。

         每一个Android 应用程序都在它自己的进程中运行,都拥有一个独立的Dalvik 虚拟机实例。Dalvik 被设计成一个设

 

         备可以同时高效地运行多个虚拟系统。Dalvik 虚拟机执行(.dex)的Dalvik 可执行文件,该格式文件针对小内存使

 

         用做了优化。同时虚拟机是基于寄存器的,所有的类都经由JAVA 编译器编译,然后通过SDK中的"dx" 工具转化

 

         成.dex 格式由虚拟机执行。 Dalvik 虚拟机依赖于linux 内核的一些功能,比如线程机制和底层内存管理机制

1.4.2 ANDROID 程序的反编译

1.4.2.1 工具


dex2jar     下载地址:http://code.google.com/p/dex2jar/downloads/list

JD-GUI

1.4.2.2 反编译步骤

.通过dex2jar将apk转换为jar文件

1) 从apk中抽取classex.dex文件

    虽说dex2jar可以直接从apk抽取出jar文件,但是会经常遇到一些问题,所以常用的方法是将.apk文件,重命名

 

    为.zip,解压缩后,找到classes.dex文件

2) 运行dex2jar生成.jar文件

    在Mac系统,打开终端,定位到dex2jar所在的目录,执行以下命令:

     ./dex2jar.sh absolute_path_classes.dex

 
    在win系统,打开命令行,定位到dex2jar所在的目录,执行以下命令:

    .\dex2jar.bat  absolute_path_classes.dex  生成文件:classes_dex2jar.jar

.通过jd-gui将jar文件反编译为java文件

 

     运行jd-gui,打开文件classes_dex2jar.jar,可以看到源码

1.4.3  代码混淆

           由于各种反编译工具的泛滥,作为Android程序员在2.3版本以前只能通过手动添proguard来实现代码混淆,

 

            proguard这个工具是一个java代码混淆的工具在2.3版本的sdk中 我们可以看到在android-sdk-

 

            windows/tools/下面多了一个proguard文件夹google已经把proguard技术放在了android sdk里面 可以通

 

             过正常的编译方式也能实现代码混淆了

1.4.3.1 代码混淆相关的文件

1.4.3.2  代码混淆的步骤

修改default.properties file 加上一句

proguard.config=proguard.cfg

生成有数字签名的apk文件

注:所有的应用程序都必须有数字证书,Android系统不会安装一个没有数字证书的应用程序

1.5 ANDOIRD开发环境

.Eclipse 3.3 (Europa), 3.4 (Ganymede)
.Eclipse JDT plugin (included in most Eclipse IDE packages)
.JDK 5 or JDK 6 (JRE alone is not sufficient)
.Android Development Tools plugin (optional)

1.6 环境搭建

JDK 安装

Google Android SDK 安装
下载地址:http://developer.android.com/sdk/index.html

建议:目前最新的版本是18,建议最低使用17版本,否则在生成最终版本的时候会有问题!

配置Android SDK Manager

The Android SDK Manager manages the various versions of the Android SDK currently installed
on your computer.

配置环境变量:
path=..;../android-sdk/platform-tools   使用命令行工具必须配置

ADT

The Android Development Tools (ADT) plug-in for Eclipse is an extension to the Eclipse IDE that

supports the creation and debugging of Android applications. Using the ADT, you will be able to do

the following in Eclipse:
➤ Create new Android application projects.
➤ Access the tools for accessing your Android emulators and devices.
➤ Compile and debug Android applications.
➤ Export Android applications into Android Packages (APK).
➤ Create digital certificates for code-signing your APK.

安装地址:http://dl-ssl.google.com/android/eclipse

1.7 创建一个ANDROID 程序

1.7.1 应用程序类型 
. Library  
Eg> Andengine

.Application

1.7.2 目录结构

SRC

       Contains the .java source files for your project. In this example, there is one file, MainActivity.java.

 

       The  MainActivity.java file is the source file for your activity. You will write the code for your

 

       application in this file.

Android 2.3 library

       This item contains one file, android.jar, which contains all the class libraries needed for an Android

 

        application.
Gen

       Contains the R.java file, a compiler-generated file that references all the resources found in your

 

       project. You should not modify this file.

Assets

       This folder contains all the assets used by your application, such as HTML, text files, databases,

 

       etc.

Res

        This folder contains all the resources used in your application. It also contains a few other

 

        subfolders: drawable-<resolution>, layout, and values.

assets:

 

         用于存放需要打包到应用程序的静态文件,以便部署到设备中。与res/raw不同点在于,ASSETS支持任意深度的子

 

         目录。这些文件不会生成任何资源ID,必须使用/assets开始(不包含它)的相对路径名。
res:

 

         用于存放应用程序的资源(如图标、GUI布局等),将被打包到编译后的Java中。不支持深度子目录

AndroidManifest.xml

         This is the manifest file for your Android application. Here you specify the permissions needed by

 

         your application, as well as other features (such as intent-filters)

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

 


Main.xml


The main.xml file defines the user interface for your activity.

<?xml version="1.0" encoding="utf-8"?>

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:scrollbars="vertical" >

<LinearLayout
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:background="@drawable/login_bg"
    android:layout_height="wrap_content">
    <ImageView android:src="@drawable/login_logo"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_margin="5dip"
    android:id="@+id/logo_image_view" />
    <RelativeLayout
                   android:layout_margin="5dip"
                   android:layout_width="fill_parent"
                   android:layout_height="wrap_content"
                   android:layout_below="@+id/logo_image_view"
                   android:gravity="top"
                   android:padding="15dip"
                   android:layout_gravity="center_vertical"
                   android:background="@drawable/login_form_bg">
   
<TextView android:id="@+id/user_name_text_view"
                  android:layout_width="wrap_content"
                   android:layout_height="wrap_content"
                   android:layout_alignParentTop="true"
                   android:text="@string/username"
                   android:textColor="@color/black"
                   android:textStyle="bold"
                   android:textSize="20sp"
                   android:layout_margin="10dip"
 >
</TextView>

<EditText android:text="" android:id="@+id/input_passport"
                android:layout_width="fill_parent" 
                android:layout_height="wrap_content" 
                android:layout_below="@+id/user_name_text_view"
                android:textSize="18sp"></EditText>
        ……..
</RelativeLayout>
</LinearLayout>
</ScrollView>

String.xml

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

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics