Chinaunix首页 | 论坛 | 博客
  • 博客访问: 78685
  • 博文数量: 24
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 161
  • 用 户 组: 普通用户
  • 注册时间: 2015-01-04 17:48
文章分类

全部博文(24)

文章存档

2015年(24)

我的朋友

分类: Android平台

2015-08-09 15:25:50

对于 Android 开发的朋友来说,首先要做的就是配置开发环境,目前官方提供的 IDE 是 AndroidStudio,不过个人还是习惯于 Eclipse。由于国内的网络环境原因,通过官方的 SDK Manager 的下载速度一般很慢,因此采用离线下载比较简单。简单来说就是先把安装需要的压缩包通过迅雷等 P2P 软件下载到本地,然后再配置改动一些参数来本地安装。但是一般方法费时费力,主要是因为网上贴出来的下载网盘链接或者官方下载地址总在不断更新,不具有时效性。这篇文章对 Android SDK 的下载和配置进行了分析,提供了有效获取离线 SDK 的方式。

原理概述

本文主要对 SDK Manager 如何解析 xml 进行分析,得到对应的文件下载地址,以及下载到本地后如何配置参数来完成 Android SDK 的安装。这种方法既不提供实时的下载地址和分享链接,又不会因为 SDK 地址更新失效,关键是分析弄清楚 SDK Manager 的工作原理。Android SDK 主要通过 Android SDK Manager 来管理,而这个 Manager 管理资源主要包括

Tools

这部分主要有下列三个工具:



  • Android SDK Tools
  • Android SDK Platform-tools
  • Android SDK Build-tools



Platform

这部分就包括对应不同 Android 版本的平台库,示例文件和 google 官方的 API 接口文件,以及对应版本的源码:



  • SDK Platform
  • Samples for SDK
  • Google APIs
  • Sources for Android SDK (始于 API 14,也即是 Android 4.0 之后的版本才有源码可以通过 Manager 下载管理)



Extras

以下的额外文件有些是必须的开发库,比如 Support Library 等,其他的主要是集成 google 的一些资源,比如应用商店 google play 等,各个文件的作用就不作介绍了,一般都能搜到相关资料。



  • Android Support Library
  • Android Support Repository
  • Google Repository
  • Google Play Licensing Library
  • Google Play APK Expansion Library
  • Google Play services for Froyo
  • Google Play services
  • Google USB Driver
  • Google Play Billing Library
  • Google AdMob Ads SDK
  • Google Analytics App Tracking SDK
  • Google Web Driver
  • Google Cloud Messaging for Android Library
  • Android Auto API Simulators



具体操作

首先得先在 Eclipse 中把插件 ADT 装好,不过在 2013 年时候 Android 官网已经提供集成 ADT 的 Eclipse 下载, 最新官方版本已经更改为 Android Studio 了,但是都使用 Android SDK Manager 来管理。因此第一步安装 ADT 工作基本可以略过了(如果确实不会装,请自行查资料解决,不在本文讨论范围内),后续操作都是在已经安装好 SDK Manager 的前提下进行的。

Load XML 文件

打开 Manager 就可以看到底下状态栏显示 Parsing XML 和 Fetching 一些 XML 文件了,通过 manager Log 也可以看到爬取记录,如下图:

解析到的的 XML 文件就是 repository-10.xml,addons_list-2.xml,addon-6.xml,addon.xml。最重要是 repository-10.xml 和 addon.xml 这两个,前者包含了平台资源文件的下载地址,后者则主要是前面介绍的 Extras 内容地址。所以,只需要打开 log 窗口,然后复制出这两个 XML 文件的地址(比如本文写作时的地址是),将其复制到浏览器打开保存或者直接用下载软件下载就可以了。

解析资源地址

通过上一步得到了 repository-10.xml 和 addon.xml,接下来就是对应分析 XML 中的地址了,其实这两个 XML 打开后稍微分析下就可以发现规律了,如下所示可以在 repository-10.xml 文件中搜索每一行后面的 跳到对应位置提取地址。

必须安装的 TOOL 资源:



  • Tools 
    Android SDK Tools
  • Platform-tools 
    Android SDK Platform-tools
  • Build-tools 
    Android SDK Build-tools



对于每一个 API level :



  • Platform 
    SDK Platform
  • Samples 
    Samples for SDK
  • Sources 
    Sources for Android SDK
    在 addon.xml 文件中搜索 跳到对应位置提取 Google APIs 地址。
  • Google APIs



