Android开发准备:

现在的 android 开发是越来越热门了,每个人都想找一些从头教到尾的教程,但是好像总会有一些不太合口味的样子,所以我就在这里把我从开始接触 android 开发的最基本开始,把我学到的都分享出来吧

 

一,Java 环境的准备:

 

Android 是基于 Linux 开发的,底层是用 C++语言实现的,应用层则是用 Java 语言实现的,所以android的开发环境必须的是 Java

 

先上 Java 的官网下载好配置 Java 开发环境用的 JDKJava Development Kit)配置开发环境

 

连接:http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html

 

Java SE Development Kit 8 Downloads Thank you for downloading this release of the JavaT" Platform, Standard Edition Development Kit The JOK is a development environment for building applications, applets, and components using the Java programming languaga The JOK includes tools useful for developing and testing programs written in the Java programming language and running on the Java platforrm See also: Java Developer From your Oracle account, select Subscriptions, expand Technolow, and subscribe to Java Java Developer Day hands-on workshops (free) and other events Java Magazine JOKBu111 Checksum JOKBu112 Checksum Java SE Development Kit 8u111 You must accept the Code License Agreement for to download this 64-blt 64-blt 73 MB 64-blt 64-blt software. O Accept License Agreement Product j File Description Linux ARM 32 Hard Float ABI Linux ARM 64 Hard Float ABI Linux x86 Linux x86 Linux *64 Linux *64 Mac OSX solans SPARC solans SPARC Solaris Solaris Windows x86 Windows File Size 777B MB 7473 MB 16ff35 MB 175114 MB 1 5835 MB 17304 MB 131 MB g3112 MB 14113B MB g&B2 MB idk- idk- idk- idk- idk- idk- idk- idk- idk- Bulli Bulli Bulli dk-Bu111 Bulli dk-Bu111 Bulli- Bulli- dk-Bu111- Bulli- dk-Bu111- Bulli- Bulli- Decline License Agreement Download -linux-arm32-»fp-hT1ttaraz -linux-arm64-»fp-hT1ttaraz -linux-i5B&rpm -linux-i5B&tar z -linux-x64xpm -linux-x64ftar z macosx-x64drna solaris-sparcvgnarz solaris-s arcvgnar z solaris-x64ftarZ solaris-x64ftar z windows-i5B&exe windows-x64Exe Java SE Development Kit 8u112 You must accept the Code License Agreement for to download this software. O Accept License Agreement Decline License Agreement Product j File Description Linux x86 Linux x86 Linux *64 Linux *64 Mac OSX solans SPARC solans SPARC Solaris Solaris Windows x86 Windows File Size 16242 MB 22315 141146 MB 1 Bagg MB lg513M8 idk- Bull dk-Bu112- idk- Bull dk-Bu112- idk- Bull idk- Bull dk-Bu112- idk- Bull dk-Bu112- idk- Bull idk- Bull Download linux-i5B&rpm linux-i5B&tar z linux-x64xpm linux-x64ftar z macosx-x64drna solaris-sparcvgnarz solaris-s arcvgnar z solaris-x64ftarZ solaris-x64ftar z windows-i5B&exe windows-x64Exe Java SE Development Kit 8u111 Demos and Samples Downloads You must accept the to download this software. O Accept License Agreement Decline License Agreement Product j File Description Linux ARM 32 Hard Float ABI File Size Download dk-Bu111-linux-arm32-»fp-hnt-demosftaraz

 

选择好自己的设备对应的版本的 JDK 按照默认的安装路径来安装即可

 

二,配置 Java 环境变量路径

 

右击我的电脑->属性->高级系统属性->高级->环境变量:

 

XXX 的用户变量中添加一个变量

名: JAVA_HOME

值为 刚才安装的 JDK 的路径(我的是默认安装路径)

JAVA HOME

 

 

完成以后再加一个变量(如果没有这个变量的话)

名:Path

值为:%JAVA_HOME%\bin;

 

如果已经有这个变量则直接在已有的变量的值后面加上 ;%JAVA_HOME%\bin;

 

Path

 

三,安装开发工具:

 

