1.创建vue项目
2.进入vue项目,用cordova创建android和iOS平台项目
直接操作,不会影响到原来的vue项目的
npm install -g cordova
cordova create mobilephone com.myproject myproject
cd mobilephone
cordova platform add ios
cordova platform add android
cordova run ios
cordova run android
参考: # Vue 全家桶 + Electron 开发的一个跨三端的应用
2.提示没有安装Gradle
一种方案是自己下载下来,在系统路径中添加
一种方案是直接用AndroidStudio下载,然后把AndroidStudio中的Gradle添加到路径中
Checking Java JDK and Android SDK versions
ANDROID_SDK_ROOT=/Users/evilcode/Library/Android/sdk (recommended setting)
ANDROID_HOME=/Users/evilcode/Library/Android/sdk (DEPRECATED)
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
解决方案,把grandle的路径添加到PATH中,下方添加的是MAC下的AndroidStudio中安装的gradle
export GRADLE=/Applications/Android\Studio.app/Contents/gradle/<gradle-4.*>
export PATH="$PATH:$GRADLE/bin"
参考: https://blog.csdn.net/u013634213/article/details/51120783
如果遇到报错如下,表示这一样有语法错误
-bash: /Applications/Android: No such file or directory
注意点: 因为使用的是Android/Studio.app
,添加转义字符\后,去掉后面的空格,就不会报错了
参考: https://apple.stackexchange.com/questions/94679/how-do-cope-with-a-space-when-setting-the-path
3.Command failed with exit code EACCES
Checking Java JDK and Android SDK versions
ANDROID_SDK_ROOT=/Users/evilcode/Library/Android/sdk (recommended setting)
ANDROID_HOME=/Users/evilcode/Library/Android/sdk (DEPRECATED)
Subproject Path: CordovaLib
Subproject Path: app
/Users/evilcode/Documents/vue/oil-system/mobilephone/platforms/android/gradlew: Command failed with exit code EACCES
使用日志命令
cordova build android --verbose
4.运行一直有错误,检查缺少的配置
cordova requirements
缺少的内容,基本上Android Studio都会自动下载
5.报错Command failed with exit code EACCES
your_error_path/platforms/android/gradlew: Command failed with exit code EACCES
解决方案,把gradlew目录的权限设置为可写就可以了
// "platforms/android/gradlew". Tried running chmod on "gradlew" directory and that worked!
chmod a+x your_error_path/platforms/android/gradlew