在 addon.xml 文件中搜索以下关键词定位到 Extras 类别的下载地址位置



  • Extras
    Android Support Library
    Android Support Repository
    Google Repository
    Google Play Licensing Library
    Google Play APK Expansion Library
    Google Play services for Froyo
    Google Play services
    Google USB Driver
    Google Play Billing Library
    Google AdMob Ads SDK
    Google Analytics App Tracking SDK
    Google Web Driver
    Google Cloud Messaging for Android Library
    Android Auto API Simulators



提取 SDK 下载地址

推荐下载 API Level 为 10、14、15、16、17、19 的 SDK,截至本文写作时的地址为:

/> />

/> /> /> /> />

/> /> /> /> />

/> /> /> /> />

/> /> /> />

/> /> /> /> /> /> /> /> /> /> /> /> />

安装配置

通过迅雷等软件直接下载到本地后都是压缩包,如图:

下一步就是找到 SDK Manager 的目录,打开 sdk 文件夹后,主要含有如下文件夹:



  • add-ons
  • build-tools
  • extras
  • platforms
  • platform-tools
  • samples
  • sources
  • temp
  • tools



add-ons

对于 add-ons 文件夹,需要将 google_apis-10_r02.zip(其他 API Level 类似)解压进去,并重命名为 addon-google_apis-google-10,然后进入目录,新建 source.properties 文件,写入如下内容:


点击(此处)折叠或打开

  1. ### Android Tool:Source of this archive.
  2. #Sun Sep 14 14:03:53 CST 2014
  3. Addon.NameDisplay=Google APIs
  4. Addon.NameId=google_apis
  5. Addon.VendorDisplay=Google Inc.
  6. Addon.VendorId=google
  7. AndroidVersion.ApiLevel=10
  8. Pkg.Desc=Android+Google APIs,API 10,revision 2
  9. Pkg.DescUrl=http\://developer.android.com/
  10. Pkg.License=Togetstarted with the Android SDK,you must agree to the following terms and conditions.\n\nThis is the Android SDK License Agreement (the"License Agreement").\n\n1. Introduction\n\n1.1 The Android SDK (referred to in the License Agreement as the"SDK"and specifically including the Android systemfiles,packaged APIs,and SDK libraryfilesand tools,if and when they are made available) is licensed to you subject to the terms of the License Agreement. The License Agreement forms a legally binding contract between you and Google in relation to your use of the SDK.\n\n1.2"Android"means the Android software stack for devices,as made available under the Android Open Source Project,which is located at the following URL\:http\://source.android.com/,as updatedfromtime to time.\n\n1.3"Google"means Google Inc.,a Delaware corporation with principal place of business at 1600 Amphitheatre Parkway,Mountain View,CA94043,United States.\n\n2. Accepting the License Agreement\n\n2.1 Inorderto use the SDK,you must first agree to the License Agreement. You may not use the SDK if you do not accept the License Agreement.\n\n2.2 By clicking to accept and/or using the SDK,you hereby agree to the terms of the License Agreement.\n\n2.3 You may not use the SDK and may not accept the License Agreement if you are a person barredfromreceiving the SDK under the laws of the United States or other countries including the country in which you are resident orfromwhich you use the SDK.\n\n2.4 If you will use the SDK internally within your company or organization you agree to be bound by the License Agreementonbehalf of your employer or other entity,and you represent and warrant that you havefulllegal authority to bind your employer or such entity to the License Agreement. If you do not have the requisite authority,you may not accept the License Agreement or use the SDKonbehalf of your employer or other entity.\n\n3. SDK LicensefromGoogle\n\n3.1 Subject to the terms of the License Agreement,Google grants you a royalty-free,non-assignable,non-exclusive,non-sublicensable,limited,revocable license to use the SDK,personally or internally within your company or organization,solely to develop and distribute applications to runonthe Android platform.\n\n3.2 You agree that Google or third parties ownalllegal right,title and interest in and to the SDK,including any Intellectual Property Rights that subsist in the SDK."Intellectual Property Rights"means any andallrights under patent law,copyright law,trade secret law,trademark law,and any andallother proprietary rights. Google reservesallrights not expressly granted to you.\n\n3.3 You may not use the SDK for any purpose not expressly permitted by the License Agreement. Except to the extent required by applicable third party licenses,you may not\:(a) copy (except for backup purposes),modify,adapt,redistribute,decompile,reverse engineer,disassemble,or create derivative works of the SDK or any part of the SDK; or (b) load any part of the SDK onto a mobile handset or any other hardware device except a personal computer,combine any part of the SDK with other software,or distribute any software or device incorporating a part of the SDK.\n\n3.4 You agree that you will not take any actions that may cause or result in the fragmentation of Android,including but not limited to distributing,participating in the creation of,or promoting in any way a software development kit derivedfromthe SDK.\n\n3.5 Use,reproduction and distribution of components of the SDK licensed under an open source software license are governed solely by the terms of that open source software license and not the License Agreement. You agree to remain a licensee in good standing in regard to such open source software licenses underallthe rights granted and to refrainfromany actions that may terminate,suspend,or breach such rights.\n\n3.6 You agree that the form and nature of the SDK that Google provides may change without priornoticeto you and that future versions of the SDK may be incompatible with applications developedonprevious versions of the SDK. You agree that Google may stop (permanently or temporarily) providing the SDK (or any features within the SDK) to you or to users generally at Google's sole discretion,without priornoticeto you.\n\n3.7 Nothing in the License Agreement gives you a right to use any of Google's trade names,trademarks,service marks,logos,domain names,or other distinctive brand features.\n\n3.8 You agree that you will not remove,obscure,or alter any proprietary rights notices (including copyright and trademark notices) that may be affixed to or contained within the SDK.\n\n4. Use of the SDK by You\n\n4.1 Google agrees that nothing in the License Agreement gives Google any right,title or interestfromyou (or your licensors) under the License Agreement in or to any software applications that you develop using the SDK,including any intellectual property rights that subsist in those applications.\n\n4.2 You agree to use the SDK and write applications only for purposes that are permitted by (a) the License Agreement,and (b) any applicable law,regulation or generally accepted practices or guidelines in the relevant jurisdictions (including any laws regarding the export of data or software to andfromthe United States or other relevant countries).\n\n4.3 You agree that if you use the SDK to develop applications,you will protect the privacy and legal rights of users. If users provide you withusernames,passwords,or other login information or personal information,you must make the users aware that the information will be available to your application,and you must provide legally adequate privacynoticeand protection for those users. If your application stores personal or sensitive information provided by users,itmust do so securely. If users provide you with Google Account information,your application may only use that information to access theuser's Google Account when,and for the limited purposes for which,eachuserhas given you permission to do so.\n\n4.4 You agree that you will not engage in any activity with the SDK,including the development or distribution of an application,that interferes with,disrupts,damages,or accesses in an unauthorized manner the servers,networks,or other properties or services of Google or any third party.\n\n4.5 You agree that you are solely responsible for (and that Google hasnoresponsibility to you or to any third party for) any data,content,or resources that you create,transmit or display through Android and/or applications for Android,and for the consequences of your actions (including any loss or damage which Google may suffer) by doing so.\n\n4.6 You agree that you are solely responsible for (and that Google hasnoresponsibility to you or to any third party for) any breach of your obligations under the License Agreement,any applicable third party contract or Terms of Service,or any applicable law or regulation,and for the consequences (including any loss or damage which Google or any third party may suffer) of any such breach.\n\n5. Your Developer Credentials\n\n5.1 You agree that you are responsible for maintaining the confidentiality of any developer credentials that may be issued to you by Google or which you may choose yourself and that you will be solely responsible forallapplications that are developed under your developer credentials.\n\n6. Privacy and Information\n\n6.1 Inorderto continually innovate and improve the SDK,Google may collect certain usage statisticsfromthe software including but not limited to a unique identifier,associated IP address,version number of the software,and informationonwhich tools and/or services in the SDK are being used and how they are being used. Before any of this information is collected,the SDK will notify you and seek your consent. If you withhold consent,the information will not be collected.\n\n6.2 The data collected is examined in the aggregate to improve the SDK and is maintained in accordance with Google's Privacy Policy located at http\://www.google.com/policies/privacy/.\n\n7. Third Party Applications\n\n7.1 If you use the SDK to run applications developed by a third party or that access data,content or resources provided by a third party,you agree that Google is not responsible for those applications,data,content,or resources. You understand thatalldata,content or resources which you may access through such third party applications are the sole responsibility of the personfromwhich they originated and that Google is not liable for any loss or damage that you may experience as a result of the use or access of any of those third party applications,data,content,or resources.\n\n7.2 You should be aware the data,content,and resources presented to you through such a third party application may be protected by intellectual property rights which are owned by the providers (or by other persons or companiesontheir behalf). You may not modify,rent,lease,loan,sell,distribute or create derivative works basedonthese data,content,or resources (either in whole or in part) unless you have been specifically given permission to do so by the relevant owners.\n\n7.3 You acknowledge that your use of such third party applications,data,content,or resources may be subject to separate terms between you and the relevant third party.\n\n8. Using Google APIs\n\n8.1 Google APIs\n\n8.1.1 If you use any API to retrieve datafromGoogle,you acknowledge that the data may be protected by intellectual property rights which are owned by Google or those parties that provide the data (or by other persons or companiesontheir behalf). Your use of any such API may be subject to additional Terms of Service. You may not modify,rent,lease,loan,sell,distribute or create derivative works basedonthis data (either in whole or in part) unless allowed by the relevant Terms of Service.\n\n8.1.2 If you use any API to retrieve auser's datafromGoogle,you acknowledge and agree that you shall retrieve data only with theuser's explicit consent and only when,and for the limited purposes for which,theuserhas given you permission to do so.\n\n9. Terminating the License Agreement\n\n9.1 The License Agreement will continue to apply until terminated by either you or Google as set out below.\n\n9.2 If you want to terminate the License Agreement,you may do so by ceasing your use of the SDK and any relevant developer credentials.\n\n9.3 Google may at any time,terminate the License Agreement,with or without cause,uponnoticeto you.\n\n9.4 The License Agreement will automatically terminate withoutnoticeor otheractionwhen Google ceases to provide the SDK or certain parts of the SDK to users in the country in which you are resident orfromwhich you use the service.\n\n9.5 When the License Agreement is terminated,the license granted to you in the License Agreement will terminate,you will immediately ceasealluse of the SDK,and the provisions of paragraphs 10,11,12 and 14 shall survive indefinitely.\n\n10. DISCLAIMERS\n\n10.1 YOU EXPRESSLY UNDERSTAND AND AGREE THAT YOUR USE OF THE SDK IS AT YOUR SOLE RISK AND THAT THE SDK IS PROVIDED"AS IS"AND"AS AVAILABLE"WITHOUT WARRANTY OF ANY KINDFROMGOOGLE.\n\n10.2 YOUR USE OF THE SDK AND ANY MATERIAL DOWNLOADED OR OTHERWISE OBTAINED THROUGH THE USE OF THE SDK IS AT YOUR OWN DISCRETION AND RISK AND YOU ARE SOLELY RESPONSIBLE FOR ANY DAMAGE TO YOUR COMPUTER SYSTEM OR OTHER DEVICE OR LOSS OF DATA THAT RESULTSFROMSUCH USE. WITHOUT LIMITING THE FOREGOING,YOU UNDERSTAND THAT THE SDK MAY CONTAIN ERRORS,DEFECTS AND SECURITY VULNERABILITIES THAT CAN RESULT IN SIGNIFICANT DAMAGE,INCLUDING THE COMPLETE,IRRECOVERABLE LOSS OF USE OF YOUR COMPUTER SYSTEM OR OTHER DEVICE.\n\n10.3 GOOGLE FURTHER EXPRESSLY DISCLAIMSALLWARRANTIES AND CONDITIONS OF ANY KIND,WHETHER EXPRESS OR IMPLIED,INCLUDING,BUT NOT LIMITED TO THE IMPLIED WARRANTIES AND CONDITIONS OF MERCHANTABILITY,FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.\n\n11. LIMITATION OF LIABILITY\n\n11.1 YOU EXPRESSLY UNDERSTAND AND AGREE THAT GOOGLE,ITS SUBSIDIARIES AND AFFILIATES,AND ITS LICENSORS SHALL NOT BE LIABLE TO YOU UNDER ANY THEORY OF LIABILITY FOR ANY DIRECT,INDIRECT,INCIDENTAL,SPECIAL,CONSEQUENTIAL OR EXEMPLARY DAMAGES THAT MAY BE INCURRED BY YOU,INCLUDING ANY LOSS OF DATA,WHETHER OR NOT GOOGLE OR ITS REPRESENTATIVES HAVE BEEN ADVISED OF OR SHOULD HAVE BEEN AWARE OF THE POSSIBILITY OF ANY SUCH LOSSES ARISING.\n\n12. Indemnification\n\n12.1 To the maximum extent permitted by law,you agree to defend,indemnify and hold harmless Google,its affiliates and their respective directors,officers,employees and agentsfromand against any andallclaims,actions,suits or proceedings,as well as any andalllosses,liabilities,damages,costs and expenses (including reasonable attorneys\u2019 fees) arising out of or accruingfrom(a) your use of the SDK,(b) any application you developonthe SDK that infringes any Intellectual Property Rights of any person or defames any person or violates their rights of publicity or privacy,and (c) any non-compliance by you of the License Agreement.\n\n13. Changes to the License Agreement\n\n13.1 Google may make changes to the License Agreement asitdistributes new versions of the SDK. When these changes are made,Google will make a new version of the License Agreement availableonthe website where the SDK is made available.\n\n14. General Legal Terms\n\n14.1 The License Agreement constitutes the whole legal agreement between you and Google and governs your use of the SDK (excluding any services which Google may provide to you under a separate written agreement),and completely replaces any prior agreements between you and Google in relation to the SDK.\n\n14.2 You agree that if Google does not exercise or enforce any legal right or remedy which is contained in the License Agreement (or which Google has the benefit of under any applicable law),this will not be taken to be a formal waiver of Google