Android 的开发工具本来是有两个的,但是最近 Google 已经取消了对Eclipse 的支持,所以现在更推荐的是使用 Google 开发的 Android Studio (而且其实android studio是比eclipse 在许多方面优胜的)

 

下载:

首先上官网下载:

AndroidStudio 官网:https://developer.android.com/studio/index.html

0 Android Studio 专 Backto Developers DOWNLOAD FEATURES USERGUIDE FEATURES USERGUIDE Android Studio 官 方 Android IDE Android studi 。 供 用 于 为 各 类 Android 设 备 建 应 用 的 最 快 速 的 工 具 。 利 用 世 界 一 流 的 代 码 编 辑 、 调 试 、 性 能 工 具 、 一 套 灵 活 的 建 系 统 以 及 一 套 即 时 建 / 部 署 系 统 , 您 可 以 专 注 于 建 独 特 的 高 品 质 应 用 。 下 {iANDROIDSTUDIO 2 . 2 . 2.0 FORWINDOWS(164] MB) Search AKEAI-MINSURVE > 阅 读 文 档 参 阅 发 行 说 明 〉 功 能 〉 最 新 资 讯 〉 资 源 〉 视 频 〉 下 载 选 项 Instant Run 将 代 码 和 资 湃 吏 改 推 送 到 在 设 备 或 模 拟 器 上 运 行 的 应 用 中 0 上 您 可 以 立 刻 看 到 吏 改 的 实 际 效 果 。

 

Android Studio 中国官网:http://www.android-studio.org/

Android Studio CHINESE ANDROID : 188-00 Android Studio Bundle 2.2. 2.0 for Rindows Download http://Android.VPN.ac.cn ANOROIO STUDIO 2.2.2.O DOWNLOAD FROM OL.GOOGLE.COM Android Studio studio *dlDR01D STUDIO z z zo FOR wnmows (1641 w) Android Studio OCTOBER 19, 2016 Windows Mac OS X Linux 3360264—windows. exe äå h-.dxoid SDK (fr#) 1641 ME (1721650280 bytes) Android SDK Android SDK, 145. 145. 3360264—windows. exe 3360264—windows. zip 3360264—mac. ding 3360264—1 inux. zip 423 ME (444308960 445 ME (467098338 440 ME (461824413 445 ME bytes) bytes) bytes) SHA-I dB79e4bf8cd2530dfaacc7e176d72bb8dfd37b41 54c65afe143e87ef40decc720854a9c1f30417d3 27152fb1cc2b59c0110935c6bdeb2eaa58fa955f 2e89fed3601e5bd19112c29c172cb29be3b34f8e fc63ca247762697c33102a78063a95f8b5ab5dea

 

在官网上找到适合自己设备的 android studio 版本,然后下载安装即可

 

下载必须的 android 开发包(SDK

 

初次打开 AndroidStudio 的时候是

 

Android Studio Version 222 Start a new Android Studio project Open an existing Android Studio project Check out project from Version Control Import project (Eclipse ADT, Gradle, etc.) Import an Android code sample Configure Get Help

 

先不急着创建项目,首先打开 Configure->SDK Manager

 

Default Settings Appearance & Behavior Appea ra nce Menus and Toolbars System Settings Pa s sword s HTTP Proxy Updates Usage Statistics Android SDK Notifications Quick Lists Path Variables Keymap Editor Plugins Build, Execution, Deployment Tools Other Settings Appearance & Behavior System Settings Android SDK Manager for the Android SDK and Tools used by Android Studio Android SDK Location: SDK Platforms SDK Tools SDK L] pdate Sites Each Android SDK Platform package includes the Android platform and sources pertaining to an API level by default. Once installed, Android Studio will automatically check for updates. Check "show Edit Status package details" to display individual SDK components. Name Android 7.0 (Nougat) Android N Preview Android 6.0 (Marshmallow) Android 5.1 (Lollipop) Android 5.0 (Lollipop) Android 4.4W (KitKat Wear) Android 4.4 (KitKat) Android 4.3 (Jelly Bean) Android 4.2 (Jelly Bean) Android 4.1 (Jelly Bean) Android 40.3 (IceCreamSandwich) Android 4.0 (IceCreamSandwich) Android 3.2 (Honeycomb) Android 3.1 (Honeycomb) Android 3.0 (Honeycomb) Android 23.3 (Gingerbread) Android 2.3 (Gingerbread) Android 2.2 (Froyo) Android 2.1 (Eclair) Launch Standalone SDK Manager API Level Revision Installed Partially installed Update available Update available Update available Installed Installed Installed Installed Installed Installed Installed Not installed Not installed Not installed Not installed Not installed Not installed Not installed Show Package Details Ca ncel Help

 

