PhoneGap的在线打包有大小限制,超过30M的包无法在线打包。当然,可以把包里面的图片、声音文件去掉,然后打包。下载以后,解包,重新打包并签名。蛮麻烦的。

本地打包的简单方法如下:

下载安装Java环境。

下载安装ADT。http://developer.android.com/sdk/index.html

打开ADT,新建一个安卓应用项目

输入名称啥的,然后就可以一路下一步

可以选择下项目位置,我的是默认的。

这里可以选择图标。

选择第一个

这个时候,一个安卓项目就建好了。这个时候运行,会看到默认的样子,不管他,无视。

将PhoneGap目录下的android目录下的jar文件拷贝到项目的libs目录下

将xml目录拷贝到项目的res目录下

在assetc目录下,建立一个www目录,下面放html内容。为了偷懒,我把phonegap例子里面的内容拷贝过来了。

修改Java代码:

  1. package com.myexample.helloworld;
  2. import android.os.Bundle;
  3. import org.apache.cordova.*;
  4. public class MainActivity extends DroidGap
  5. {
  6. @Override
  7. public void onCreate(Bundle savedInstanceState)
  8. {
  9. super.onCreate(savedInstanceState);
  10. // Set by <content src="index.html" /> in config.xml
  11. super.loadUrl(Config.getStartUrl());
  12. //super.loadUrl("file:///android_asset/www/index.html")
  13. }
  14. }
  15. /*
  16. * 下面是adt生成的代码,注释掉
  17. import android.os.Bundle;
  18. import android.app.Activity;
  19. import android.view.Menu;
  20. public class MainActivity extends Activity {
  21. @Override
  22. protected void onCreate(Bundle savedInstanceState) {
  23. super.onCreate(savedInstanceState);
  24. setContentView(R.layout.activity_main);
  25. }
  26. @Override
  27. public boolean onCreateOptionsMenu(Menu menu) {
  28. // Inflate the menu; this adds items to the action bar if it is present.
  29. getMenuInflater().inflate(R.menu.main, menu);
  30. return true;
  31. }
  32. }*/

修改一下项目根目录下的AndroidManifest.xml和res/xml目录下的config.xml文件

