Angular、ionic、Cordova的关系介绍与打包

一、关系介绍

Angular:是一个前端JS框架,类似于JQuery,BootStrap,Three.js等。

ionic :是开源的H5移动App开发框架,是Angular的衍生物,利用Angular实现很多移动端的组件。

Cordova:在项目中,Cordova负责将前端页面包装成原生页面,作为一个桥梁负责前端页面与原生应用的通信。另外,前端页 面没有调用设备的能力,这时就需要与原生应用通信来,通过cordova插件调用设备,例如相机,文件等。

二、打包

    1.常用命令

            ionic serve

            ionic cordova build android    #打包

            cordova platform rm android    #移除项目中的android环境

            cordova platform add [email protected]    #添加安装环境,@xxx是安卓版本号

            cordova platforms list    #列出项目环境

            ionic cordova plugin list    #列出项目中安装的插件

            cordova plugin remove  XXX    #卸载插件

            cordova plugin add XXX    #安装插件

       2.项目中的环境配置

               cordova platforms list


可以看出,项目中的安卓环境是android6.3.0

cordova plugins list


项目中所安装的插件,其中最重要的是cordova-plugin-camera,cordova-plugin-file,cordova-plugin-transfer这三个插件,是拍照,以及上传图片功能所用到的插件,在后面详细介绍

3.上传图片插件安装

不管是从相册中选择图片上传,还是拍照上传。我们都需要如下先安装如下三个插件:Camera(相机)、file(文件访问操作)、fileTransfer(文件传输)。

cordova plugin add cordova-plugin-camera
cordova plugin add cordova-plugin-file
cordova plugin add cordova-plugin-file-transfer

在cordova插件中有一个插件:cordova-

-image-picker,在安卓中选择图片上传会出现闪退现象,解决方法很简单

cordova plugin remove com.synconset.imagepicker #删除这个插件

npm install git      #npm安装git,详情见http://blog.csdn.net/yiifaa/article/details/53784427

cordova plugin add https://github.com/Findiglay/cordova-imagePicker.git    #从git上安装一个修复过的plugin

上传图片搞定。。。

有一段时间在ionic cordova build android打包的过程中(安装环境是6.3.0),会报如下错误

BUILD FAILED
 
Total time: 19.142 secs
ERROR: In <declare-styleable> FontFamilyFont, unable to find attribute android:ttcIndex
 
 
FAILURE: Build failed with an exception.
 
* What went wrong:
Execution failed for task ':processDebugResources'.
> com.android.ide.common.process.ProcessException: Failed to execute aapt
 
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
Error: cmd: Command failed with exit code 1 Error output:
ERROR: In <declare-styleable> FontFamilyFont, unable to find attribute android:fontVariationSettings
ERROR: In <declare-styleable> FontFamilyFont, unable to find attribute android:ttcIndex
 
 
FAILURE: Build failed with an exception.
 
* What went wrong:
Execution failed for task ':processDebugResources'.
> com.android.ide.common.process.ProcessException: Failed to execute aapt
 
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
 
[ERROR] An error occurred while running cordova build android (exit code 1).

解决办法是在platforms/android/build.gradle中顶级节点加入

configurations.all {
    resolutionStrategy {
        force 'com.android.support:support-v4:27.1.0'
    }
}


猜你喜欢

转载自blog.csdn.net/nuoWei_SenLin/article/details/79532265