版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
ThistutorialdescribeshowyoucansetupandevelopmentenvironmentforbuildingAndroidappsonanUbuntu11.04desktopusingEclipse,theAndroidSDK,andPhoneGap.IwilldescribehowtobuildAndroidappsfromthecommandlinewithPhoneGapandfromtheGUIwithEclipseandPhoneGapandhowtotesttheminanAndroidemulatorandonarealAndroiddevice.PhoneGapallowsyoutodevelopyourAndroidapplicationsusingwebtechnologiessuchasHTML,CSS,andJavaScript(e.g.withJavaScriptlibrariessuchasjQuery/jQTouch),anditwillturnthesewebappsintonativeAndroidapps(infact,PhoneGapsupportsmultipleplatformssuchasAndroid,iPhone,Palm,WindowsMobile,Symbian,soyoucanusethesamesourcestocreateappsformultipleplatforms).Idonotissueanyguaranteethatthiswillworkforyou!1PreliminaryNoteIwillnotexplainhowtodevelopanAndroidappusingHTML,CSS,andJavaScript.YoucanfindlotsoftutorialsaboutthisontheInternet,e.g.thisone:Tutorial:AsimpleTwitterclientwithInfact,I'musingaslightlymodifiedversionoftheTwitterclientdescribedinthelinktobuildaTwitterappinthistutorial.Youcandownloadmymodifiedversionfromhere: I'mworkingwiththeUbuntuClassicdesktophere(GNOME);thestepsshouldalmostbeidenticalifyouuseUnity.InstallingEclipseAndPrerequisitesForTheAndroidSDK/PhoneGapFirstopenaterminal(Applications>Accessories>Terminal):Lix公社(LinuID.c)于26年月2日注册并开通网站,Liux现在已经成为一种广受关注和支持的一种操作系统,ID中心,LinuxID就是关于inux的数据中心。并被收录到Google网页目录-计算机>软件>操作系统>Linux目录下。Ubuntu专题Fedora专题RedHat专题红旗LinuxAndroidLinux公社简介-广告服务-网站地图-帮助信息-本站(LinuxID)本站带宽由[668.CC友情提供Copyright©2006-2011Linux公社AllrightsEclipseandtheprerequisitesfortheAndroidSDKandPhoneGapcanbeinstalledassudoapt-getinstallopenjdk-6-jdkeclipserubyrubygemsruby-devlibnokogiri-rubygitantlibxml2libxml2-devlibxslt1-devIfyouareona64bitsystem,youalsoneedtoinstallthefollowingtwopackages:sudoapt-getinstalllib32stdc++6ia32-libsInstallingTheAndroidOpenFirefoxandgoto/sdk/index.html.ThereyouwillfindlinksfortheAndroidSDKforthedifferentplatforms(Windows,MacOSX,Linux).CopythelinklocationofthedownloadforLinux(i386)(don'tworry,thisdownloadworksonbothi386andx86_64...anddownloadanduncompressitascdwget/android/android-sdk_r11-linux_x86.tgztarxvfzandroid-sdk_r11-linux_x86.tgzThiswillgiveyouthedirectoryandroid-sdk-linux_x86inyourhomedirectory($HOME).We $HOME/android-sdk-linux_x86/platform-toolsdirectorytoourPATHvariablewhichwedoasOpengedit...andaddthefollowinglineatthebottomoftheTomakethechangeeffective(sothatwedon'thavetologoutandbackin),run:NowstarttheAndroidSDK:ThisishowtheAndroidSDKSelectAvailablepackagesintheleftpanelandthenselectAndroidRepositoryintherightpaneltodownloadSDKpackages:ThepackagesthatbelongtotheAndroidRepositorygroupshouldnowallbechecked.ClickontheInstallSelectedbutton:Anewwindowopens;marktheAcceptradioboxandclickon...tostartthedownloadoftheSDKIfADB(AndroidDebugBridge)needstoberestarted,clickonClickonCloseafterthedownloadhasfinished-thiswillclosethedownloadIntegratingTheAndroidSDKIntoIfyouwanttouseEclipsetocreateyourAndroidappsinsteadofthecommandline,youneedtointegratetheAndroidSDKintoEclipse.Todothis,startEclipse(Applications>Programming>ClickonOKifyouseetheWorkspaceLauncherwindow(youcanchecktheUsethisasthedefaultanddonotaskagaincheckboxtonotseethismessageanymore):NowinEclipse,gotoHelp>InstallNewTheAvailableSoftwarewindowopens.ClickontheAdd...AsmallAddSitewindowopens.FillinthefollowingvaluesandclickonOK:Name:ADTPluginBackintheAvailableSoftwarewindow,youshouldnowseethesoftwareDeveloperTools.SelectthatsoftwareandclickonNext>:Inthenextwindow,clickonNext>NowacceptthelicenseagreementsandclickonThepackagesneededtointegratetheAndroidSDKintoEclipsearenowbeingdownloadedandIfyouseethefollowingmessageaboutunsignedcontent,it'soktoclickontheOKAttheendoftheinstallation,Eclipseneedstoberestarted.Todothis,clickonNowthere'sonefinalsteptocompletetheAndroidSDKintegrationinEclipse:GotoWindow>InthePreferenceswindow,selectAndroidintheleftpanel,andthenclickontheBrowse...buttonthatbelongstotheSDKLocationfieldintherightpanel:SelectthedirectorywheretheAndroidSDKislocated(it'sandroid-sdk-linux_x86inyourhomedirectory)andclickonOK:BackinthePreferenceswindow,clickonApply(youshouldthenseethesupportedAndroidversionsintheTargetNamecolumn)......andthenonInstallingToinstallPhoneGap,openFirefoxandgoto/phonegap/phonegap-android.ClickontheDownloadsbutton:SelectDownload.tar.gzfromtheoverlaythatcomesIntheFirefoxdownloaddialogue,pleasechooseSaveAfterthedownloadhasfinished,gotothedirectorywherethedownloadhasbeensavedcdcdTakealookatthedirectory'scontentstolearnhowthePhoneGapdownloadislsls-falko@falko-virtual-machine:~/Downloads$ls-ltotal11200-rw-r--r--1falkofalko114671782011-06-2114:01Asyousee,inmycaseitisnamedphonegap-phonegap-android--15-g939754e.tar.gz.Nowletsuncompressthefile:directory.IwanttomovethatdirectorytomyhomedirectoryandrenameitWemustaddthebindirectoryinside$HOME/phonegap-phonegap-androidtoourPATHvariable,thereforeweedit~/.profileagain:cdcdgeditTomakethechangeeffective,NowwearefinishedwithsettingupourAndroiddevelopmentenvironment;finallywecanstartdoingthingswithit!StartingAnAndroidTheAndroidSDKcomeswithanemulatorsothatyoucantestyourappsintheemulatorinsteadofonarealAndroiddevice.Tocreateanemulator,wefirstneedtoknowwhichAndroidversions(targets)areandroidandroidlistfalko@falko-virtual-machine:~$androidlisttargetsAvailableAndroidtargets:id:1or"android-3"Name:Android1.5Type:PlatformAPIlevel:3Revision:Skins:HVGA(default),QVGA-L,HVGA-P,HVGA-L,QVGA-id:2or"android-4"Name:Android1.6Type:PlatformAPIlevel:4Revision:Skins:HVGA,QVGA,WVGA854,WVGA800id:3or"android-Name:Android2.1-update1Type:PlatformAPIlevel:Revision:Skins:HVGA,QVGA,WQVGA400,WVGA854,WQVGA432,WVGA800id:4or"android-Name:Android2.2Type:PlatformAPIlevel:8Revision:Skins:HVGA,QVGA,WQVGA400,WVGA854,WQVGA432,WVGA800id:5or"android-10"Name:Android2.3.3Type:PlatformAPIlevel:Revision:Skins:HVGA,QVGA,WQVGA400,WVGA854,WQVGA432,WVGA800id:6or"android-11"Name:Android3.0Type:PlatformAPIlevel:11Revision:Skins:WXGA(default)id:7or"android-12"Name:Android3.1Type:PlatformAPIlevel:12Revision:Skins:WXGA(default)IwillnowcreateanemulatorcalledmySimforAndroid2.3.3(id5orandroid-androidandroidcreateavd-nmySim-tandroid-falko@falko-virtual-machine:~$androidcreateavd-nmySim-tandroid-10Android2.3.3isabasicAndroidplatform.Doyouwishtocreateacustomhardwareprofile[no]<--CreatedAVD'mySim'basedonAndroid2.3.3,withthefollowinghardwareconfig:Tostarttheemulator,emulatoremulator-avdmySim-scaleItcantakeafewminutesuntiltheemulatorisupandrunning,butthenitshouldlookasTobuildmyAndroidapp(whichIcallTweetMe)fromitsHTML,CSS,andJavaScriptsources,Icreateafoldercalledtweetmeinmyhomedirectory,andinthattweetmefolderIplaceanotherfoldercalledtweetmewichcontainsthesources(HTML,CSS,JavaScript):||+||||SOURCES(HTML,CSS,GotocdcdYoushouldseetheHTML,CSS,JavaScriptsourcesinthatlsls-falko@falko-virtual-machine:~/tweetme/tweetme$ls-ltotal96-rw-r--r--1falkofalko42332011-01-2400:20drwxr-xr-x2falkofalko40962011-06-2114:23-rw-r--r--1falkofalko786012011-01-2323:15drwxr-xr-x4falkofalko40962011-06-2114:23themesNowwecancreateanappeitherfromthecommandlineorbyusingdroidgapdroidgap(Ifyougettheerrormessagedroidgap:commandnotfound,pleaseandtryagain.Thiswillcreatethedirectory~/tweetme/tweetme_androidwhichcontainseverythingweneedtobuildJavaScriptsourcesplusthephonegap.<version>.jsfile.ls-lfalko@falko-virtual-machine:~/tweetme/tweetme_android$ls-ltotal44-rw-r--r--1falkofalko22412011-06-2114:25drwxr-xr-x3falkofalko40962011-06-2114:25drwxr-xr-x2falkofalko40962011-06-2114:25-rw-r--r--1falkofalko6962011-06-2114:25-rw-r--r--1falkofalko28912011-06-2114:25-rw-r--r--1falkofalko3632011-06-2114:25drwxr-xr-x2falkofalko40962011-06-2114:25-rw-r--r--1falkofalko4252011-06-2114:25-rw-r--r--1falkofalko11592011-06-2114:25drwxr-xr-x7falkofalko40962011-06-2114:25ls-lls-lfalko@falko-virtual-machine:~/tweetme/tweetme_android$ls-lassets/www/total228-rw-r--r--1falko 42332011-06-2114:25drwxr-xr-x2falko 40962011-06-2114:25-rw-r--r--1falkofalko786012011-06-2114:25-rw-r--r--1falkofalko1329552011-06-2114:25drwxr-xr-x4falkofalko 40962011-06-2114:25themesImportant:Ifoundaproblemwiththephonegap.0.9.5.jsfile-itcontainsseverallineswithaprompt()functionthataskstheusersomequestions(itasksforgetPort,getToken,getServer,restartServer,usePolling),andthisisclearlynotwhatyouwantinsideyourapp-seethefollowingscreenshots:Asasolutionforthisproblem,youcaneithereditphonegap.0.9.5.jsandcommentoutalllinesthatcontaintheprompt()function(therearesixlines),oryoudownloadPhoneGap0.9.4from/files/phonegap-0.9.4.zip(PhoneGap0.9.4doesn'tusetheprompt()function),extractthephonegap.0.9.4.jsfilefromit,deletephonegap.0.9.5.jsfromtheassets/www/directoryandplacephonegap.0.9.4.jsintheassets/www/directoryinstead.Ifyouprefertocommentoutalllinesthatcontaintheprompt()functioninphonegap.0.9.5.js,butdon'twanttoeditthefilemanually,youcanusethefollowingcommandwhichcommentsoutallsixlinesautomatically(thecommandworksfineforphonegap.0.9.5.js;however,itmightnotworkforfutureversions,sopleasekeepthisinmind!):sedsed-i'/prompt/s;^;//;'lsls-lfalko@falko-virtual-machine:~/tweetme/tweetme_android$ls-llibs/total136-rw-r--r--1falkofalko1390042011-06-2114:25phonegap.0.9.5.jarNowwemustedittheindex.htmlfileintheassets/www/folderandaddthegeditgeditLet'sassumethefilestartsas<!DOCTYPEHTMLPUBLIC"-//W3C//DTDHTML4.01Transitional//EN"<metahttp-equiv="Content-Type"content="text/html;<!--includeJQuerythroughGoogleAPI=>Alwayshavethelatestversion--><scripttype="text/javascript"<scripttype="text/javascript">google.load("jquery","1.3.2");</script><!--importJQTouch--<scriptsrc="jqtouch/jqtouch.min.js"<!--ImportJQTouchdefaultstyle(iPhoneReplacethestring"themes/apple"with"themes/jq"foranon-iPhonetheme--><linktype="text/css"rel="stylesheet"media="screen"<link<linktype="text/css"rel="stylesheet"media="screen"Addtheline<scripttype="text/javascript"charset="utf-8"src="phonegap.0.9.5.js"></script>beforeallotherJavaScriptsothatitlooksasfollows(ifyouhavereplacedphonegap.0.9.5.jswithphonegap.0.9.4.js,pleaseusetheline<scripttype="text/javascript"charset="utf-8"src="phonegap.0.9.4.js"></script>instead):<!DOCTYPEHTMLPUBLIC"-//W3C//DTDHTML4.01Transitional//EN"<metahttp-equiv="Content-Type"content="text/html;<scripttype="text/javascript"charset="utf-8"<!--includeJQuerythroughGoogleAPI=>Alwayshavethelatestversion--><scripttype="text/javascript"<scripttype="text/javascript">google.load("jquery","1.3.2");</script><!--importJQTouch--<scriptsrc="jqtouch/jqtouch.min.js"<!--ImportJQTouchdefaultstyle(iPhoneReplacethestring"themes/apple"with"themes/jq"foranon-iPhonetheme--><linktype="text/css"rel="stylesheet"media="screen"<linktype="text/css"rel="stylesheet"media="screen"antantItshouldsayBUILDSUCCESSFULatthe[apkbuilder]Creatingtweetme-debug-unaligned.apkandsigningitwithadebug[echo]RunningzipalignonfinalBUILDTotaltime:38Youcannowfindyourappinthebin/directory(calledtweetme-debug.apk;apkistheextensionforAndroidapps):ls-lfalko@falko-virtual-machine:~/tweetme/tweetme_android/bin$ls-ltotal808drwxr-xr-x3falko 40962011-06-2114:32-rw-r--r--1falkofalko1556522011-06-2114:32-rw-r--r--1falkofalko1718772011-06-2114:32-rw-r--r--1falkofalko2449002011-06-2114:32tweetme--rw-r--r--1falkofalko2448462011-06-2114:32tweetme-debug-unaligned.apkToinstallittothefirstrunningemulator,wecanadbadb-einstall-rtweetme-falko@falko-virtual-machine:~/tweetme/tweetme_android/bin$adb-einstall-rtweetme-d411KB/s(244900bytesin(Insteadofrunningantdebugfirstandthenadb-einstall-rtweetme-debug.apkfromthedirectorytoinstalltheapp,wecouldhaveantantdebugwhichwouldhavebuiltandafterwardsinstalledtheappinoneNowgotoyouremulator,andyoushouldfindthenewapplistedamongtheotherThisiswhattheapplooksdroidgapdroidgap(Ifyougettheerrormessagedroidgap:commandnotfound,pleaseandtryagain.Thiswillcreatethedirectory~/tweetme/tweetme_androidwhichcontainseverythingweneedtobuildJavaScriptsourcesplusthephonegap.<version>.jsfile.cdcdlsls-totasls-lfalko@falko-virtual-machine:~/tweetme/tweetme_android$ls-lassets/www/total228-rw-r--r--1falko 42332011-06-2114:25drwxr-xr-x2falko 40962011-06-2114:25-rw-r--r--1falkofalko786012011-06-2114:25-rw-r--r--1falkofalko1329552011-06-2114:25drwxr-xr-x4falkofalko 40962011-06-2114:25themesImportant:Ifoundaproblemwiththephonegap.0.9.5.jsfile-itcontainsseverallineswithaprompt()functionthataskstheusersomequestions(itasksforgetPort,getToken,getServer,restartServer,usePolling),andthisisclearlynotwhatyouwantinsideyourapp-seethefollowingscreenshots:Asasolutionforthisproblem,youcaneithereditphonegap.0.9.5.jsandcommentoutalllinesthatcontaintheprompt()function(therearesixlines),oryoudownloadPhoneGap0.9.4from/files/phonegap-0.9.4.zip(PhoneGap0.9.4doesn'tusetheprompt()function),extractthephonegap.0.9.4.jsfilefromit,deletephonegap.0.9.5.jsfromtheassets/www/directoryandplacephonegap.0.9.4.jsintheassets/www/directoryinstead.Ifyouprefertocommentoutalllinesthatcontaintheprompt()functioninphonegap.0.9.5.js,butdon'twanttoeditthefilemanually,youcanusethefollowingcommandwhichcommentsoutallsixlinesautomatically(thecommandworksfineforphonegap.0.9.5.js;however,itmightnotworkforfutureversions,sopleasekeepthisinmind!):sedsed-i'/prompt/s;^;//;'lsls-lfalko@falko-virtual-machine:~/tweetme/tweetme_android$ls-llibs/total136-rw-r--r--1falkofalko1390042011-06-2114:25phonegap.0.9.5.jarNowopenEclipseandgotoFile>New>IntheNewProjectwindow,selectAndroid>AndroidProjectandclickonNextcreatedthesourcebyrunningdroidgapcreate)andclickontheBrowse...button-don'tfilloutanyotherfieldsinthatwindow:BackintheNewAndroidProjectwindow,allotherfieldsshouldnowbefilled.ClickonYoushouldnowseethesourcetreeofyourappintheleftpanelinAndroid.Right-clickassets/www/index.htmlfileandselectOpenWith>TextAddthephonegap.<version>.jsfiletothe<head></head>section(beforeallotherJavaScriptfiles/JavaScriptcode).Let'sassumethefilestartsas<!DOCTYPE<!DOCTYPEHTMLPUBLIC"-//W3C//DTDHTML4.01Transitional//EN"<metahttp-equiv="Content-Type"content="text/html;<!--includeJQuerythroughGoogleAPI=>Alwayshavethelatestversion--><scripttype="text/javascript"<scripttype="text/javascript"<scripttype="text/javascript">google.load("jquery","1.3.2");</script><!--importJQTouch--<scriptsrc="jqtouch/jqtouch.min.js"<!--ImportJQTouchdefaultstyle(iPhoneReplacethestring"themes/apple"with"themes/jq"foranon-iPhonetheme--><linktype="text/css"rel="stylesheet"media="screen"<linktype="text/css"rel="stylesheet"media="screen"Addtheline<scripttype="text/javascript"charset="utf-8"src="phonegap.0.9.5.js"></script>beforeallotherJavaScriptsothatitlooksasfollows(ifyouhavereplacedphonegap.0.9.5.jswithphonegap.0.9.4.js,pleaseusetheline<script<!DOCTYPE<!DOCTYPEHTMLPUBLIC
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025年度生物质能发电纯劳务分包合同模板4篇
- 2025年度智能电动汽车车辆借用协议书汇编4篇
- 2025年洗车服务行业新能源汽车充电站合作合同3篇
- 2025年洗车店租赁与客户数据安全保护合同3篇
- 2025年度个人住房抵押贷款延期还款补充协议4篇
- 2025年度个人汽车买卖协议书示范文本3篇
- 2025年度健康医疗大数据平台建设合同模板4篇
- 2025年浙江瓯海建设集团有限公司招聘笔试参考题库含答案解析
- 2025年校企共同开发新型课程体系合作协议书3篇
- 2025年度个人股权质押股权信托服务合同(信托保障版)4篇
- GB/T 14600-2009电子工业用气体氧化亚氮
- 小学道德与法治学科高级(一级)教师职称考试试题(有答案)
- 申请使用物业专项维修资金征求业主意见表
- 河北省承德市各县区乡镇行政村村庄村名居民村民委员会明细
- 实用性阅读与交流任务群设计思路与教学建议
- 应急柜检查表
- 通风设施标准
- 酒店市场营销教案
- 房屋买卖合同简单范本 房屋买卖合同简易范本
- 无抽搐电休克治疗规范
- 环保有限公司营销策划方案
评论
0/150
提交评论