Chapter 1: Getting started – your first line of Android code

1.1 Get the Big Picture — Introduction to Android Kingdom

1.1.1 Android System Architecture

  • The Android system architecture is divided into four layers:

  • Linux kernel layer: The Android system is based on the Linux kernel. Provides underlying drivers for Android hardware, such as display drivers, audio drivers, camera drivers, Bluetooth drivers, Wi-Fi drivers, power management, etc.

  • System runtime layer: provides feature support for Android system through C/C++ library, for example :SQLite library provides database support, Webkit library provides browser kernel support. This layer also has the Android runtime library, which provides the core library that allows Android applications to be developed in the Java language. The Android runtime library also includes Dalvik Virtual Machine (ART runtime environment after 5.0), which enables each Android application to run in a separate process and has its own Dalvik VIRTUAL machine instance. Compared to Java VIRTUAL machine,Dalvik is specially customized for mobile devices, targeting mobile phones The memory and CPI performance are optimized.

  • Application framework layer: Provides various apis for applications, which are used to complete the core applications of Android.

  • Application layer: All applications in the mobile phone belong to the application layer, such as the system’s own contacts, SMS, and other third-party applications.

1.1.2 Released Versions of Android (as of December 201712)

<tr> <th width=10%, bgcolor=yellow> Version </th> < TH width=10%, BGcolor =yellow>API level </th> < TH width=10%, Bgcolor =yellow> Release date </th> < TH width=10%, bgcolor=yellow> version </th> < TH width=10%, Bgcolor = yellow > CodeName (system name) < / th > < / tr > < tr > < th > 1.0 < / th > < th > 1 < / th > < th > 2008-09-23 < / th > < th > astro boy < / th > < th > BASE < / th > < / tr > < tr > < th > 1.5 < / th > < th > 3 < / th > < th > 2009-04-17 < / th > < th > cupcakes < / th > < th > Cupcake < / th > < / tr > < tr > < th > 1.6 < / th > < th > 4 < / th > The < th > 2009-09-15 < / th > < th > doughnuts < / th > < th > Donut < / th > < / tr > < tr > < th > 2.0 < / th > < th > 5 < / th > < th > 2009-10-26 < / th > < th > puff < / th > The < th > Eclair < / th > < / tr > < tr > < th > 2.2 < / th > < th > 8 < / th > < th > 2010-05-20 < / th > < th > frozen yogurt < / th > < th > android < / th > < / tr > < tr > The < th > 2.3 < / th > < th > 9 < / th > < th > 2010-12-06 < / th > < th > Gingerbread < / th > < th > Gingerbread < / th > < / tr > < tr > < th > 3.0 < / th > < th > 11 < / th > The < th > 2011-02-24 < / th > < th > Honeycomb < / th > < th > Honeycomb < / th > < / tr > < th > 4.0 < / th > < th > 14 < / th > < th > 2011-10-19 < / th > < th > ice cream sandwich < / th > The < th > Ice Cream Sandwich < / th > < / tr > < th > 4.1 < / th > < th > 16 < / th > < th > 2012-06-28 < / th > < th > Jelly Bean < / th > < th > Jelly Bean < / th > < / tr > The < th > 4.4 < / th > < th > 19 < / th > < th > 2013-09-03 < / th > < th > kit kat < / th > < th > KitKat < / th > < / tr > < th > 5.0 < / th > < th > and < / th > The < th > 2014-10-15 < / th > < th > Lollipop < / th > < th > Lollipop < / th > < / tr > < th > 6.0 < / th > < th > 23 < / th > < th > 2015-05-28 < / th > < th > cotton candy < / th > The < th > Marshmallow < / th > < / tr > < th > 7.0 < / th > < th > 24 < / th > < th > 2016-05-18 < / th > < th > Nougat < / th > < th > Nougat < / th > < / tr > < th > 8.0 < / th > 26 the < th > < / th > < th > 2017-8-22 < / th > < th > Oreo < / th > < th > Oreo < / th > < / table >Copy the code
  • Let me shit, isn’t the Table used in this way, the screenshot above…

1.1.3 Features of Android Application development

  • Four major components

    • The Activity Activity
    • Service Service
    • BroadCast Receiver BroadCast Receiver
    • Content Provider Indicates the Content Provider
  • Rich system controls

  • SQLite database

  • Powerful multimedia

  • Geographic location

1.2 Take you hand in hand to build the development environment

To do a good job, he must sharpen his tools

1.2.1 Preparing Required Tools

  • JDK1.8 or above: Java language software development kit (including Java runtime environment, tool set, basic class library, etc.)
  • Android SDK: Android development kit
  • Android Studio: Android compiler

1.2.2 Setting up the development environment

  • Download AndroidStudio:
    • Website: https://developer.android.google.cn/studio/index.html
    • Developers: http://www.androiddevtools.cn/

The latest version is 3.0.1

1.3 Create your first Android project

Hello World

1.3.1 Creating the HelloWorld Project

1.3.2 Starting the emulator

1.3.3 run the HelloWorld

It took me most of the day to make things, and now I think of running in the sunset for a few minutes…

1.3.4 Analyze your first Android application