其他 API 版本,则需要改动上述代码中的对应数字和 Revision 号,即


点击(此处)折叠或打开

  1. AndroidVersion.ApiLevel=10
  2. Pkg.Desc=Android + Google APIs, API 10, revision 2
  3. Pkg.Revision=2


这三行中数字,比如将 10 改为 14、15、17、19,revision 后的 2 改为对应的 1、2 者 3 等,具体信息解压缩后的文件夹名称可以体现出来,google_apis-10_r02 则说明 API Level 为 10,Revision 号为 2。

build-tools

解压后重命名为版本号即可,如压缩包名称为 build-tools_r21.1.2-windows.zip,解压后重命名文件夹为 21.1.2 放进 build-tools 文件夹即可。

extras

extras 文件夹下主要为 android 和 google 这两个文件夹,将前面 Extras 列表下的 Google 开头文件对应压缩包解压后放在 google 文件夹里,Android 开头的压缩包则解压缩后放进 android 文件夹。

platforms

直接将对应的 android SDK 版本解压后放进去即可,比如 android-17_r03.zip 解压后为 android-4.2.2 文件夹。

platform-tools

直接解压放进去即可

samples

比如解压 samples-16_r01.zip 得到 android-4.1 文件夹,重命名为 android-16 后放进 samples 文件夹。