比较推荐下载安装Android7.05.04.34.0.32.3 版本的开发包和相应的虚拟机。

 

勾选完你需要下载的 SDK 以后就可以点击 Apply 并下载安装。

 

四,新建项目

 

既然准备工作都已经做好了,这时候可以开始开发了,那么,如何新建一个项目呢?

 

1,点击 Start a newAndroid Studio project

 

Android Studio Version 222 Start a new Android Studio project Open an existing Android Studio project Check out project from Version Control Import project (Eclipse ADT, Gradle, etc.) Import an Android code sample Configure Get Help

 

 

2,填写基本的 项目信息

 

Create New Project New Project Android Studio Configure your new project Application name: Company Domain: Package name: Project location: My Application oufenghua.example.com com.example.oufenghua.myapplication Include C++ Support E: \ Prog ra mmi ng \And mid Stud ioProject\Action8a rCompat-Ba sic\MyAppl ication2 Previous Ca ncel

 

Application name:(随便你喜欢)项目名字

Project location:(你喜欢存放项目的位置)

 

*Include C++ Support 这个选项当你想要写底层的时候再勾选

 

下一步。

 

3,选择你的应用适配到的最低版本

 

 

Create New Project Target Android Devices Select the form factors your app will run on Different platforms may require separate SDKs Phone and Tablet Minimum SDK Wea r Minimum SDK Minimum SDK Android Auto Glass Minimum SDK API 15: Android 40.3 (IceCreamSandwich) Lower API levels target more devices, but have fewer features available. By targeting API 15 and later, your app will run on approximately 97.4% of the devices that are active on the Google Play Store. Help me choose API 21: Android 5.0 (Lollipop) API 21: Android 5.0 (Lollipop) Glass Development Kit Preview (API 19) Previo us Ca ncel

 

目前的 android 手机已经普遍使用到了 Android4.0或以上的系统了,所以最低可以只兼容到4.0.3了(老实说,之前做兼容到2.0.3 app 的时候真心累,很多不兼容的情况)

 

下一步。

 

4,选择一个初始新建页面样式:

 

Create New Project Add an Activity to Mobile Add No Activity Google Maps Activity Ba sic Activity Log i n Activity Empty Acti Master/Detail Flow Fullscreen Activity Navigation Drawer Activity Previou s Google Ad Mob Ads Activity Scrolling Activity Ca ncel

 

选择别的页面可以快捷地生成一些页面效果,但是初学者的话并不推荐,推荐的还是使用 Empty Actvity

 

5,最后一步决定 Activity xml 文件和 Java 源文件的名字

 

Create New Project Customize the Activity Creates a new empty activity Activity Name: Layout Name: E mpty Activity M a i nActivity Generate Layout File activity main Backwards Compatibility (AppCompat) The name of the activity class to create Previo us Ca ncel Finish

 

自定义名字以后按 finish 即可成功新建好项目

 

五,一些必须要会的基本操作:

 

1,创建虚拟机(CPU 需要是 Intel 的):

 

