Detailed explanation of how to package cordova into webapp

小云云
Release: 2018-01-09 14:35:40
Original
3061 people have browsed it

This article mainly introduces the detailed method of packaging cordova into webapp. It has certain reference value. Interested friends can refer to it. I hope it can help everyone.

In project development, the h5 page needs to be packaged into an app. At this time, we can use cordova to package. From the official documentation, we can learn that creating an app is very simple. You only need nodejs on your computer. We can follow the official documentation step by step to add the Android platform and iOS platform. After the entire project structure is built, we can stuff all the webapp pages we need to package into the project structure. The next step is the troublesome part, how to carry out platform development, that is, how to package our project into an installable file.

1: Set environment variables:

1. Set the JAVA_HOME environment variable and specify it as the JDK installation path

2. Set the ANDROID_HOME environment variable and specify Install path for Android SDK

3. Also add the tools and platform-tools directories of Android SDK to your PATH

What needs to be noted here is to set the ANDROID_HOME environment variable, we You can install android studio into our computer. During the installation process, android studio will automatically install the Android SDK into our computer. Just remember this address at this time, as shown in the figure (the path in the line below is the Android SDK) :

2: When reporting this error: Error: Minimum supported Gradle version is xxxx. Current version is xxxx.

I was packaging at that time This error was reported at some time. I found the reason on the Internet. It is because android studio has updated the version of Gradle. The steps to solve this problem are as follows:

1: Open android studio, find setting, search for gradle, as shown in the figure Settings (specific paths vary):

3: Windows cordova build Error: Could not find gradle wrapper within Android SDK. Might need to update

Solution Method:

  1. Download Android SDK tools package (https://dl.google.com/android/repository/tools_r25.2.3-windows.zip)

  2. Enter the C:\Users\\AppData\Local\Android\sdk directory

  3. Back up the tools directory

  4. Put the compressed package into Unzip the tools directory into this directory

  5. Enter the project directory and run "cordova build android" again.

Four: Error when installing cordova-plugin-splashscreen:

The possible reason at this time is that you have already packaged the apk file, and you need to delete the apk file, and then Install again.

5: Problems encountered when packaging vue projects

1: Where to package using npm run build?

As shown in the picture, Qianne is the name of my vue project. I opened the dos window in this folder, and then created an app framework named myApp1. Then I modified the index.js in the config:

index: path.resolve(__dirname, '../myApp1/www/index.html'), assetsRoot: path.resolve(__dirname, '../myApp1/www'), assetsSubDirectory: 'static', assetsPublicPath: './',
Copy after login

The path here directly points to the www folder under myApp1. Then we run npm run build in the vue project. At this time, we placed the packaged files directly in the www folder under myApp1. At this time we also need to put the

cordova.js and cordova_plugins.js files into the www folder, at the same level as index.html. (Remember that index.html will be overwritten at this time. We need to copy the code that refers to cordova.js in index.html to the packaged index.html).

2: Directly open the packaged index.html, but the routing does not work?

My solution:

Find the main.js in the vue project and change the mode of the routing code to "hash". I used to use "history" so the routing has been useless.

const router = new VueRouter({ mode: 'hash', routes })
Copy after login

After that, we will package it again. If the packaged index.html is routed normally after opening, congratulations. At this time, we enter the dos window under myApp1, enter cordova build android, and package it into an apk file.

6: Where should the app’s logo startup page be placed?

In the project structure, we need to install the splashscreen plug-in:

cordova plugin add cordova-plugin-splashscreen
Copy after login

We insert the following code in config.xml:

                                                      
Copy after login

Similarly, we need to put the corresponding logo or picture in the corresponding folder under the res folder.

Related recommendations:

How to develop WebAppDemo based on WebStorm, React and Ant.Design

javascript - How does webapp development determine whether a user message has been read or unread

webapp External css reference_html/css_WEB-ITnose

The above is the detailed content of Detailed explanation of how to package cordova into webapp. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!