Directory structure under Project

  • .gradle and.idea: files automatically generated by Android Studio
  • App: Almost all the code and resources in the project are placed in the APP directory
    • Build: a file automatically generated during compilation
    • Libs: Place third-party JAR packages
    • AndroidTest: Write Android Test Test cases and automate project tests
    • Java: Places all Java code
    • Res: Project resource directory
    • Androidmanifest.xml: Android project configuration file
    • Test: Write Unit Test test cases and automate the project tests
    • .gitignore: controls the version to ignore files
    • App. iml: a file automatically generated by IntellJ IDEA
    • Build. gradle: Gradle build script for app module
    • Proguard-rules. pro: Specifies obfuscation rules for project code
  • Build: a file automatically generated when a project is compiled
  • Gradle: a configuration file containing gradle Wrapper. To use gradle Wrapper, you do not need to have Gradle wrapped in advance. Android Studio will automatically decide whether to download gradle from the Internet based on the cache. Gradle Wrapper is not enabled by default and configuration changes can be made through file-setting-build-execution-deployment-gradle
  • .gitignore: The specified directory or file is excluded from the version
  • Build. gradle: Gradle build scripts for your project globally
  • Gradle.properties: The global Gradle configuration file where the configured properties affect all gradle compilation scripts in the project
  • Gradlew and gradlew. Bat: Command line interface To execute gradle commands. Gradlew is used on Linux or Mac systems, gradlew is used on Windows systems
  • Helloworld.iml: A file automatically generated in all IntelliJ IDEA projects to identify this as an Intellij. IDEA project
  • Local. properties: Specifies the SDK path on the host, usually automatically generated
  • Setting. gradle: Specifies all imported modules in your project

1.3.5 Explain the resources in the project

  • Drawable stores images
  • Mipmap stores application ICONS
  • Value stores strings, styles, colors, and other configurations
  • Layout Stores layout files

1.3.6 Details about the build.gradle file

AndroidStudio uses Gradle to build projects

1. In the outermost directory :build.gradle

  • Jcenter: Code managed repository
    • Classpath: Gradle plugin version
      • The classpath ‘com. Android. Tools. Build: gradle: 3.0.1’
      • Because Gradle is not specifically developed for building android projects,Java and C++ can be built with Gradle

2. Build. Gradle in App directory

  • Apply plugin:

    • Com.android. application application module, which can be run directly
    • Com.android. library library module, can only be attached as a code library
  • Android closures (configure the various properties of the project build) :

    • CompileSdkVersion: Specifies the compiled version of the project
    • BulidToolsVersion: Used to specify the version of the build tool
    • DefaultConfig closure: Configure more details of the project
      • ApplicationId: Specifies the package name of the project
      • MinSdkVersion: Specifies the least compatible system version for the project
      • TargetSdkVersion: Fully tested on this target version, the system will enable some of the latest functions and features for your application
      • VersionCode: Specifies the version number of the project
      • VersionName: specifies the versionName of the project
    • BulidTypes closure: Specifies the configuration associated with generating installation files, usually with only two child closures
      • Debug: Specifies the configuration to generate the beta installation file, which can be ignored
      • Release: Specifies the configuration to generate the official version installation file
        • MinifyEnable: Specifies whether to obfuscate items
        • ProguardFiles: Specifies the rule files to use in obfuscation, two of which are specified here
          • Proguard-android. TXT is in the AndrliodSDK directory, which contains obturation rules common to all projects
          • Proguard-rules.pro is the root directory of the current project. Write the obfuscation rules specific to the current project. Note: Running the project directly from androidStudio will generate a beta installation file
  • Dependencies closure: Specifies all the dependencies of the current project

    • Compile fileTree Local dependencies: Add dependencies to local JAR packages or directories
      • implementation fileTree(include: [‘*.jar’], dir: ‘libs’)
      • All jar extensions in the lib directory are added to the project build path
    • Library dependencies: Add dependencies to library modules in your project
      • compile project(‘:helper’)
    • Remote dependencies: Add dependencies to open source projects on the JCenter library
      • Implementation ‘com. Android. Support: appcompat – v7:26.1.0’
      • Com.android. support domain name part: used to divide appcompat-v7 group names with other companies to distinguish different libraries of the same company

1.4 Prerequisites – Master the log tool

android.util.Log

1.4.1 Using the Android Log Tool Log

  • Log.v():verbose Indicates the minimum Log
  • Log.d():debug debugging information, which is one level higher than verbose
  • Log.i():info Indicates important information, one level higher than debug
  • Log.w():warm warning message, one level higher than info
  • Log.e():error Indicates the error information, which is one level higher than warm

1.4.2 Why Log is Used instead of Systom.out

  • Log: Controls the printing information, determines the printing time, adds filters, and identifies Log levels
  • System. Out does not satisfy

1.5 Summary and comments

Starting point for learning Android

This chapter summarizes

Looking back, I can’t tell the cause and effect of this chapter, such as the android system architecture /build.gradle file of each item related to the situation, usually do not pay attention to the development of it, but do not know why, take this time to make a good summary, in the later notes to write more of my own thinking, by comparison.

Disorderly punch killed the old master, with a state of mind to review the foundation. Two days ago I division I an Android development and architecture debate for the wool background Java interface encryption with MD5 not asymmetric encryption, architecture big guy directly asked: you know how to realize the MD5 encryption bottom, its bit length is how much… Suddenly speechless.. The choice of technology is not necessarily good or bad, but it is important to be prepared in advance when discussing it with others.