- Studio 2.2.2 Eile Edit yiew Navigate Code Analyze Refactor Build Run MyApplication2 Gapp main Ejava Z com Android Project Files Problems O 1001s VCS Window Help example oufenghua myapplication MainActivity 2 app manifests com.example.oufenghua.myapplication MainActivity com.example.oufenghua.myapplication (android Test) com.example.oufenghua.myapplication (test) Gradle Scripts activity_ma i n. x ml Mai nActivityjava x package com.example.oufenghua.myapplication; import . public class MainActivity extends AppCompatActivity { @Override protected void onCreate (Bundle savedInstanceState) { super. onCreate (savedInstanceState) ; setContentView(R. layout. activi ty_matn) ; Terminal Android Monitor Q: Messages [3 Gradle build finished in IIS 63ms (yesterday 20:59) TODO CRLF: •1 a.'ent Log Gradle Console UT F -8: Context: < no context >

 

注意到这个 android 手机的小图标,这个就是虚拟机

 

Your Virtual Devices Android Studio AVD Manager Virtual devices allow you to test your application without having to cwn the physical devices. Create a virtual device To prioritize which devices to test your application on, visit the Android Dashboards, where you can get up-to-date information on which devices are active in the Android and Google Play ecosystem.

 

点击进去它会提醒你没有任何的虚拟机器(第一次使用的时候),点击创建一个虚拟机 Create a virtual device

 

Virtual Device Configuration Select Hardware Android Studio Choose a device definition Category Wea r Phone Tablet Name Nexus S Nexus One Nexus 6? Nexus 6 Nexus 5X Nexus 5 Nexus 4 Galaxy Nexus 5.4' PUVGA 5.1' WVGA 4.7" WXGA Size 4.95' 4.65' Resolution 14400560 14400560 1080x1920 1080x1920 768x1280 720x1280 480x854 720x1280 Density hdpi hdpi 5608 pi 5608 pi 4208 pi xxhdpi xhdpi xhdpi me pi me pi xhdpi Nexus 5 losogx New Hardware Profile Import Hardware Profiles Previous 1S20px Ca ncel Size: normal Ratio: long Density: 420dpi Clone Devicem Help

 

点击进去以后会让你选择你想使用的虚拟机外观,不同型号的虚拟机就跟各个对应的不同的手机一样,屏幕分辨率和外观都各不相同,然后点击 Next

 

Virtual Device Configuration System Image Android Studio Select a system image Recommended x86 Images Other I mages Release Name Nougat Nougat Cmvnload Marshmallow arshmallow Lollipop Lollipop Lollipop Lompop Down load Lollipop Lollipop KitKai Cmvnload KitKai Cmvnload Jeffy Bean Cmvnload Jeffy Bean Cmvnload API Level • x86 64 x86 64 x86 64 x86 64 x86 64 x86 64 Ta rget Android 7.0 Android 7.0 Android 7.0 Android 6.0 Android 6.0 Android 5.1 Android 5.1 Android 5.0 (with Google APIs) Android 5.0 (with Google APIs) Android 5.0 Android 5.0 Android 44 (with Google APIs) "droid 4.4 Android 43 (with Google APIs) Android 4.3 'I Previou s Marshmallow API 23 6.0 Android Open Source Project x86 Recommendation Consider using a system image with Google APIs to enable testing with Google Play Services. Questions on API level? See the API level distribution chart Ca ncel Help

 

然后是选择 android 虚拟机版本,选择你喜欢的 android 版本(当然,前提是你刚才再SDK的步骤里面就已经下载好的,没下载好的版本的名字后面会有一个蓝色的 Download 字样),然后镜像的选择框上标分为三类:Recommend(推荐镜像) x86 Imagesx86 镜像) Other Images(其他镜像) Recommend 的镜像是 Google 推荐使用的,x86 Images 是最流畅的镜像(Recommend 的也是使用 x86 Images 的),Other Images 是比较没那么流畅的镜像(不推荐)。我比较推荐使用的是 ABI 下写着 x86_64 的镜像,亲测,基本上卡顿情况是没有的。选好以后按 Next

 

Virtual Device Configuration Android Virtual Device (AVD) Android Studio Verify Configuration AVD Name Nexus 5 API 25 Nexus 5 Nougat Startup orientation Portra it 4.95 1080x1920 420dpi Android 7.1.1 x86 64 La nd sca pe Emulated Perfor ma nce Device Fra me Graphics: Enable Device Frame Auto ma tic Show Advanced Settings AVD Name Change... The name of this AVC). Change... Previou s Ca ncel Finish Help

 

AVD Name:你的虚拟机的名字

其他的话其实默认就好,不过有一其他的要求的话可以点击 ShowAdvanced Settings

 

Virtual Device Configuration Android Virtual Device (AVD) Android Studio Verify Configuration Network Speed: La tency: Emulated Perfor ma nce M emory Storage Full None Graphics: Automatic Multi-Core CPL] 4 1536 VM heap: Internal Storage: SD card: (Experimenta l) 100 Device Frame Ena ble Device Fra me Custom skin definition Studio-managed External file nexus 5 Keyboa rd How do I create a custom hardware skin? Enable keyboard input Hide Advanced Settings Previou s Nothing Selected Ca ncel Finish Help

 