sources

同上 samples 方法,解压后得到 src 文件夹,重命名为对应名称如 android-16 放进 sources 文件夹。

temp

通过 SDK Manager 下载的压缩包一般临时放在此文件夹下,安装完成后压缩包会被删除。

tools

直接解压放进去即可。

补充(15.3.22)

墙内无缝更新 Android SDK,请戳 

备份文字 1

1. 打开 Android SDK Manager, 打开设置 
2. 设置代理
可选取下面之一

备份文字 2

1.Android SDK 在线更新镜像服务器 
其他镜像服务器地址同上补充:
中国科学院开源协会镜像站地址:
IPV4/IPV6: 
端口:80
IPV4/IPV6: 
端口:80
IPV4/IPV6: 
端口:80
2. 使用方法:
2.1 启动 Android SDK Manager ,打开主界面,依次选择『Tools』、『Options…』,弹出『Android SDK Manager - Settings』窗口;
2.2 在『Android SDK Manager - Settings』窗口中,在『HTTP Proxy Server」和「HTTP Proxy Port』输入框内填入上面镜像服务器地址 (不包含http://,如下图) 和端口,并且选中『Force https://… sources to be fetched using http://…』复选框。设置完成后单击『Close』按钮关闭『Android SDK Manager - Settings』窗口返回到主界面;
2.3 依次选择『Packages』、『Reload』。

补充:

后记

结果如下图所示:

亲测 Eclipse 环境可行,按理 AndroidStudio 也行得通(未测试)。

目前就写到这里了,大家如果有改进的建议,欢迎留言~~

阅读(1646) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~