AndroidManifest.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. http://www.apache.org/licenses/LICENSE-2.0
  11. Unless required by applicable law or agreed to in writing,
  12. software distributed under the License is distributed on an
  13. "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  14. KIND, either express or implied.  See the License for the
  15. specific language governing permissions and limitations
  16. under the License.
  17. -->
  18. <manifest xmlns:android="http://schemas.android.com/apk/res/android"
  19. package="com.myexample.helloworld"
  20. android:hardwareAccelerated="true"
  21. android:versionCode="1"
  22. android:versionName="1.0"
  23. android:windowSoftInputMode="adjustPan" >
  24. <supports-screens
  25. android:anyDensity="true"
  26. android:largeScreens="true"
  27. android:normalScreens="true"
  28. android:resizeable="true"
  29. android:smallScreens="true"
  30. android:xlargeScreens="true" />
  31. <uses-permission android:name="android.permission.CAMERA" />
  32. <uses-permission android:name="android.permission.VIBRATE" />
  33. <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
  34. <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
  35. <uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" />
  36. <uses-permission android:name="android.permission.INTERNET" />
  37. <uses-permission android:name="android.permission.RECEIVE_SMS" />
  38. <uses-permission android:name="android.permission.RECORD_AUDIO" />
  39. <uses-permission android:name="android.permission.RECORD_VIDEO" />
  40. <uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
  41. <uses-permission android:name="android.permission.READ_CONTACTS" />
  42. <uses-permission android:name="android.permission.WRITE_CONTACTS" />
  43. <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
  44. <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
  45. <uses-permission android:name="android.permission.GET_ACCOUNTS" />
  46. <uses-permission android:name="android.permission.BROADCAST_STICKY" />
  47. <application
  48. android:debuggable="true"
  49. android:hardwareAccelerated="true"
  50. android:icon="@drawable/ic_launcher"
  51. android:label="@string/app_name" >
  52. <activity
  53. android:name="com.myexample.helloworld.MainActivity"
  54. android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale"
  55. android:label="@string/app_name"
  56. android:theme="@android:style/Theme.Black.NoTitleBar" >
  57. <intent-filter>
  58. <action android:name="android.intent.action.MAIN" />
  59. <category android:name="android.intent.category.LAUNCHER" />
  60. </intent-filter>
  61. </activity>
  62. </application>
  63. <uses-sdk
  64. android:minSdkVersion="7"
  65. android:targetSdkVersion="17" />
  66. </manifest>

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. http://www.apache.org/licenses/LICENSE-2.0
  11. Unless required by applicable law or agreed to in writing,
  12. software distributed under the License is distributed on an
  13. "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  14. KIND, either express or implied.  See the License for the
  15. specific language governing permissions and limitations
  16. under the License.
  17. -->
  18. <widget
  19. id="com.myexample.helloworld"
  20. version="2.0.0"
  21. xmlns="http://www.w3.org/ns/widgets" >
  22. <name>
  23. helloworld
  24. </name>
  25. <description>
  26. A sample Apache Cordova application that responds to the deviceready event.
  27. </description>
  28. <author
  29. email="dev@cordova.apache.org"
  30. href="http://cordova.io" >
  31. Apache Cordova Team
  32. </author>
  33. <access origin="*" />
  34. <!-- <content src="http://mysite.com/myapp.html" /> for external pages -->
  35. <content src="index.html" />
  36. <preference
  37. name="loglevel"
  38. value="DEBUG" />
  39. <!--
  40. <preference name="splashscreen" value="resourceName" />
  41. <preference name="backgroundColor" value="0xFFF" />
  42. <preference name="loadUrlTimeoutValue" value="20000" />
  43. <preference name="InAppBrowserStorageEnabled" value="true" />
  44. <preference name="disallowOverscroll" value="true" />
  45. -->
  46. <feature name="App" >
  47. <param
  48. name="android-package"
  49. value="org.apache.cordova.App" />
  50. </feature>
  51. <feature name="Geolocation" >
  52. <param
  53. name="android-package"
  54. value="org.apache.cordova.GeoBroker" />
  55. </feature>
  56. <feature name="Device" >
  57. <param
  58. name="android-package"
  59. value="org.apache.cordova.Device" />
  60. </feature>
  61. <feature name="Accelerometer" >
  62. <param
  63. name="android-package"
  64. value="org.apache.cordova.AccelListener" />
  65. </feature>
  66. <feature name="Compass" >
  67. <param
  68. name="android-package"
  69. value="org.apache.cordova.CompassListener" />
  70. </feature>
  71. <feature name="Media" >
  72. <param
  73. name="android-package"
  74. value="org.apache.cordova.AudioHandler" />
  75. </feature>
  76. <feature name="Camera" >
  77. <param
  78. name="android-package"
  79. value="org.apache.cordova.CameraLauncher" />
  80. </feature>
  81. <feature name="Contacts" >
  82. <param
  83. name="android-package"
  84. value="org.apache.cordova.ContactManager" />
  85. </feature>
  86. <feature name="File" >
  87. <param
  88. name="android-package"
  89. value="org.apache.cordova.FileUtils" />
  90. </feature>
  91. <feature name="NetworkStatus" >
  92. <param
  93. name="android-package"
  94. value="org.apache.cordova.NetworkManager" />
  95. </feature>
  96. <feature name="Notification" >
  97. <param
  98. name="android-package"
  99. value="org.apache.cordova.Notification" />
  100. </feature>
  101. <feature name="Storage" >
  102. <param
  103. name="android-package"
  104. value="org.apache.cordova.Storage" />
  105. </feature>
  106. <feature name="FileTransfer" >
  107. <param
  108. name="android-package"
  109. value="org.apache.cordova.FileTransfer" />
  110. </feature>
  111. <feature name="Capture" >
  112. <param
  113. name="android-package"
  114. value="org.apache.cordova.Capture" />
  115. </feature>
  116. <feature name="Battery" >
  117. <param
  118. name="android-package"
  119. value="org.apache.cordova.BatteryListener" />
  120. </feature>
  121. <feature name="SplashScreen" >
  122. <param
  123. name="android-package"
  124. value="org.apache.cordova.SplashScreen" />
  125. </feature>
  126. <feature name="Echo" >
  127. <param
  128. name="android-package"
  129. value="org.apache.cordova.Echo" />
  130. </feature>
  131. <feature name="Globalization" >
  132. <param
  133. name="android-package"
  134. value="org.apache.cordova.Globalization" />
  135. </feature>
  136. <feature name="InAppBrowser" >
  137. <param
  138. name="android-package"
  139. value="org.apache.cordova.InAppBrowser" />
  140. </feature>
  141. <!-- Deprecated plugins element. Remove in 3.0 -->
  142. <plugins>
  143. </plugins>
  144. </widget>

然后,就可以运行了

PhoneGap的官方方法不是这样的,是用命令行生成默认包的。但是要装好几个东西。具体可以看PhoneGap包里面的readme文档。