可以看到多了很多选项,要修改的话推荐的有:

Memory RAM 运行内存的大小分配(最好就是限制在你电脑内存的1/4以下)

Internal Storage :内部储存大小,4G以下自由分配(其实也是看你存放VM的硬盘的大小,一般在C盘)

SD card:外部储存卡的大小,可以选择使用 Studio 自己的,也可以自己另外定一个目录(虚拟的)

 

在你修改完你喜欢的设置以后点击 Finish,你再打开虚拟机图标的时候就多了一台属于你的虚拟机了。

 

Android Virtual Device Manager Type Your Virtual Devices Android Studio Na me Nexus 5X API 23 Nexus 6 Create Virtual Devicem Ta rget Android 6.0 (Google APIs) Android 7.0 CPU/A81 x86 64 Size on Disk Actio ns 1080 x 1920: 1440 x 2560: Resolution 4208 pi 5608 pi

 

随后点击你要打开的虚拟机的绿色的播放图标即可运行你的虚拟机

 

Android Emulator - Nexus 5X API 23:5554 Google Google 3:16 Play Games

 

2,添加外部依赖包:

 

很多时候要做一些很炫的效果只是用SDK 自带的 support.v7 包是不够的,还需要引进一些其他的包,例如联网操作用的 Volley

 

