文档 文档 文档

node v8.11.1
npm 5.6.0
cordova 8.0.0

一、cordova
cd /d E:\mapp\qyjg
cordova create cordova com.stbc.qyjg 区域监管
cd cordova
cordova platform add android
cordova plugin add cordova-plugin-camera

备注:
npm uninstall -g cordova
删除E:\Users\Administrator\AppData\Roaming\nvm\v8.11.1\node_modules\cordova
npm install -g cordova@6.5
npm install -g cordova@latest
注意:安装cordova不能用cnpm,否则创建项目会失败!!!

常用命令:
cordova platform remove android
cordova plugin rm cordova-plugin-baidumaplocation

二、react
cd ..
dva new react
cd react
cnpm install antd-mobile --save
cnpm install dva-loading --save
cnpm install babel-plugin-import --save
cnpm install leaflet --save
cnpm install react-leaflet --save
npm install leaflet-easybutton --save
npm install coordtransform --save
cnpm install rc-form --save


npm start

cnpm install eslint-config-prettier --save-dev
cnpm install eslint-config-airbnb --save-dev
cnpm install stylelint-config-standard --save-dev
cnpm install stylelint-config-prettier --save-dev


三、其他
设断点调试:
chrome://inspect/#devices

https://github.com/litehelpers/Cordova-sqlite-storage#readme
https://github.com/gregallensworth/L.TileLayer.Cordova


定位:
百度sdk https://blog.csdn.net/u010730897/article/details/52055802
更换为:https://github.com/aruis/cordova-plugin-baidumaplocation

四、签名
(1)生成秘钥:
cd /d E:\Program Files\Java\jdk1.8.0_172\bin
keytool -genkey -v -keystore C:\release-key.keystore -alias qyjg -keyalg RSA -keysize 2048 -validity 20000
秘钥库密码:stbc..
组织单位:珠江水利委员会珠江流域水土保持监测中心站
秘钥口令:stbc..

(2)在cordova根目录放置release-key.keystore和build.json
build.json文件内容:
{
    "android": {
        "debug": {
            "keystore": "release-key.keystore",
            "storePassword": "stbc..",
            "alias": "qyjg",
            "password" : "stbc..",
            "keystoreType": ""
        },
        "release": {
            "keystore": "release-key.keystore",
            "storePassword": "stbc..",
            "alias": "qyjg",
            "password" : "stbc..",
            "keystoreType": ""
        }
    }
}

另一个key,qyjg的地方换成xmjg同样操作

(3)获取SHA1
keytool -v -list -keystore c:/release-key.keystore
得到SHA1: C8:10:47:90:5A:F7:AE:0F:3E:C1:92:71:DF:95:EE:B0:F8:56:A8:CB

五、申请百度地图Android key
http://lbsyun.baidu.com/apiconsole/key
发布版SHA1:C8:10:47:90:5A:F7:AE:0F:3E:C1:92:71:DF:95:EE:B0:F8:56:A8:CB
开发版SHA1:BF:98:B2:4E:4A:C3:C0:D9:1F:1C:4D:FF:84:AE:07:AC:0B:A3:C6:F2
包名:com.stbc.qyjg
申请得到的Key:HEG5iGepE9a12tH4yqAXhL7GFW64XLkl

六、添加插件,config.xml找不到
https://github.com/aruis/cordova-plugin-baidumaplocation
cordova plugin add cordova-plugin-baidumaplocation --variable ANDROID_KEY="HEG5iGepE9a12tH4yqAXhL7GFW64XLkl" --variable IOS_KEY="<API_KEY_IOS>"

编译出现bug:
Parsing E:\mapp\qyjg\cordova\platforms\android\res\xml\config.xml failed(node:10988) UnhandledPromiseRejectionWarning: Error: ENOENT: no such file or directory, open 'E:\mapp\qyjg\cordova\platforms\android\res\xml\config.xml'

原因分析:
E:\mapp\qyjg\cordova\platforms\android下多了libs文件夹,导致判断错误
E:\mapp\qyjg\cordova\platforms\android\cordova\lib\AndroidStudio.js中var eclipseFiles = ['AndroidManifest.xml', 'libs', 'res'];

