2018年6月1日 星期五

cordova 筆記

[Android 模擬器] Genymotion
https://www.genymotion.com/account/create/
tomz50/tomz10750

tomz50@gmail.com


----
1.安裝 node.js / node-v8.11.1-x64
2.安裝 java.jdk 1.8版本
3.設PATH 路徑參數
2.安裝 apache-ant / 解壓 apache-ant-1.9.11-bin.zip 到 d:\apache-ant 資料夾
5.建立cordova環境,導入專案
6.建立android studio 裡的模擬器環境
7.將要編譯成APK的完整網頁(含HTML/CSS/IMAGES),複製到 D:\cordova\blogapp\www\ 資料夾
8.D:\cordova\blogapp>cordova build android 進行編譯成APK
9.將 D:\cordova\blogapp\platforms\android\app\build\outputs\apk\debug\app-debug.apk
拖曳到模擬器執行

10. create/add/build --> 生成apk -> 丟到模擬器RUN
11. cordova 步驟 :

(1)D:\cordova>cordova create myapp com.macroviz.myapp myapp
(2)D:\cordova\myapp>cordova platform add android
(3)D:\cordova\myapp>cordova build android

www 存放位置 : D:\cordova\myapp\www
apk 存放位置 : D:\cordova\myapp\platforms\android\app\build\outputs\apk\debug

----

ANDROID_HOME   C:\Users\user\AppData\Local\Android\sdk
ANT_HOME D:\apache-ant-1.9.7
JAVA_HOME C:\Program Files\Java\jdk1.8.0_171


PATH=
C:\Program Files (x86)\Common Files\Oracle\Java\javapath;
C:\Program Files\Java\jdk1.8.0_171\bin;
C:\Program Files\nodejs\;D:\javaScript\apache-ant-1.9.7\bin;
C:\Users\user\AppData\Local\Android\sdk\tools;
C:\Users\user\AppData\Local\Android\sdk\platform-tools;
D:\apache-ant-1.9.11\bin



cordova -v 版本
ant -version

cordova 只支援JAVA 1.8版本,先移除較新的版本,安裝1.8版
D:\cordova\blogapp>java -version
java version "1.8.0_171"
Java(TM) SE Runtime Environment (build 1.8.0_171-b11)
Java HotSpot(TM) 64-Bit Server VM (build 25.171-b11, mixed mode)



C:\Program Files\Java\jdk-10\bin;
C:\nodejs\;
%ANT_HOME%\bin;
%ANDROID_HOME%\tools;
%ANDROID_HOME%\platform-tools;


set path=
C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\ProgramData\Oracle\Java\javapath;C:\Program Files (x86)\Intel\iCLS Client\;C:\Program Files\Intel\iCLS Client\;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files\Java\jdk-10\bin;%ANT_HOME%\bin;%ANDROID_HOME%\tools;%ANDROID_HOME%\platform-tools;C:\xampp\php;C:\ProgramData\ComposerSetup\bin;D:\apache-ant-1.9.11\bin;C:\nodejs\;C:\Users\Administrator\AppData\Roaming\npm\node_modules\cordova\bin;C:\Program Files\Java\jdk1.8.0_171



移到你想建立專案的目錄下。
使用指令建立專案,建立在目前的位置上。
建立一個 D:\cordova\ 資料夾

**一定要在 D:\cordova 資料夾下執行以下指令
D:\cordova>cordova create myapp com.macroviz.myapp myapp
Creating a new cordova project.


會建立一個 D:\cordova\blogapp\ 資料夾

將專案加入平台,平台指的是你的App之後要執行在哪,以Android為例,使用指令完成。
cordova platform add android

為專案加入作業系統台
**一定要在 D:\cordova\blogapp 資料夾下執行以下指令
D:\cordova\blogapp>cordova platform add android         
Using cordova-fetch for cordova-android@~7.0.0
Adding android project...
Creating Cordova project for the Android platform:
        Path: platforms\android
        Package: com.macroviz.blogapp
        Name: blogapp
        Activity: MainActivity
        Android target: android-26
Subproject Path: CordovaLib
Subproject Path: app
Android project created with cordova-android@7.0.0
Android Studio project detected
Android Studio project detected
Discovered plugin "cordova-plugin-whitelist" in config.xml. Adding it to the project
Installing "cordova-plugin-whitelist" for android

               This plugin is only applicable for versions of cordova-android greater t
han 4.0. If you have a previous platform version, you do *not* need this plugin since t
he whitelist will be built in.

Adding cordova-plugin-whitelist to package.json
Saved plugin info for "cordova-plugin-whitelist" to config.xml
--save flag or autosave detected
Saving android@~7.0.0 into config.xml file ...

D:\cordova\blogapp>cordova platform rm android
Removing platform android from config.xml file...
Removing android from cordova.platforms array in package.json




生成Android專案
D:\cordova\blogapp>cordova build android
.....
:app:cdvBuildDebug

BUILD SUCCESSFUL in 20m 33s
47 actionable tasks: 47 executed
Built the following apk(s):
        D:\cordova\blogapp\platforms\android\app\build\outputs\apk\debug\app-debug.apk

Regular Expression 正則表示式做字串比對

Regular Expression 中文翻成正則表示式 英文簡寫為 Regex 或 RegExp RegExp 是用來比對字串是不是有符合正確的格式 語法很簡單而且大部分語言都有支援它 使用時機 譬如說你需要在程式內請使用者輸入生日 你規定的格式 1996-08...