MyApplication2 - - [app] - Eile Edit yiew Navigate Code Analyze Refactor Build Run 1001s VCS Window Help MainActivity MYApplication2 5 app src main t java Z com example oufenghua myapplication - Android Studio 2.22 2 Android Project Files Problems O app manifests com.example.oufenghua.myapplication com.example.oufenghua.myapplication (android Test) com.example.oufenghua.myapplication (test) Gradle Scripts AVD: Nexus 5X API 23 emulator: WARNING: Crash service did not start Hax is enabled Hax ram size Ox60000000 is working and emulator runs in fast virt mode. audio: Failed to create voice activity_main.xmlx MainActivityjava x package com.example.oufenghua.myapplication; import . public class MainActivity extends AppCompatActivity { @Override protected void onCreate (Bundle savedInstanceState) { super. onCreate (savedInstanceState) ; setContentView(R. layout. activi ty_matn) ; Run qemu—system—i386. exe: warning: opening audio input failed emulator: Listening for console connections on port: 5554 emulator: Serial number of this emulator (for ADB) : emulator—5554 emulator: WARNING: . / cpp : 189: Can' t upload usage metrics: Err or Terminal Android Monitor Q: Messages [3 Gradle build finished in IIS 63ms (yesterday 20:59) 4: Run TODO 11:1 CRLF: •1 a.'ent Log Gradle Console UT F-8: Context: < no context >

 

点击依赖包库

 

Project Structure Project Developer Servicm Ad s Authentication Notifications Modules app SDK Location Android SDK location: The directory where the Android SDK is located. This location will be used for new projects, and for existing projects that do not have a local.properties file with a sdk.dir property. E rid roid _stud rid roid _stud rid roid _stud rid roid _stud io_SDK JDK location: The directory where the Java Development Kit (JDK) is located. use embedded JOK (recommended) Filesuava\jdkl .8.0 60 Android NDK location: The directory where the Android NOK is located. This location will be saved as ndk.dir property in the local.properties file. Cmvvnload Android NDK. Ca ncel

 

点击 app->Dependencies

 

Project Structur SDK Location P roject Developer Servicm Ad s Authentication Notifications Modules Properties Signing Flavors {inc dir=libs) Build Types Dependencies Sco pe Compile ex' Compile Test compile Ca ncel

 

点击加号按钮

 

Project Structure SDK Location P roject Developer Servicm Ad s Authentication Notifications Modules Properties Signing Flavors {inc dir=libs) Build Types Dependencies Sco pe Compile ex' Compile Test compile Ca ncel

 

File dependency Module dependency

 

选择 Library dependency 会出现一个搜索框

 

Choose Library Dependency Enter terms for Maven Central search, or fully-qualified coordinates com.android.support:support-annotations com.android.support:support-v4 com.android.support:support-v13 com.android.support:appcompat-v7 com.android.support:support-vector-drawable com.android.support:design com.android.support:gridlayout-v7 com.android.support:mediarouter-v7 Ca ncel

 

输入你的项目要依赖的包名(以 Volley 为例)

 

Choose Library Depende eu.the4thfloorvolley:com.a rid mid ley:201 5.05.28 Enter terms for Maven Central search, or fully-qualified coordinates me.neavo:volley com.dubsmash.volley:library com.navercorp.volleyextensions:volley-views com.navercorp.volleyextensions:volley-requests com.navercorp.volleyextensions:volley-caches com.navercorp.volleyextensions:volley-extensions-common-utils (com.navercorp.volleyextensions:volley-extensi... com.github.bumptech.glide:volley-integration Ca ncel

 

选择你想使用的版本任何点击ok

 

Project Structure SDK Location P roject Developer Servicm Ad s Authentication Notifications Modules Properties Signing Flavors dir=libs) Build Types Dependencies Scope Compile nd roidTestCompile('com.and , m euthe4thfloor.volley:com.android volley:2015.0528 Compile Compile Compile Ca ncel

 

你会发现你的依赖库就会多了这个依赖包,然后点击确定,等 Android Studio 帮你建立这个依赖就好了,你就可以使用这个依赖包中的东西了

 

3,运行项目:

 

运行项目其实很简单,当你确认你的项目没有任何错误以后点击运行项目的按钮

 

MyApplication2 - - [app] - Eile Edit yiew Navigate Code Analyze Refactor Build Run 1001s VCS Window Help MainActivity MYApplication2 5 app src main t java Z com example oufenghua myapplication - Android Studio 2.22 2 Android Project Files Problems O app manifests com.example.oufenghua.myapplication com.example.oufenghua.myapplication (android Test) com.example.oufenghua.myapplication (test) Gradle Scripts AVD: Nexus 5X API 23 emulator: WARNING: Crash service did not start Hax is enabled Hax ram size Ox60000000 is working and emulator runs in fast virt mode. audio: Failed to create voice activity_main.xmlx MainActivityjava x package com.example.oufenghua.myapplication; import . public class MainActivity extends AppCompatActivity { @Override protected void onCreate (Bundle savedInstanceState) { super. onCreate (savedInstanceState) ; setContentView(R. layout. activi ty_matn) ; Run qemu—system—i386. exe: warning: opening audio input failed emulator: Listening for console connections on port: 5554 emulator: Serial number of this emulator (for ADB) : emulator—5554 emulator: WARNING: . / cpp : 189: Can' t upload usage metrics: Err or Terminal Android Monitor Q: Messages [3 Gradle build finished in IIS 63ms (yesterday 20:59) 4: Run TODO 11:1 CRLF: •1 a.'ent Log Gradle Console UT F-8: Context: < no context > CD

 

选择虚拟机或着是你已经连接了的设备(上面的是已连接的设备或正在运行的虚拟机,下面的是你所有的虚拟机)

 

Select Deployment Targ Connected Devices Available Virtual Devices Nexus 6 Create New Virtual Device use same selection for future launches Don't see your device? Ca ncel

 

点击 ok 以后,你的 app 就会在你的选择的设备中运行了

 

计算机生成了可选文字:Android Emulator _ Nexus 5X API 2 555 My Application H 0 World! O , 3 : 54 g: 0 / lib 86 1 C 5 .

 

关于 Android 开发的基本准备和 Android Studio 的基本介绍就到这里了,欢迎各位读者的提问或纠正。

  • 4
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值