首先你得安裝一個adt-eclipsejavascript
參考資料html
http://www.crifan.com/android_eclipse_offline_install_adt/html5
而後就能夠運行adt-eclipse來進行打包java
1.新建Android一個項目android
打開Eclipse,單擊菜單欄的「File」->把鼠標光標移動到「New」->在彈出的列表框中,若是直接能看到「Android Applicaion Project」選項項,則直接單擊此選項,不然選擇最下面的「Other...」,在彈出的窗口中,展開「Android」項,選擇「Android Applicaion Project」,而後「Next」;express
其實還有一個方法就是直接點Eclipse工具欄的以下圖所指示的圖標:apache
在新彈出的窗口中按下圖提s示填寫相關信息,一路「Next」,直到點擊「Finish」,這樣第一個Android程序就建立好了,這是你會發現Eclipse左邊多了一個你新建立的Android項目。session
2.將sencha touch項目導入app
由於須要加入cordova,因此咱們須要從http://cordova.apache.org/下載一個cordova的包less
http://archive.apache.org/dist/cordova/cordova-2.6.0-src.zip我如今用的是2.6版本的
在安卓項目中結構目錄以下:
如圖咱們須要將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進行權限配置等
代碼以下:
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>
如今環境基本配置完成了,接下來就把咱們的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 //設置啓動圖片 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 }); /* *請自行添加模擬數據 *這裏涉及到了 *路由:controller.Main *List:view.img.List *歷史記錄支持、自動銷燬、自定義消息提示:view.img.util.CardPanel *登陸、註冊:controller.User和view.user *Carousel:view.img.List和controller(除開user) *若有問題請聯繫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' }); // 等待加載PhoneGap document.addEventListener("deviceready", onDeviceReady, false); // PhoneGap加載完畢後執行,這樣就能夠在項目中使用PhoneGap調用手機硬件 function onDeviceReady() { } } });
這樣就算完成了,以後就是打包項目了。
3.簽名打包
Eclipse工程中右鍵工程,彈出選項中選擇 android工具-生成簽名應用包:
選擇須要打包的android項目工程:
若是已有私鑰文件,選擇私鑰文件輸入密碼,若是沒有參見第6和7步建立私鑰文件:
4.輸入私鑰別名和密碼:
5.選擇APK存儲的位置,並完成設置 開始生成:
6.沒有私鑰文件的狀況,建立私鑰文件:
7.輸入私鑰文件所需信息,並建立:
*SDK的安裝目錄最後不要有中文和空格,不然會出現沒必要要的錯誤。若是你的安裝路徑包含Program Files(有空格),用ADT打包會報錯,Ant方式打包的也會報錯,不要緊,不用重裝,解決方法:配置SDk環境變量和在Eclipse中配置SDK路徑的時候把Program Files改成Progra~1便可。(並且改爲其餘的都不行,只能是Progra~1,不信試試,這是Dos的規格)。
附上項目實例一份,在adt-eclipse工具中,file-Import
選擇導入便可