解决方案:
添加hook
<platform name="android">
        <hook src="scripts/patch-android-studio-check.js" type="before_plugin_add" />
        <hook src="scripts/patch-android-studio-check.js" type="before_plugin_install" />
        <hook src="scripts/patch-android-studio-check.js" type="before_plugin_rm" />
        <hook src="scripts/patch-android-studio-check.js" type="before_plugin_uninstall" />
        <hook src="scripts/patch-android-studio-check.js" type="before_prepare" />
</platform>

patch-android-studio-check.js内容如下:
/**
 * This hook overrides a function check at runtime. Currently, cordova-android 7+ incorrectly detects that we are using
 * an eclipse style project. This causes a lot of plugins to fail at install time due to paths actually being setup
 * for an Android Studio project. Some plugins choose to install things into 'platforms/android/libs' which makes
 * this original function assume it is an ecplise project.
 */
module.exports = function(context) {
  if (context.opts.cordova.platforms.indexOf('android') < 0) {
    return;
  }

  const path = context.requireCordovaModule('path');
  const androidStudioPath = path.join(context.opts.projectRoot, 'platforms/android/cordova/lib/AndroidStudio');
  const androidStudio = context.requireCordovaModule(androidStudioPath);
  androidStudio.isAndroidStudioProject = function() {  return true; };
};


参考:
https://gist.github.com/joeljeske/68121fa6d643e0937f50458d0172e16e
http://cordova.apache.org/announcements/2017/12/04/cordova-android-7.0.0.html

七、Java包引用编译错误
修改:
    <platform name="android">
        <source-file src="src/android/BaiduMapLocation.java" target-dir="src/com/aruistar/cordova/baidumap"/>
        <source-file src="libs/android/armeabi/liblocSDK7a.so" target-dir="libs/armeabi"/>
        <source-file src="libs/android/armeabi-v7a/liblocSDK7a.so" target-dir="libs/armeabi-v7a"/>
        <source-file src="libs/android/arm64-v8a/liblocSDK7a.so" target-dir="libs/arm64-v8a"/>
        <source-file src="libs/android/x86/liblocSDK7a.so" target-dir="libs/x86"/>
        <source-file src="libs/android/x86_64/liblocSDK7a.so" target-dir="libs/x86_64"/>
        <source-file src="libs/android/BaiduLBS_Android.jar" target-dir="libs"/>
    </platform>

为:
    <platform name="android">
        <source-file src="src/android/BaiduMapLocation.java" target-dir="src/com/aruistar/cordova/baidumap"/>
        <lib-file src="libs/android/armeabi" arch="device"/>
        <lib-file src="libs/android/armeabi-v7a" arch="device"/>
        <lib-file src="libs/android/arm64-v8a" arch="device"/>
        <lib-file src="libs/android/x86" arch="device"/>
        <lib-file src="libs/android/x86_64" arch="device"/>
        <lib-file src="libs/android/BaiduLBS_Android.jar" arch="device"/>
    </platform>

其他插件
cordova-plugin-background-mode 0.7.2 "BackgroundMode"
cordova-plugin-chrome-apps-common 1.0.7 "Chrome Apps Common Utils"
cordova-plugin-chrome-apps-sockets-tcp 1.3.7 "Chrome Apps Sockets TCP API"
cordova-plugin-device 1.1.4 "Device"
cordova-plugin-ionic-webview 1.1.16 "cordova-plugin-ionic-webview"
cordova-plugin-splashscreen 4.0.3 "Splashscreen"
cordova-plugin-whitelist 1.3.1 "Whitelist"
cordova-sqlite-storage 2.1.4 "Cordova sqlite storage plugin"
cz.blocshop.socketsforcordova 1.1.0 "SocketsForCordova"
ionic-plugin-keyboard 2.2.1 "Keyboard"

nvm install 8.11.1
nvm use 8.11.1
npm install cnpm -g --registry=https://registry.npm.taobao.org
npm install -g cordova
npm install -g ant-design-pro-cli
npm install -g dva-cli
npm install -g eslint
npm install -g eslint-config-airbnb
npm install -g eslint-config-prettier

