美文网首页ionic
ionic开发遇到的问题1(持续更新...)

ionic开发遇到的问题1(持续更新...)

作者: andrewliu20 | 来源:发表于2020-03-13 12:21 被阅读0次

    1. 运行 ionic cordova platform add ios 报错:Error: npm: Command failed with exit code 1 Error output: 日志信息

    0 info it worked if it ends with ok
    1 verbose cli [ '/Users/developer/.nvm/versions/node/v10.19.0/bin/node',
    1 verbose cli   '/usr/local/bin/npm',
    1 verbose cli   'install',
    1 verbose cli   'cordova-ios@~4.5.4',
    1 verbose cli   '--production',
    1 verbose cli   '--save' ]
    2 info using npm@6.13.4
    3 info using node@v10.19.0
    4 verbose npm-session 48f53ab19ff80dd2
    5 silly install loadCurrentTree
    6 silly install readLocalPackageData
    7 http fetch GET 304 https://registry.npmjs.org/cordova-ios 4452ms (from cache)
    8 silly fetchPackageMetaData error for cordova-ios@~4.5.4 sha512-3+30m2dZ2yii7kg+H7cgpdpkXpMj54zoX5imjGGG4Z7dPXKmalTLc/9rLq+Iaa+Q1BqyOrUFaHopWOODRU6vCg== integrity checksum failed when using sha512: wanted sha512-3+30m2dZ2yii7kg+H7cgpdpkXpMj54zoX5imjGGG4Z7dPXKmalTLc/9rLq+Iaa+Q1BqyOrUFaHopWOODRU6vCg== but got sha512-MPQBVZmfRlkxeVcC/ebWLZ1r3RMr2+rXUZi22wRgKAVv6yaCiT0kMUw54P3rGFejiMKzlVIuiXhM7B3mhJO5xQ==. (180073 bytes)
    9 timing stage:rollbackFailedOptional Completed in 0ms
    10 timing stage:runTopLevelLifecycles Completed in 8535ms
    11 verbose stack Error: sha512-3+30m2dZ2yii7kg+H7cgpdpkXpMj54zoX5imjGGG4Z7dPXKmalTLc/9rLq+Iaa+Q1BqyOrUFaHopWOODRU6vCg== integrity checksum failed when using sha512: wanted sha512-3+30m2dZ2yii7kg+H7cgpdpkXpMj54zoX5imjGGG4Z7dPXKmalTLc/9rLq+Iaa+Q1BqyOrUFaHopWOODRU6vCg== but got sha512-MPQBVZmfRlkxeVcC/ebWLZ1r3RMr2+rXUZi22wRgKAVv6yaCiT0kMUw54P3rGFejiMKzlVIuiXhM7B3mhJO5xQ==. (180073 bytes)
    11 verbose stack     at Transform.on (/usr/local/lib/node_modules/npm/node_modules/ssri/index.js:328:19)
    11 verbose stack     at Transform.emit (events.js:203:15)
    11 verbose stack     at endReadableNT (_stream_readable.js:1145:12)
    11 verbose stack     at process._tickCallback (internal/process/next_tick.js:63:19)
    12 verbose cwd /Users/developer/Desktop/heavyLXApp
    13 verbose Darwin 17.7.0
    14 verbose argv "/Users/developer/.nvm/versions/node/v10.19.0/bin/node" "/usr/local/bin/npm" "install" "cordova-ios@~4.5.4" "--production" "--save"
    15 verbose node v10.19.0
    16 verbose npm  v6.13.4
    17 error code EINTEGRITY
    18 error sha512-3+30m2dZ2yii7kg+H7cgpdpkXpMj54zoX5imjGGG4Z7dPXKmalTLc/9rLq+Iaa+Q1BqyOrUFaHopWOODRU6vCg== integrity checksum failed when using sha512: wanted sha512-3+30m2dZ2yii7kg+H7cgpdpkXpMj54zoX5imjGGG4Z7dPXKmalTLc/9rLq+Iaa+Q1BqyOrUFaHopWOODRU6vCg== but got sha512-MPQBVZmfRlkxeVcC/ebWLZ1r3RMr2+rXUZi22wRgKAVv6yaCiT0kMUw54P3rGFejiMKzlVIuiXhM7B3mhJO5xQ==. (180073 bytes)
    19 verbose exit [ 1, true ]
    
    

    解决方案:

    removing the package-lock.json and reinstall with npm install --cache /tmp/empty-cache
    or npm cache clean --force
    

    这不成功是你的网络问题,你可以尝试换个网路试试,或者用手机热点!祝你成功!

    2 运行 ionic cordova platform add ... 报错信息:

    Something went wrong installing the “sharp” module
    

    报错截图:


    image.png

    解决方案:


    image.png

    期间遇到的坑:

    info sharp Using cached /Users/xmm/.npm/_libvips/libvips-8.8.1-darwin-x64.tar.gz
    ERR! sharp Please delete /Users/xmm/.npm/_libvips/libvips-8.8.1-darwin-x64.tar.gz as it is not a valid tarball
    ERR! sharp zlib: unexpected end of file
    info sharp Attempting to build from source via node-gyp but this may fail due to the above error
    info sharp Please see https://sharp.pixelplumbing.com/page/install for required dependencies
    TOUCH Release/obj.target/libvips-cpp.stamp
    CXX(target) Release/obj.target/sharp/src/common.o
    …/src/common.cc:25:10: fatal error: ‘vips/vips8’ file not found
    #include <vips/vips8>
    ^~~~~~~~~~~~
    1 error generated.
    make: *** [Release/obj.target/sharp/src/common.o] Error 1
    gyp ERR! build error
    gyp ERR! stack Error: make failed with exit code: 2
    gyp ERR! stack at ChildProcess.onExit (/usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:194:23)
    gyp ERR! stack at ChildProcess.emit (events.js:210:5)
    gyp ERR! stack at Process.ChildProcess._handle.onexit (internal/child_process.js:272:12)
    gyp ERR! System Darwin 19.0.0
    gyp ERR! command “/usr/local/bin/node” “/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js” “rebuild”
    gyp ERR! cwd /Users/xmm/node_modules/sharp
    gyp ERR! node -v v12.13.1
    gyp ERR! node-gyp -v v5.0.5
    gyp ERR! not ok
    npm WARN enoent ENOENT: no such file or directory, open ‘/Users/xmm/package.json’
    npm WARN xmm No description
    npm WARN xmm No repository field.
    npm WARN xmm No README data
    npm WARN xmm No license field.
    
    npm ERR! code ELIFECYCLE
    npm ERR! errno 1
    npm ERR! sharp@0.23.3 install: (node install/libvips && node install/dll-copy && prebuild-install) || (node-gyp rebuild && node install/dll-copy)
    npm ERR! Exit status 1
    npm ERR!
    npm ERR! Failed at the sharp@0.23.3 install script.
    npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
    
    npm ERR! A complete log of this run can be found in:
    npm ERR! /Users/xmm/.npm/_logs/2019-12-03T10_52_58_570Z-debug.log
    
    

    解决方案:

    这个错误把应该是libvips-8.8.1-darwin-x64.tar.gz没下载好,删掉就好了,重新运行.如果还不行就去就去网上下载该包,放在该目录下 /Users/xmm/.npm/_libvips/ 重新运行即可!

    3.ionic 浏览器调试跨域问题

    1.在 app.config.json 文件配置 proxies ,复制时删除注释

    //ionicProject/ionic.config.json
    {
        "name": "ionicProject",
        "app_id": "",
        "type": "ionic-angular",
        "integrations": {
            "cordova": {}
        },
        "proxies": [
            {
                "path": "/mobile/", //需要替换的标识符
                "proxyUrl": "http://xxx:8089/mobile/"  //最终替换的地址
            }
        ]
    }
    

    2、全局请求地址调整

    //SERVE_URL = "http://xxx/mobile/";
    SERVE_URL = "http://localhost:8100/mobile/";
    
    1. ionic serve 调试,跨域问题解决

    4 # [Ionic Cordova build fails with 'toLowerCase' of undefined]

    解决方案:

    ionic cordova platform rm ios
    ionic cordova platform add ios@latest
    
    

    5 . ionic Cannot read property 'toLowerCase' of undefined

    ionic cordova platform rm ios
    ionic cordova platform add ios@latest
    ionic cordova build ios
    
    

    若该方法不好使使用下面方法修改:
    解决方案:

    修改platforms/ios/cordova/lib/list-emulator-build-targets文件第53行左右。原来的代码:
    
    if (device.name === deviceType.name.replace(/\-inch/g, ' inch') &&
        device.availability.toLowerCase().indexOf('unavailable') < 0) {
        availAcc.push(device);
     }
    
    修改为:
    
    if (device.name === deviceType.name.replace(/\-inch/g, ' inch')) {
    if ((device.availability && device.availability.toLowerCase().indexOf('unavailable') < 0)
    || device.isAvailable == 'YES') {
    // XCode 10 and lower
    availAcc.push(device);
    }
    }
    

    6 ios 项目run以及build在xcode10下的处理方法:

    ionic cordova run ios -- --buildFlag="-UseModernBuildSystem=0"
    ionic cordova build ios -- --buildFlag="-UseModernBuildSystem=0"
    
    
    

    or
    sudo cordova build
    在Xcode中打开项目,则需要将Workspace Settings中的构建系统更改为“Legacy Build System”

    7.启动项目出现
    src/node_contextify.cc 631:assertion 'arg[1]->IsString()' faill

    出现原因:
    node 10 版本都会出现这个问题

    解决办法:

    npm install natives
    

    8 ionic 发布release版本包https请求无法连接debug版本可以正常请求--解决方案

    onic测试时一直使用ionic build android/ios发布debug包,一切正常;上线当天打release包后一直提示网络连接错误,debug版本和release版本的程序代码是完全一致的,区别也只在于release版本多了签名,这和http请求应该没关系的,经查询得知,在debug模式下会跳过证书的认证,这时候http请求是没问题的,但是release版本就会进行认证,这和PC端的道理其实是一样的,证书无效或者未认证会提示是否还要进行访问,但是使用ajaix进行http请求无法看到提示信息导致连接一直失败。
    对于IOS来说:

    修改webstrom 工程platforms-->MyApp-->AppDelegate.m-->在末尾追加如下代码:
        @implementation NSURLRequest(DataController)
        + (BOOL)allowsAnyHTTPSCertificateForHost:(NSString *)host
        {
         return YES;
        }
       @end
    
    

    对于Android来说:

    修改 \platforms\android\CordovaLib\src\org\apache\cordova\engine\SystemWebViewClient 文件里的 onReceivedSslError 函数,原函数如下:
    public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) {
    
            final String packageName = parentEngine.cordova.getActivity().getPackageName();
            final PackageManager pm = parentEngine.cordova.getActivity().getPackageManager();
    
            ApplicationInfo appInfo;
            try {
                appInfo = pm.getApplicationInfo(packageName, PackageManager.GET_META_DATA);
                if ((appInfo.flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0) {
                    // debug = true
                    handler.proceed();
                    return;
                } else {
                    // debug = false
                    super.onReceivedSslError(view, handler, error);
                }
            } catch (NameNotFoundException e) {
                // When it doubt, lock it out!
                super.onReceivedSslError(view, handler, error);
            }
        }
        修改为如下即可:
        public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) {
            handler.proceed();
        }
    
    
    

    修改完成重新打包,亲测可用。打包时使用ionic build android --release --prod添加–prod能够优化APP启动速度,一点小建议。

    在网上还看到有人说这个网络问题是由于cordova造成的,原因是没有添加白名单插件,使用cordova plugin ls 进行查看是否存在cordova-plugin-whitelist这个插件,如果存在则使用cordova plugin remove cordova-plugin-whitelist卸载之后再重新安装即可cordova plugin add cordova-plugin-whitelist
    这也是可能的原因之一,但是这只是针对很老的cordova平台而言,目前基本使用的都是5.0以上的会自动包含此插件,也做个参考吧,有可能在操作插件时不经意间把白名单插件卸载了
    ————————————————
    原文链接:https://blog.csdn.net/qq_42835445/article/details/87614802

    1. 版本问题造成版本 build ios 失败
      Error: Cannot find module '../plugman/platforms/ios'

    解决方法

    sudo npm i -g cordova@6.5.0
    
    2.进入路径 plugins/cordova-hot-code-push-plugin/scripts/lib
      找到文件 iosWKWebViewEngineSupport.js
      用以下代码替换原方法
      
    function loadProjectFile() {
      var platform_ios;
      var projectFile;
      try {
        // try pre-5.0 cordova structure
        platform_ios = context.requireCordovaModule('cordova-lib/src/plugman/platforms')['ios'];
        projectFile = platform_ios.parseProjectFile(iosPlatformPath());
      } catch (e) {
        try {
          // let's try cordova 5.0 structure
          platform_ios = context.requireCordovaModule('cordova-lib/src/plugman/platforms/ios');
          projectFile = platform_ios.parse(iosPlatformPath());
        } catch (e) {
          // try cordova 7.0 structure
          var iosPlatformApi = require(path.join(iosPlatformPath(), '/cordova/Api'));
          var projectFileApi = require(path.join(iosPlatformPath(), '/cordova/lib/projectFile.js'));
          var locations = (new iosPlatformApi()).locations;
          projectFile = projectFileApi.parse(locations);
        }
      }
      return projectFile;
    }
    

    补充

    // 如果使用方法2报以下错误的话
    CHCP plugin after prepare hook:
    Error: iosPlatformPath is not a function
    
    就把方法2内所有 iosPlatformPath() 的 '()' 删除
    

    原文链接:https://www.jianshu.com/p/392e626d4e19

    相关文章

      网友评论

        本文标题:ionic开发遇到的问题1(持续更新...)

        本文链接:https://www.haomeiwen.com/subject/pagqshtx.html