cordova相关
全局安装
npm install -g cordova
// 安装指定版本
npm install -g cordova@9.0.0
or
npm install -g cordova@8.1.2
创建项目
cordova create test
添加平台
cordova platform add android --save
// 指定版本
cordova platform add android@6.3.0 --save
调试
cordova run android
打包
cordova build android
andorid studio build 报错:Invalid escape sequence at line 1 column 29 path $[0].name
修改gradle.properties
org.gradle.jvmargs=-Dfile.encoding=UTF-8
拷贝www文件到平台中
cordova prepare
插件
安装
cordova plugin add xxx
移除
cordova plugin remove xxx
常见问题
报错java.util.concurrent.ExecutionException: com.android.ide.common.process.ProcessException:
or
Execution failed for task ':mergeDebugResources'.
去除掉PNG合法性检测
根目录\platforms\android\build.gradle
android {
aaptOptions.cruncherEnabled = false
aaptOptions.useNewCruncher = false
...
}
viewport无效问题
根目录\platforms\android1\src\io\cordova\hellocordova\MainActivity.java
package io.cordova.hellocordova;
import android.os.Bundle;
import org.apache.cordova.*;
//WebView
import android.webkit.WebView;
public class MainActivity extends CordovaActivity
{
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
// enable Cordova apps to be started in the background
Bundle extras = getIntent().getExtras();
if (extras != null && extras.getBoolean("cdvStartInBackground", false)) {
moveTaskToBack(true);
}
// Set by <content src="index.html" /> in config.xml
loadUrl(launchUrl);
//WebView
WebView webView = (WebView) appView.getEngine().getView();
webView.getSettings().setLoadWithOverviewMode(true);
webView.getSettings().setUseWideViewPort(true);
}
}
变更环境cordova 打包 找不到sdk
修改/platforms/android/local.properties文件
sdk.dir=D:\\soft\\android-resources\\sdk