第二步 (仅供参考) sencha touch + PhoneGap(cordova 2.9 及其以下版本) 使用 adt eclipse进行打包...
首先你得安裝一個adt-eclipse
參考資料
http://www.crifan.com/android_eclipse_offline_install_adt/
然后就可以運行adt-eclipse來進行打包
1.新建Android一個項目
打開Eclipse,單擊菜單欄的“File”->把鼠標光標移動到“New”->在彈出的列表框中,如果直接能看到“Android Applicaion Project”選項項,則直接單擊此選項,否則選擇最下面的“Other...”,在彈出的窗口中,展開“Android”項,選擇“Android Applicaion Project”,然后“Next”;
其實還有一個方法就是直接點Eclipse工具欄的如下圖所指示的圖標:
在新彈出的窗口中按下圖提s示填寫相關(guān)信息,一路“Next”,直到點擊“Finish”,這樣第一個Android程序就創(chuàng)建好了,這是你會發(fā)現(xiàn)Eclipse左邊多了一個你新創(chuàng)建的Android項目。
2.將sencha touch項目導入
因為需要加入cordova,所以我們需要從http://cordova.apache.org/下載一個cordova的包
http://archive.apache.org/dist/cordova/cordova-2.6.0-src.zip我現(xiàn)在用的是2.6版本的
在安卓項目中結(jié)構(gòu)目錄如下:
如圖我們需要將cordova的jar包引入,然后需要在res/xml目錄下加入cordova的配置文件config.xml
代碼如下:
1 <?xml version="1.0" encoding="utf-8"?> 2 <!-- 3 Licensed to the Apache Software Foundation (ASF) under one 4 or more contributor license agreements. See the NOTICE file 5 distributed with this work for additional information 6 regarding copyright ownership. The ASF licenses this file 7 to you under the Apache License, Version 2.0 (the 8 "License"); you may not use this file except in compliance 9 with the License. You may obtain a copy of the License at 10 11 http://www.apache.org/licenses/LICENSE-2.0 12 13 Unless required by applicable law or agreed to in writing, 14 software distributed under the License is distributed on an 15 "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 KIND, either express or implied. See the License for the 17 specific language governing permissions and limitations 18 under the License. 19 --> 20 <cordova> 21 <!-- 22 access elements control the Android whitelist. 23 Domains are assumed blocked unless set otherwise 24 --> 25 26 <access origin="http://127.0.0.1*"/> <!-- allow local pages --> 27 28 <!-- <access origin="https://example.com" /> allow any secure requests to example.com --> 29 <!-- <access origin="https://example.com" subdomains="true" /> such as above, but including subdomains, such as www --> 30 <access origin=".*"/> 31 32 <!-- <content src="http://mysite.com/myapp.html" /> for external pages --> 33 <content src="index.html" /> 34 35 <log level="DEBUG"/> 36 <preference name="useBrowserHistory" value="true" /> 37 <preference name="exit-on-suspend" value="false" /> 38 <plugins> 39 <plugin name="App" value="org.apache.cordova.App"/> 40 <plugin name="Geolocation" value="org.apache.cordova.GeoBroker"/> 41 <plugin name="Device" value="org.apache.cordova.Device"/> 42 <plugin name="Accelerometer" value="org.apache.cordova.AccelListener"/> 43 <plugin name="Compass" value="org.apache.cordova.CompassListener"/> 44 <plugin name="Media" value="org.apache.cordova.AudioHandler"/> 45 <plugin name="Camera" value="org.apache.cordova.CameraLauncher"/> 46 <plugin name="Contacts" value="org.apache.cordova.ContactManager"/> 47 <plugin name="File" value="org.apache.cordova.FileUtils"/> 48 <plugin name="NetworkStatus" value="org.apache.cordova.NetworkManager"/> 49 <plugin name="Notification" value="org.apache.cordova.Notification"/> 50 <plugin name="Storage" value="org.apache.cordova.Storage"/> 51 <plugin name="FileTransfer" value="org.apache.cordova.FileTransfer"/> 52 <plugin name="Capture" value="org.apache.cordova.Capture"/> 53 <plugin name="Battery" value="org.apache.cordova.BatteryListener"/> 54 <plugin name="SplashScreen" value="org.apache.cordova.SplashScreen"/> 55 <plugin name="Echo" value="org.apache.cordova.Echo" /> 56 <plugin name="Globalization" value="org.apache.cordova.Globalization"/> 57 <plugin name="InAppBrowser" value="org.apache.cordova.InAppBrowser"/> 58 </plugins> 59 </cordova>然后需要修改AndroidManifest.xml進行權(quán)限配置等
代碼如下:
1 <?xml version="1.0" encoding="utf-8"?> 2 <manifest xmlns:android="http://schemas.android.com/apk/res/android" 3 package="com.example.jy110" 4 android:hardwareAccelerated="true" 5 android:versionCode="1" 6 android:versionName="1.0" 7 android:windowSoftInputMode="adjustPan" > 8 9 <supports-screens 10 android:anyDensity="true" 11 android:largeScreens="true" 12 android:normalScreens="true" 13 android:resizeable="true" 14 android:smallScreens="true" 15 android:xlargeScreens="true" /> 16 17 <uses-sdk 18 android:minSdkVersion="8" 19 android:targetSdkVersion="16" /> 20 21 <uses-permission android:name="android.permission.CAMERA" /> 22 <uses-permission android:name="android.permission.VIBRATE" /> 23 <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> 24 <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> 25 <uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" /> 26 <uses-permission android:name="android.permission.INTERNET" /> 27 <uses-permission android:name="android.permission.RECEIVE_SMS" /> 28 <uses-permission android:name="android.permission.RECORD_AUDIO" /> 29 <uses-permission android:name="android.permission.RECORD_VIDEO" /> 30 <uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" /> 31 <uses-permission android:name="android.permission.READ_CONTACTS" /> 32 <uses-permission android:name="android.permission.WRITE_CONTACTS" /> 33 <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> 34 <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> 35 <uses-permission android:name="android.permission.GET_ACCOUNTS" /> 36 <uses-permission android:name="android.permission.BROADCAST_STICKY" /> 37 38 <application 39 android:allowBackup="true" 40 android:icon="@drawable/ic_launcher" 41 android:label="@string/app_name" 42 android:theme="@style/AppTheme" > 43 <activity 44 android:name="com.example.jy110.Jy110Activity" 45 android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale" 46 android:label="@string/app_name" 47 android:theme="@android:style/Theme.Black.NoTitleBar" > 48 <intent-filter> 49 <action android:name="android.intent.action.MAIN" /> 50 51 <category android:name="android.intent.category.LAUNCHER" /> 52 </intent-filter> 53 </activity> 54 </application> 55 56 </manifest>現(xiàn)在環(huán)境基本配置完成了,接下來就把我們的html5項目引入進去
我們將做好的項目放進一個www的文件,如下圖:
然后將整個www文件放入安卓項目的assets目錄下
然后修改src之中的項目啟動文件,我這里是Jy110Activity文件,代碼如下
1 package com.example.jy110; 2 3 import org.apache.cordova.DroidGap; 4 5 import android.annotation.TargetApi; 6 import android.os.Bundle; 7 8 9 public class Jy110Activity extends DroidGap { 10 private int retryCount = 0; 11 @Override 12 public void onCreate(Bundle savedInstanceState) { 13 super.onCreate(savedInstanceState); 14 //設(shè)置啟動圖片 15 super.setIntegerProperty("splashscreen", R.drawable.splash); 16 super.init(); 17 //解決4.1以上安卓白屏問題 18 if(android.os.Build.VERSION.SDK_INT > android.os.Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1) { 19 fixJellyBeanIssues(); 20 } 21 //運行html5項目 22 super.loadUrl("file:///android_asset/www/index.html",5000); 23 } 24 25 @TargetApi(16) 26 protected void fixJellyBeanIssues() { 27 System.out.println(super.appView.toString()); 28 try { 29 super.appView.getSettings().setAllowUniversalAccessFromFileURLs(true); 30 } catch(NullPointerException e) { 31 System.out.println(e.toString()); 32 } 33 } 34 35 @Override 36 public void onReceivedError( int errorCode, String description, String failingUrl) 37 { 38 if(retryCount < 3) { 39 retryCount++; 40 super.loadUrl("file:///android_asset/www/index.html"); 41 } else { 42 super.loadUrl("file:///android_asset/www/fail.html"); 43 } 44 return; 45 } 46 47 }在st項目中引入cordova.js文件,在app.js中加入以下代碼
Ext.Loader.setConfig({enabled: true }); /* *請自行添加模擬數(shù)據(jù) *這里涉及到了 *路由:controller.Main *List:view.img.List *歷史記錄支持、自動銷毀、自定義消息提示:view.img.util.CardPanel *登錄、注冊:controller.User和view.user *Carousel:view.img.List和controller(除開user) *如有問題請聯(lián)系qq:534502520 q群:224711028 213119459@魔狼再世 歡迎交流 *此版本已在安卓中打包測試 */ Ext.application({name: 'app',appFolder: 'app',controllers: ['Main', 'User','Img'],views: ['util.CardPanel'],//請求地址postUrl: 'http://localhost:40231/PictureManager/mynetpic/',//過期時間sessionTimeout: 1000 * 60 * 60 * 24 * 30,launch: function () {Ext.Viewport.add({xclass: 'app.view.util.CardPanel'});// 等待加載PhoneGapdocument.addEventListener("deviceready", onDeviceReady, false);// PhoneGap加載完畢后執(zhí)行,這樣就可以在項目中使用PhoneGap調(diào)用手機硬件function onDeviceReady() {}} });這樣就算完成了,之后就是打包項目了。
3.簽名打包
Eclipse工程中右鍵工程,彈出選項中選擇 android工具-生成簽名應(yīng)用包:
選擇需要打包的android項目工程:
如果已有私鑰文件,選擇私鑰文件輸入密碼,如果沒有參見第6和7步創(chuàng)建私鑰文件:
4.輸入私鑰別名和密碼:
5.選擇APK存儲的位置,并完成設(shè)置 開始生成:
6.沒有私鑰文件的情況,創(chuàng)建私鑰文件:
7.輸入私鑰文件所需信息,并創(chuàng)建:
*SDK的安裝目錄最后不要有中文和空格,否則會出現(xiàn)不必要的錯誤。如果你的安裝路徑包含Program Files(有空格),用ADT打包會報錯,Ant方式打包的也會報錯,沒關(guān)系,不用重裝,解決方法:配置SDk環(huán)境變量和在Eclipse中配置SDK路徑的時候把Program Files改為Progra~1即可。(而且改成其他的都不行,只能是Progra~1,不信試試,這是Dos的規(guī)格)。
?附上項目實例一份,在adt-eclipse工具中,file-Import
選擇導入即可
http://download.csdn.net/detail/jy02534655/5635403
?
《新程序員》:云原生和全面數(shù)字化實踐50位技術(shù)專家共同創(chuàng)作,文字、視頻、音頻交互閱讀總結(jié)
以上是生活随笔為你收集整理的第二步 (仅供参考) sencha touch + PhoneGap(cordova 2.9 及其以下版本) 使用 adt eclipse进行打包...的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 应用按home键无最近应用
- 下一篇: 关于code reiview