Basic tutorial for getting started with cordova
This article mainly introduces you to the basic introductory tutorial on cordova and some problems encountered in its use. The article introduces it step by step through sample code in very detail. It has certain reference learning value for everyone's study or work. It needs Friends, please follow the editor to learn together. Hope it helps everyone.
Preface
In order to save money and succeed in projects now, adapting to multi-platform cordova is not a good choice. Personally I think it may be a trend in the future! Many well-known APPs such as Alipay and Taobao have integrated a large number of HTML5 pages! For example, most of our company's current apps are h5 pages, and it feels like there is nothing much to do in the native version. One can imagine the importance of learning cordova!
Introduction
Cordova provides a set of device-related APIs. Through this set of APIs, mobile applications can access native device functions, such as cameras, microphones, etc., using JavaScript. Cordova also provides a unified set of JavaScript libraries, as well as device-specific native code backends for these libraries. Cordova supports the following mobile operating systems: iOS, Android, ubuntu phone os, Blackberry, Windows Phone, Palm WebOS, Bada and Symbian.
The first step to get started: Download the resource library and integrate it into the project
To download the source code of the cordova library, you can download it from github or from the official website. In fact, the code on the official website is also posted on github!
Official website: http://cordova.apache.org/
github resource download address: https://github.com/apache/cordova-ios
Use For CocoaPods management of third-party libraries, I used cordova3.8.0 before and updated it to 4.0.1 a few days ago. 4.0.1 only supports 8.0 and above. If you use CocoaPods to update below, an error will be prompted! Just pay attention!
platform :ios, '8.0'
pod 'Cordova', '~> 4.0.1'
Step 2 of getting started: How to integrate correctly in the project cordova4.0.1 library
1. Configuration Config.xml is very important
Config.xml is a global configuration file that controls many aspects of a cordova application's behavior. This platform-agnostic XML file is arranged based on the W3C'sPackaged Web Apps (Widgets) specification, and extended to specify core Cordova API features, plugins, and platform-specific settings. For projects created with the Cordova CLI (described in The Command-Line Interface), this file can be found in the top-level directory:
The general meaning is: config.xml is a global configuration file that controls many aspects of a cordova application behavior. This platform-agnostic XML file is based on the W3C's packaged web application settings (widgets) specification and extends to specify core Cordova API functionality, plugins, and platform-specific settings. Project created with Cordova CLI (described in the command line interface)
http://cordova.apache.org/docs/en/6.x/config_ref/index.html Official detailed explanation
2. Displaying html5 pages requires a container. Here, the CDVViewController class is used to display and control html5. Of course, you can also customize a container to inherit the CDVViewController class to do some customized functions.
How to use is as follows:
self.cordovaManageVC= [[CordovaManageVCalloc]init]; self.cordovaManageVC.startPage=@"http://www.baidu.com"; [self.navigationControllerpushViewController:self.cordovaManageVCanimated:YES];
3. Set the user agent
- (instancetype)init { self= [superinit]; if(self!=nil) { //设置用户代理 如不设置无法调用与H5定制的JavaScript方法进行交互 NSString* original = [CDVUserAgentUtiloriginalUserAgent]; NSString* userAgent = [originalstringByAppendingString:@"delegateUserName"]; self.baseUserAgent= userAgent; } returnself; }
4. Custom plug-ins need to use the CDVPlugin class of cordova and use subclasses to integrate CDVPlugin
/** *返回控件 * *@param command */ - (void)back:(CDVInvokedUrlCommand*)command;
After the customization is completed, you need to configure it in confing.xml
The above is the most basic usage of cordova;
Some things encountered when using Cordova Problem
Problem one
Problem
[Error: Failed to find 'ANDROID_HOME' environment variable. Try setting setting it manually. Failed to find 'android' command in your 'PATH'. Try update your 'PATH' to inclde path to valid SDK directory.] ERROR building one of the platforms: Error: cmd: Command failed with exit code
Solution
ANDROID_HOME=D:\apps\Android\sdk PATH=%PATH%;%ANDROID_HOME%\tools;%ANDROID_HOME%\platform-tools
Problem two
Problem
Error: Could not find an installed version of Gradle either in Android Studio, or on your system to install the gradle wrapper. Please include gradle in your path, or install Android Studio
Solution
Download the latest gradle package from https://services.gradle.org/distributions/ and install it.
ANDROID_HOME=/home/kongxx/Android/Sdk GRADLE_HOME=/apps/gradle-3.2.1 PATH=$PATH:$ANDROID_HOME/tools/:$ANDROID_HOME/platform-tools:$GRADLE_HOME/bin
Question 3
Question
When using "cordova build android" to package, an error is reported: Error: Could not find gradle wrapper within Android SDK.
$ cordova build android CHCP plugin after prepare hook: config-file set to http://www.tjdr.info/EWT/chcp.json ANDROID_HOME=/home/kongxx/Android/Sdk JAVA_HOME=/opt/jdk8 Error: Could not find gradle wrapper within Android SDK. Might need to update your Android SDK. Looked here: /home/kongxx/Android/Sdk/tools/templates/gradle/wrapper
Solution
Checked the /home/kongxx/Android/Sdk/tools/templates/gradle/wrapper directory. The directory did not exist, so I checked the android-studio environment and found that it can be found in plugins/android The /lib/templates directory contains the above content, so copy it decisively.
$ cp -rf android-studio/plugins/android/lib/templates /home/kongxx/Android/Sdk/tools/
Problem 4
Problem
Error when using Cordova packaging: Error: spawn EACCES
$ cordova build android CHCP plugin after prepare hook: config-file set to http://www.tjdr.info/EWT/chcp.json ANDROID_HOME=/home/kongxx/Android/Sdk JAVA_HOME=/opt/jdk8 Subproject Path: CordovaLib Error: spawn EACCES
Solution
sudo chmod -Rf 755 ~/Android
Problem 5
Problem
When using the browser test in cordova, the google-chrome browser is started by default, such as:
cordova run browser
Solution
You can use –target to specify the browser you want to use.
cordova run browser --target=opera cordova run browser --target=firefox
Related recommendations:
How Cordova packages Vue projects
Detailed explanation of the method of packaging cordova into webapp
The above is the detailed content of Basic tutorial for getting started with cordova. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



Diffusion can not only imitate better, but also "create". The diffusion model (DiffusionModel) is an image generation model. Compared with the well-known algorithms such as GAN and VAE in the field of AI, the diffusion model takes a different approach. Its main idea is a process of first adding noise to the image and then gradually denoising it. How to denoise and restore the original image is the core part of the algorithm. The final algorithm is able to generate an image from a random noisy image. In recent years, the phenomenal growth of generative AI has enabled many exciting applications in text-to-image generation, video generation, and more. The basic principle behind these generative tools is the concept of diffusion, a special sampling mechanism that overcomes the limitations of previous methods.

Kimi: In just one sentence, in just ten seconds, a PPT will be ready. PPT is so annoying! To hold a meeting, you need to have a PPT; to write a weekly report, you need to have a PPT; to make an investment, you need to show a PPT; even when you accuse someone of cheating, you have to send a PPT. College is more like studying a PPT major. You watch PPT in class and do PPT after class. Perhaps, when Dennis Austin invented PPT 37 years ago, he did not expect that one day PPT would become so widespread. Talking about our hard experience of making PPT brings tears to our eyes. "It took three months to make a PPT of more than 20 pages, and I revised it dozens of times. I felt like vomiting when I saw the PPT." "At my peak, I did five PPTs a day, and even my breathing was PPT." If you have an impromptu meeting, you should do it

In the early morning of June 20th, Beijing time, CVPR2024, the top international computer vision conference held in Seattle, officially announced the best paper and other awards. This year, a total of 10 papers won awards, including 2 best papers and 2 best student papers. In addition, there were 2 best paper nominations and 4 best student paper nominations. The top conference in the field of computer vision (CV) is CVPR, which attracts a large number of research institutions and universities every year. According to statistics, a total of 11,532 papers were submitted this year, and 2,719 were accepted, with an acceptance rate of 23.6%. According to Georgia Institute of Technology’s statistical analysis of CVPR2024 data, from the perspective of research topics, the largest number of papers is image and video synthesis and generation (Imageandvideosyn

After rain in summer, you can often see a beautiful and magical special weather scene - rainbow. This is also a rare scene that can be encountered in photography, and it is very photogenic. There are several conditions for a rainbow to appear: first, there are enough water droplets in the air, and second, the sun shines at a low angle. Therefore, it is easiest to see a rainbow in the afternoon after the rain has cleared up. However, the formation of a rainbow is greatly affected by weather, light and other conditions, so it generally only lasts for a short period of time, and the best viewing and shooting time is even shorter. So when you encounter a rainbow, how can you properly record it and photograph it with quality? 1. Look for rainbows. In addition to the conditions mentioned above, rainbows usually appear in the direction of sunlight, that is, if the sun shines from west to east, rainbows are more likely to appear in the east.

We know that LLM is trained on large-scale computer clusters using massive data. This site has introduced many methods and technologies used to assist and improve the LLM training process. Today, what we want to share is an article that goes deep into the underlying technology and introduces how to turn a bunch of "bare metals" without even an operating system into a computer cluster for training LLM. This article comes from Imbue, an AI startup that strives to achieve general intelligence by understanding how machines think. Of course, turning a bunch of "bare metal" without an operating system into a computer cluster for training LLM is not an easy process, full of exploration and trial and error, but Imbue finally successfully trained an LLM with 70 billion parameters. and in the process accumulate

1. First open WeChat. 2. Click [+] in the upper right corner. 3. Click the QR code to collect payment. 4. Click the three small dots in the upper right corner. 5. Click to close the voice reminder for payment arrival.

Editor of the Machine Power Report: Yang Wen The wave of artificial intelligence represented by large models and AIGC has been quietly changing the way we live and work, but most people still don’t know how to use it. Therefore, we have launched the "AI in Use" column to introduce in detail how to use AI through intuitive, interesting and concise artificial intelligence use cases and stimulate everyone's thinking. We also welcome readers to submit innovative, hands-on use cases. Video link: https://mp.weixin.qq.com/s/2hX_i7li3RqdE4u016yGhQ Recently, the life vlog of a girl living alone became popular on Xiaohongshu. An illustration-style animation, coupled with a few healing words, can be easily picked up in just a few days.

Retrieval-augmented generation (RAG) is a technique that uses retrieval to boost language models. Specifically, before a language model generates an answer, it retrieves relevant information from an extensive document database and then uses this information to guide the generation process. This technology can greatly improve the accuracy and relevance of content, effectively alleviate the problem of hallucinations, increase the speed of knowledge update, and enhance the traceability of content generation. RAG is undoubtedly one of the most exciting areas of artificial intelligence research. For more details about RAG, please refer to the column article on this site "What are the new developments in RAG, which specializes in making up for the shortcomings of large models?" This review explains it clearly." But RAG is not perfect, and users often encounter some "pain points" when using it. Recently, NVIDIA’s advanced generative AI solution