PhoneGap本地将html打包成安卓App的更多相关文章

  1. 将h5用HBuilderX打包成安卓app后,document.documentElement.scrollTop的值始终为0或者document.body.scrollTop始终为0

    let time = setInterval(() => { let scroll = document.documentElement.scrollTop || document.body.s ...

  2. 将H5页面打包成安卓原生app

    第一步:下载HBuilderX,新建项目选择5+App新建一个空项目如下图 新建后项目目录结构如下图 第二步,将你要打包成安卓app的文件打包,最后生成的文件目录如下图 1.打包完成后,将对应文件内容 ...

  3. HBuilderX打包成安卓或苹果app之后的调试问题,避免每次都要打包

    一.使用VScode安装 Live Server插件 二.使用:安装成功后---->>新建一个index.html 写入内容如下图所示 注:href地址是你在电脑上启动该项目的访问地址(此 ...

  4. 项目打包成手机app 通过什么打包?

    项目打包成手机app  通过什么打包? 1.HbuildX注册邮箱账号 2.新建-app,然后将自动生成的除manifest.json之外的所有文件删除,然后将vue项目build之后生成的dist文 ...

  5. 把H5打包成IOS APP其实可以很简单!签名?越狱?都不需要!

    很多小伙伴都在开发自己的app, 有的实现实现比较简单,就是一个h5页面,然后想要打包成app发布出去. 这个想法很单纯 打包生成个app这个是很简单的,网上一堆打包工具,分分钟可以完成 BUT…… ...

  6. 搭建ionic3-angular5 开发环境并打包成安卓apk包教程

    安装node.js 搭建ionic3-angular5 开发环境,首先查看本地电脑是否安装node环境,打开终端,输入 命令: node -v 没有去安装nodejs  网址:http://nodej ...

  7. 将python代码打包成一个app/exe

    前言 打包的代码通常都需要写一个简单的界面,一般用PyQt来写.用PyQt写界面的方法请戳这里:PyQt5的安装及基本配置    PyQt5教程 python提供了几个用来打包的模块,主要有py2ap ...

  8. vue+hbuilder 打包成移动app

    查看了很多网上写的改来改去都在手机上运行不起来,运行起来又是白屏:最后放弃,自己结合文档搞吧! 1. 项目目录下的config文件夹里的index.js文件中,将build对象下的assetsPubl ...

  9. pc端页面打包成安卓apk

    一.phoneGap PhoneGap是一个采用HTML,CSS和JavaScript的技术,创建移动跨平台移动应用程序的快速开发平台.它使开发者能够在网页中调用IOS,Android,Palm,Sy ...

随机推荐

  1. SSH服务器拒绝了密码。请再试一次。怎么改都不行

    使用Xshell连接服务器,之前还好好的,突然之间就报"SSH服务器拒绝了密码.请再试一次"的错误. 1.检查 检查了IP.连接端口.用户.密码.网络是否正确? 本机情况:能够pi ...

  2. ThreadPoolExecutor里面4种拒绝策略(详细)

    ThreadPoolExecutor类实现了ExecutorService接口和Executor接口,可以设置线程池corePoolSize,最大线程池大小,AliveTime,拒绝策略等.常用构造方 ...

  3. c++学习笔记4(函数重载)

    一个或多个函数,名字相似,然而参数个数或类型不同,这个叫做函数重载 优点:可以使函数的命名变得简单

  4. Spring IOC&DI 控制反转和依赖注入

    控制反转(Inversion of Control,缩写为IOC),它是把你设计好的对象交给spring控制,而不再需要你去手动 new Object(); 网上对于IOC的解释很多,对程序员而言,大 ...

  5. Django笔记&教程 3-3 模板常用语法

    Django 自学笔记兼学习教程第3章第3节--模板常用语法 点击查看教程总目录 本文主要参考:https://docs.djangoproject.com/en/2.2/ref/templates/ ...

  6. 菜鸡的Java笔记 第二十六 - java 内部类

    /*    innerClass        从实际的开发来看,真正写到内部类的时候是在很久以后了,短期内如果是自己编写代码,几乎是见不到内部类出现的        讲解它的目的第一个是为了解释概念 ...

  7. Web优化躬行记(5)——网站优化

    最近阅读了很多优秀的网站性能优化的文章,所以自己也想总结一些最近优化的手段和方法. 个人感觉性能优化的核心是:减少延迟,加速展现. 本文主要从产品设计.前端.后端和网络四个方面来诉说优化过程. 一.产 ...

  8. kibana解决Kibana server is not ready yet问题

    找到kbn的config中的xml配置 将es的ip改成真正的ip

  9. layui某个字段不让页面显示显示

    <script src="/layuiadmin/layui/layui.js"></script> <script> layui.config ...

  10. 从零开始学Kotlin第一课

    Kotlin的方法: 一个简单的计算器: fun main(args:Array<String>){ //主函数main方法 var a=8; var b=9; println(plus( ...