PhoneGap本地将html打包成安卓App
PhoneGap的在线打包有大小限制,超过30M的包无法在线打包。当然,可以把包里面的图片、声音文件去掉,然后打包。下载以后,解包,重新打包并签名。蛮麻烦的。
本地打包的简单方法如下:
下载安装Java环境。
下载安装ADT。http://developer.android.com/sdk/index.html
打开ADT,新建一个安卓应用项目
输入名称啥的,然后就可以一路下一步
可以选择下项目位置,我的是默认的。
这里可以选择图标。
选择第一个
这个时候,一个安卓项目就建好了。这个时候运行,会看到默认的样子,不管他,无视。
将PhoneGap目录下的android目录下的jar文件拷贝到项目的libs目录下
将xml目录拷贝到项目的res目录下
在assetc目录下,建立一个www目录,下面放html内容。为了偷懒,我把phonegap例子里面的内容拷贝过来了。
修改Java代码:
- package com.myexample.helloworld;
- import android.os.Bundle;
- import org.apache.cordova.*;
- public class MainActivity extends DroidGap
- {
- @Override
- public void onCreate(Bundle savedInstanceState)
- {
- super.onCreate(savedInstanceState);
- // Set by <content src="index.html" /> in config.xml
- super.loadUrl(Config.getStartUrl());
- //super.loadUrl("file:///android_asset/www/index.html")
- }
- }
- /*
- * 下面是adt生成的代码,注释掉
- import android.os.Bundle;
- import android.app.Activity;
- import android.view.Menu;
- public class MainActivity extends Activity {
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- }
- @Override
- public boolean onCreateOptionsMenu(Menu menu) {
- // Inflate the menu; this adds items to the action bar if it is present.
- getMenuInflater().inflate(R.menu.main, menu);
- return true;
- }
- }*/
修改一下项目根目录下的AndroidManifest.xml和res/xml目录下的config.xml文件
AndroidManifest.xml
- <?xml version="1.0" encoding="utf-8"?>
- <!--
- Licensed to the Apache Software Foundation (ASF) under one
- or more contributor license agreements. See the NOTICE file
- distributed with this work for additional information
- regarding copyright ownership. The ASF licenses this file
- to you under the Apache License, Version 2.0 (the
- "License"); you may not use this file except in compliance
- with the License. You may obtain a copy of the License at
- http://www.apache.org/licenses/LICENSE-2.0
- Unless required by applicable law or agreed to in writing,
- software distributed under the License is distributed on an
- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- KIND, either express or implied. See the License for the
- specific language governing permissions and limitations
- under the License.
- -->
- <manifest xmlns:android="http://schemas.android.com/apk/res/android"
- package="com.myexample.helloworld"
- android:hardwareAccelerated="true"
- android:versionCode="1"
- android:versionName="1.0"
- android:windowSoftInputMode="adjustPan" >
- <supports-screens
- android:anyDensity="true"
- android:largeScreens="true"
- android:normalScreens="true"
- android:resizeable="true"
- android:smallScreens="true"
- android:xlargeScreens="true" />
- <uses-permission android:name="android.permission.CAMERA" />
- <uses-permission android:name="android.permission.VIBRATE" />
- <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
- <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
- <uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" />
- <uses-permission android:name="android.permission.INTERNET" />
- <uses-permission android:name="android.permission.RECEIVE_SMS" />
- <uses-permission android:name="android.permission.RECORD_AUDIO" />
- <uses-permission android:name="android.permission.RECORD_VIDEO" />
- <uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
- <uses-permission android:name="android.permission.READ_CONTACTS" />
- <uses-permission android:name="android.permission.WRITE_CONTACTS" />
- <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
- <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
- <uses-permission android:name="android.permission.GET_ACCOUNTS" />
- <uses-permission android:name="android.permission.BROADCAST_STICKY" />
- <application
- android:debuggable="true"
- android:hardwareAccelerated="true"
- android:icon="@drawable/ic_launcher"
- android:label="@string/app_name" >
- <activity
- android:name="com.myexample.helloworld.MainActivity"
- android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale"
- android:label="@string/app_name"
- android:theme="@android:style/Theme.Black.NoTitleBar" >
- <intent-filter>
- <action android:name="android.intent.action.MAIN" />
- <category android:name="android.intent.category.LAUNCHER" />
- </intent-filter>
- </activity>
- </application>
- <uses-sdk
- android:minSdkVersion="7"
- android:targetSdkVersion="17" />
- </manifest>
config.xml
- <?xml version="1.0" encoding="UTF-8"?>
- <!--
- Licensed to the Apache Software Foundation (ASF) under one
- or more contributor license agreements. See the NOTICE file
- distributed with this work for additional information
- regarding copyright ownership. The ASF licenses this file
- to you under the Apache License, Version 2.0 (the
- "License"); you may not use this file except in compliance
- with the License. You may obtain a copy of the License at
- http://www.apache.org/licenses/LICENSE-2.0
- Unless required by applicable law or agreed to in writing,
- software distributed under the License is distributed on an
- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- KIND, either express or implied. See the License for the
- specific language governing permissions and limitations
- under the License.
- -->
- <widget
- id="com.myexample.helloworld"
- version="2.0.0"
- xmlns="http://www.w3.org/ns/widgets" >
- <name>
- helloworld
- </name>
- <description>
- A sample Apache Cordova application that responds to the deviceready event.
- </description>
- <author
- email="dev@cordova.apache.org"
- href="http://cordova.io" >
- Apache Cordova Team
- </author>
- <access origin="*" />
- <!-- <content src="http://mysite.com/myapp.html" /> for external pages -->
- <content src="index.html" />
- <preference
- name="loglevel"
- value="DEBUG" />
- <!--
- <preference name="splashscreen" value="resourceName" />
- <preference name="backgroundColor" value="0xFFF" />
- <preference name="loadUrlTimeoutValue" value="20000" />
- <preference name="InAppBrowserStorageEnabled" value="true" />
- <preference name="disallowOverscroll" value="true" />
- -->
- <feature name="App" >
- <param
- name="android-package"
- value="org.apache.cordova.App" />
- </feature>
- <feature name="Geolocation" >
- <param
- name="android-package"
- value="org.apache.cordova.GeoBroker" />
- </feature>
- <feature name="Device" >
- <param
- name="android-package"
- value="org.apache.cordova.Device" />
- </feature>
- <feature name="Accelerometer" >
- <param
- name="android-package"
- value="org.apache.cordova.AccelListener" />
- </feature>
- <feature name="Compass" >
- <param
- name="android-package"
- value="org.apache.cordova.CompassListener" />
- </feature>
- <feature name="Media" >
- <param
- name="android-package"
- value="org.apache.cordova.AudioHandler" />
- </feature>
- <feature name="Camera" >
- <param
- name="android-package"
- value="org.apache.cordova.CameraLauncher" />
- </feature>
- <feature name="Contacts" >
- <param
- name="android-package"
- value="org.apache.cordova.ContactManager" />
- </feature>
- <feature name="File" >
- <param
- name="android-package"
- value="org.apache.cordova.FileUtils" />
- </feature>
- <feature name="NetworkStatus" >
- <param
- name="android-package"
- value="org.apache.cordova.NetworkManager" />
- </feature>
- <feature name="Notification" >
- <param
- name="android-package"
- value="org.apache.cordova.Notification" />
- </feature>
- <feature name="Storage" >
- <param
- name="android-package"
- value="org.apache.cordova.Storage" />
- </feature>
- <feature name="FileTransfer" >
- <param
- name="android-package"
- value="org.apache.cordova.FileTransfer" />
- </feature>
- <feature name="Capture" >
- <param
- name="android-package"
- value="org.apache.cordova.Capture" />
- </feature>
- <feature name="Battery" >
- <param
- name="android-package"
- value="org.apache.cordova.BatteryListener" />
- </feature>
- <feature name="SplashScreen" >
- <param
- name="android-package"
- value="org.apache.cordova.SplashScreen" />
- </feature>
- <feature name="Echo" >
- <param
- name="android-package"
- value="org.apache.cordova.Echo" />
- </feature>
- <feature name="Globalization" >
- <param
- name="android-package"
- value="org.apache.cordova.Globalization" />
- </feature>
- <feature name="InAppBrowser" >
- <param
- name="android-package"
- value="org.apache.cordova.InAppBrowser" />
- </feature>
- <!-- Deprecated plugins element. Remove in 3.0 -->
- <plugins>
- </plugins>
- </widget>
然后,就可以运行了
PhoneGap的官方方法不是这样的,是用命令行生成默认包的。但是要装好几个东西。具体可以看PhoneGap包里面的readme文档。
PhoneGap本地将html打包成安卓App的更多相关文章
- 将h5用HBuilderX打包成安卓app后,document.documentElement.scrollTop的值始终为0或者document.body.scrollTop始终为0
let time = setInterval(() => { let scroll = document.documentElement.scrollTop || document.body.s ...
- 将H5页面打包成安卓原生app
第一步:下载HBuilderX,新建项目选择5+App新建一个空项目如下图 新建后项目目录结构如下图 第二步,将你要打包成安卓app的文件打包,最后生成的文件目录如下图 1.打包完成后,将对应文件内容 ...
- HBuilderX打包成安卓或苹果app之后的调试问题,避免每次都要打包
一.使用VScode安装 Live Server插件 二.使用:安装成功后---->>新建一个index.html 写入内容如下图所示 注:href地址是你在电脑上启动该项目的访问地址(此 ...
- 项目打包成手机app 通过什么打包?
项目打包成手机app 通过什么打包? 1.HbuildX注册邮箱账号 2.新建-app,然后将自动生成的除manifest.json之外的所有文件删除,然后将vue项目build之后生成的dist文 ...
- 把H5打包成IOS APP其实可以很简单!签名?越狱?都不需要!
很多小伙伴都在开发自己的app, 有的实现实现比较简单,就是一个h5页面,然后想要打包成app发布出去. 这个想法很单纯 打包生成个app这个是很简单的,网上一堆打包工具,分分钟可以完成 BUT…… ...
- 搭建ionic3-angular5 开发环境并打包成安卓apk包教程
安装node.js 搭建ionic3-angular5 开发环境,首先查看本地电脑是否安装node环境,打开终端,输入 命令: node -v 没有去安装nodejs 网址:http://nodej ...
- 将python代码打包成一个app/exe
前言 打包的代码通常都需要写一个简单的界面,一般用PyQt来写.用PyQt写界面的方法请戳这里:PyQt5的安装及基本配置 PyQt5教程 python提供了几个用来打包的模块,主要有py2ap ...
- vue+hbuilder 打包成移动app
查看了很多网上写的改来改去都在手机上运行不起来,运行起来又是白屏:最后放弃,自己结合文档搞吧! 1. 项目目录下的config文件夹里的index.js文件中,将build对象下的assetsPubl ...
- pc端页面打包成安卓apk
一.phoneGap PhoneGap是一个采用HTML,CSS和JavaScript的技术,创建移动跨平台移动应用程序的快速开发平台.它使开发者能够在网页中调用IOS,Android,Palm,Sy ...
随机推荐
- 阿里云ECI如何6秒扩容3000容器实例?
引言 根据最新CNCF报告,有超过90%的用户在生产环境使用容器,并且有超过80%的用户通过Kubernetes管理容器.是不是我们的生产环境上了K8s就完美解决了应用部署的问题?IT界有句俗语,没有 ...
- 虚拟化与kvm
cpu指令级别 传统中操作系统运行于R0中称之为特权级别,直接与硬件进行交互. 应用程序运行于r3级别称之为低权限,无法与硬件直接进行交互.也就是说程序是运行于用户态,系统运行于内核态中. 虚拟化要解 ...
- Qt 窗口阴影效果的实现
前言 今天正好搞一下窗口的阴影,发现一篇文章写的真是不错.毫不犹豫滴转过来了,感谢作者分享. 转自:http://blog.sina.com.cn/s/blog_a6fb6cc90101eoop.ht ...
- 解决IntelliJ IDEA的Plugins无法访问Marketplace去下载插件
本文图文讲解如何解决IntelliJ IDEA的Plugins无法访问Marketplace去下载插件. 默认打开IDEA的Plugins会加载很久,最后什么也没加载出来. 这时我们可以给插件市场设置 ...
- oracle的 listagg() WITHIN GROUP () 行转列函数的使用
1.使用条件查询 查询部门为20的员工列表 -- 查询部门为20的员工列表 SELECT t.DEPTNO,t.ENAME FROM SCOTT.EMP t where t.DEPTNO ...
- 解决一个无聊的问题,如何处理Java用户在dos被收集信息时拷贝带换行符的文本信息造成的while的多次循环(java解决Scanner.next在接收用户输入时出现多个换行的形况)[解决方案一]
问题描述: 用户在dos窗口输入的时候(web项目不会出现这样的问题,所以这个问题日常碰不到),摁下回车时,Scanner对象的next()扫描用户输入的文本,后面就可以根据输入的字符串进行判断,并执 ...
- [loj2977]巧克力
先考虑第一个问题,即求最小的巧克力块数 将这张网格图建图(仅对$c_{i,j}\ne -1$的位置建点),即求点数最少的连通块(的点数)使得存在$k$个不同的$c_{i,j}$ (以下$c$仅用一维数 ...
- [bzoj1934]善意的投票
最小割,考虑最小割就是要将整张图分为两块,本题中就分别表示赞同和不赞同,那么首先一开始赞同的点向S连边,不赞同的点向T连边,如果这些点分到了另一边就要割掉这条边,朋友关系同理,连双向边同样表示分到两边 ...
- 一些需要记住的linux命令
1. 系统帮助命令 ----man 2. 数据同步写入磁盘 ----sync 3. 查找文件命令 ...
- 由于vue的for循环id并不严谨,提高id严谨性
如果后台没有传入id,我们拿到的数据没有id修改等操作不方便,如何拿到id呢 https://github.com/dylang/shortid 提供唯一id 插件的引入和使用: <templa ...