总结:
1、hook及早配置
2、添加插件后,修改plugins.xml配置文件
3、移除Android
4、添加Android

定位问题
参考:http://lbsyun.baidu.com/index.php?title=android-locsdk/guide/create-project/android-studio


error code 162
E:\mapp\qyjg\cordova\platforms\android\app\build.gradle文件
    sourceSets{
        main {
            jniLibs.srcDir 'libs'
            jni.srcDirs = [] //disable automatic ndk-build
        }
    }
}

/*
 * WARNING: Cordova Lib and platform scripts do management inside of this code here,
 * if you are adding the dependencies manually, do so outside the comments, otherwise
 * the Cordova tools will overwrite them
 */

dependencies {

error code 505

-------------------------------------------

cordova plugin add cordova-sqlite-storage
cordova-plugin-dbcopy
cordova-plugin-advanced-http
com-sarriaroman-photoviewer
cordova-plugin-qrscanner
cordova-plugin-zip
uk.co.workingedge.cordova.plugin.sqliteporter

https://blog.csdn.net/xundh/article/details/46914097
调试https://segmentfault.com/a/1190000002933971
chrome://inspect/#devices

----------------------
https://my.oschina.net/guodapeng/blog/1796211
出现updatetodate
使用cordova clean


----文件传输
http://cordova.apache.org/docs/en/latest/reference/cordova-plugin-file-transfer/
http://cordova.apache.org/docs/en/latest/reference/cordova-plugin-file/index.html#sample
https://cordova.apache.org/blog/2017/10/18/from-filetransfer-to-xhr2.html
cordova plugin add cordova-plugin-file

/* eslint-disable */
    window.resolveLocalFileSystemURL(cordova.file.externalDataDirectory, fs => {
      console.log(`file system open: ${fs.name}`);
      console.log(fs);
      // window.resolveLocalFileSystemURL
      // eslint-disable-next-line

      console.log(cordova.file);
      fs.getFile(
        'bot.png',
        { create: true, exclusive: false },
        fileEntry => {
          console.log(`fileEntry is file? ${fileEntry.isFile.toString()}`);
          const oReq = new XMLHttpRequest();
          // Make sure you add the domain name to the Content-Security-Policy <meta> element.
          oReq.open('GET', 'http://cordova.apache.org/static/img/cordova_bot.png', true);
          // Define how you want the XHR data to come back
          oReq.responseType = 'blob';
          oReq.onload = function(oEvent) {
            const blob = oReq.response;
            // 创建一个写入对象
            fileEntry.createWriter(fileWriter => {
              // 文件写入成功
              fileWriter.onwriteend = function() {
                console.log('Successful file read...');
              };

              // 文件写入失败
              fileWriter.onerror = function(e) {
                console.log(`Failed file read: ${e.toString()}`);
              };

              // 写入文件
              fileWriter.write(blob);
            });
          };
          oReq.send(null);
        },
        err => {
          console.error(`error getting file! ${err}`);
        }
      );
    });
    /* eslint-enable */


-------安卓输出路径
console.log(cordova.file);

applicationDirectory:"file:///android_asset/"
applicationStorageDirectory:"file:///data/user/0/com.stbc.qyjg/"
cacheDirectory:"file:///data/user/0/com.stbc.qyjg/cache/"
dataDirectory:"file:///data/user/0/com.stbc.qyjg/files/"
documentsDirectory:null
externalApplicationStorageDirectory:"file:///storage/emulated/0/Android/data/com.stbc.qyjg/"
externalCacheDirectory:"file:///storage/emulated/0/Android/data/com.stbc.qyjg/cache/"
externalDataDirectory:"file:///storage/emulated/0/Android/data/com.stbc.qyjg/files/"
externalRootDirectory:"file:///storage/emulated/0/"
sharedDirectory:null
syncedDataDirectory:null
tempDirectory:null

----蓝牙打印机
cordova plugin add cordova-plugin-printer 错
cordova plugin add cordova-plugin-starprnt 错
cordova plugin add cordova-plugin-bluetoothle 错
cordova-plugin-bluetooth-serial2


https://blog.csdn.net/qq_29287973/article/details/78108933
https://wenku.baidu.com/view/e936a07b178884868762caaedd3383c4bb4cb463.html?qq-pf-to=pcqq.c2c


----蓝牙
 bluetoothSerial.list(
      result => {
        // eslint-disable-next-line
        bluetoothSerial.connect(
          result[0].id,
          r2 => {
            console.log(r2);
            // eslint-disable-next-line
            bluetoothSerial.write(
              'hello,world!',
              rx => {
                console.log(rx);
              },
              ry => {
                console.log(ry);
              }
            );
          },
          r3 => {
            console.log(r3);
          }
        );
      },
      result => {
        console.log(result);
      }
    );

----eslint常用关闭校验语句
https://www.cnblogs.com/liyongquan/p/7831717.html
1. 关闭段落校验

/* eslint-disable */some code
some code
/* eslint-enable */
2. 关闭当前行校验

1
some code // eslint-disable-line
3. 关闭下一行校验

1
2
// eslint-disable-next-line
some code


-----瓦片下载
    const myImageLayer = L.tileLayerCordova(
      'http://193.112.129.81/BasemapService/rest/image/latest/tile/{z}/{y}/{x}',
      {
        // these options are perfectly ordinary L.TileLayer options
        maxZoom: 20,
        // these are specific to L.TileLayer.Cordova and mostly specify where to store the tiles on disk
        folder: 'cache',
        name: 'myImageLayer',
        debug: true,
      }
    );
    this.myImageLayer = myImageLayer; 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
百度地图定位Cordova插件,支持Android,IOS 可以在此地址查看example 基于百度地图Android版定位SDK(v7.1)以及百度地图IOS SDK (v3.2.1) 一,申请Android及IOS版密钥 申请密钥Android定位SDK 每一个AndroidManifest.xml 中的package属性 对应一个AK,不可混用 iOS SDK开发密钥 每一个Bundle Identifier 对应一个AK,不可混用 二,安装插件```` cordova plugin add cordova-plugin-baidumaplocation --variable ANDROID_KEY="" --variable IOS_KEY="" //此处的API_KEY_XX来自于第一步,直接替换,也可以最后跟 --save 参数,将插件信息保存到config.xml中 //如果只需要Android端或者IOS端,可以只填写一个相应的AK,但是都不填肯定不行 三,使用方法 // 进行定位 baidumap_location.getCurrentPosition(function (result) {     console.log(JSON.stringify(result, null, 4)); }, function (error) { }); 获得定位信息,返回JSON格式数据: {     "time": "2017-02-25 17:30:00",//获取时间     "latitude": 34.6666666,//纬度     "lontitude": 117.8888,//经度     "radius": 61.9999999,//半径     //--------Android 独享 begin     "locType": 161,//定位类型                                                 "locTypeDescription": "NetWork location successful!",//定位类型解释        "userIndoorState": 1,//是否室内                                          //--------Android 独享 end     //--------IOS 独享 begin     "title": "我的位置",//定位标注点标题信息     "subtitle": "我的位置",//定位标注点子标题信息     //--------IOS 独享 end } 具体字段内容请参照: Android版 BDLocation v7.1 IOS版 BMKUserLocation 如果Android版获取到的信息是: {     "locType": 505,     "locTypeDescription": "NetWork location failed because baidu location service check the key is unlegal, please check the key in AndroidManifest.xml !",     "latitude": 5e-324,     "lontitude": 5e-324,     "radius": 0,     "userIndoorState": -1,     "direction": -1 } 说明Key有问题,可以检查下生成的AndroidManifest.xml文件里面是否有如下信息                                                           如果没有,说明插件使用不当,尝试重新安装,如果有这些信息,说明Key与当前程序AndroidManifest.xml 中的package名不一致,请检查Key的申请信息是否正确 四,查看当前安装了哪些插件 cordova plugin ls 五,删除本插件 cordova plugin rm cordova-plugin-baidumaplocation 标签:cordova

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值