首页 > 其他分享 >PhoneGap2.9.0本地将html打包成Android应用

PhoneGap2.9.0本地将html打包成Android应用

时间:2023-01-04 13:37:01浏览次数:60  
标签:name package html apache org Android cordova PhoneGap2.9 android


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


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


下载安装Java环境。


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

PhoneGap2.9.0本地将html打包成Android应用_xml


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

PhoneGap2.9.0本地将html打包成Android应用_apache_02


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

PhoneGap2.9.0本地将html打包成Android应用_PhoneGap_03


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

PhoneGap2.9.0本地将html打包成Android应用_PhoneGap_04


这里可以选择图标。

PhoneGap2.9.0本地将html打包成Android应用_PhoneGap_05


选择第一个

PhoneGap2.9.0本地将html打包成Android应用_xml_06

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


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

PhoneGap2.9.0本地将html打包成Android应用_apache_07

PhoneGap2.9.0本地将html打包成Android应用_apache_08


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

PhoneGap2.9.0本地将html打包成Android应用_android_09

PhoneGap2.9.0本地将html打包成Android应用_xml_10


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

PhoneGap2.9.0本地将html打包成Android应用_android_11

PhoneGap2.9.0本地将html打包成Android应用_xml_12


修改Java代码:

PhoneGap2.9.0本地将html打包成Android应用_xml_13


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="[email protected]"
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>


然后,就可以运行了

PhoneGap2.9.0本地将html打包成Android应用_PhoneGap_14

PhoneGap2.9.0本地将html打包成Android应用_apache_15


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

标签:name,package,html,apache,org,Android,cordova,PhoneGap2.9,android
From: https://blog.51cto.com/u_15929643/5988306

相关文章

  • unity3d,android平台下,高德地图搜索附近
    今天把高德地图androidsdk搜索附近的功能搞定了。和定位一样,引入jar,AndroidManifest.xml和定位的一样,没有需要修改的地方。改的多的是Java插件。原java示例代码中,query=n......
  • unity3d,android平台下,高德地图定位
    这里,用了一个比较偷懒的办法,直接用高德提供的android定位sdk,没有重新编译。好处是省事,坏处是,没法修改默认的定位模式。部分信息获取不到。如果需要完整的功能,还是需要重新编......
  • self hosted private support chat software use JavaScript remove HTML tags
    ThemainreasonforremovingHTMLtagsinonlinecustomerservicesystemsistopreventmalicioususersfromattackingthewebsiteorotherusersbyinputting......
  • html5打包成移动平台应用的工具的大致情况
    首先说,日期很重要,这是2013年5月24日做的简单调查。题外话,之前做网站维护,职位设置太坑爹了,于是改行做移动平台开发,主要方向是用html5打包成移动应用。首先声明,在下的英文水平......
  • 在线客服系统中javascript 源码实现除去html标签
    在线客服系统中除去HTML标签的主要原因是为了防止恶意用户通过输入恶意的HTML代码来攻击网站或其他用户。例如,如果你不过滤用户输入的HTML,一个恶意用户可能会输入下面这段......
  • html css 学成在线综合案例
    html部分<!DOCTYPEhtml><htmllang="en"><head><metacharset="UTF-8"><metahttp-equiv="X-UA-Compatible"content="IE=edge"><metaname="viewport"conten......
  • Android笔记--如何在Android studio里面打开数据库
    具体操作1、找到界面内的DeviceFileExplorer这里找可以;这里直接打开也行2、在里面找到与java下面的第一个package名称相同的文件夹3、找到下面的databases会看......
  • Android笔记--修改Device File Explorer的文件打开方式
    在首次打开该文件时,不小心选错了打开方式,导致以后每次打开也是同样的打开方式,也不会弹出第一次那样的打开方式的选择弹窗在这里提供修改文件的默认打开方式的方法:首先通......
  • Android笔记--基础的连接数据库的操作
    start.javapackagecom.example.myapplication;importandroidx.activity.result.ActivityResult;importandroidx.activity.result.ActivityResultCallback;importa......
  • Android学习day03【跑马灯】
    这个学习内容很简单,说一下自己笨蛋的点吧要实现这种情况,我始终没有办法实现  后来发现(你先别说话,我知道很傻,但是大话先别说太早)android:layout_width="wrap_cont......