真機遠程調試 ( IOS Android 以及微信,weex, react native)和vscode配置各種開發調試環境


1.以前cordova遠程調試,Android的直接連接USB后,用chrome打開chrome://inspect網址

   (有人遇到第一次打開chrome inspect是空白頁面,是因為第一次要下載一些工具,是要翻牆的。當然有離線包可用,具體可以網上搜索。)

 IOS的打開Safari的developer下。

   

   這是因為cordova的webView都已經開放了遠程調試,

 如果是自己的加的webView,要進行遠程調試

Android:

在調試WebView需要滿足安卓系統版本為Android 4.4+已上。並且需要再你的APP內配置相應的代碼,在WebView類中調用靜態方法setWebContentsDebuggingEnabled,如下:

if (Build.VERSION.SDK_INT >=Build.VERSION_CODES.KITKAT) {  
  
   WebView.setWebContentsDebuggingEnabled(true);  
  
}

IOS:

  利用WebView隱含的一個API

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
  // ......
  [NSClassFromString(@"WebView") _enableRemoteInspector];
  // ......
}

不過這是個私有API,ARC關閉的情況下才能這么寫,不然會報錯。

微信:

  利用微信開發者工具進行遠程調試,具體操作很簡單

 2.遠程調試可以debug那些web上看不出來,但是在在device上就出問題的情況

 1.weex安裝完weex-toolkit

  $ npm install  -g  weex-toolkit
  就可以直接通過weex debug命令進行調試
  
2.比如下載的weex demo,進入根目錄,運行
    weex debug examples
就會出現一些二維碼頁面,用playground app掃這個二維碼,瀏覽器里出現如下頁面

點擊remotedebug按鈕就可以進行遠程調試了

 
真機調試微信(android,ios)H5頁面
https://www.jianshu.com/p/c620ef778e1c



3.React Native
在運行帶RN的工程后,當前頁面下ios模擬器通過cmd+D(真機可以通過搖一搖),android通過Menu按鍵,調出RN的開發者菜單,

4.electron和node調試(vscode中)
{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "type": "node",
            "request": "launch",
            "name": "Launch Program",
            "program": "${workspaceFolder}/app/templates/electron/node-util/encrypt.js"  //如果是debug當前文件,就是"${file}"

        },
    
      {
        "type": "node",
        "request": "launch",
        "name": "Launch via NPM",
        "cwd": "${workspaceFolder}/qogirShopClient-web/",
        "runtimeExecutable": "npm",
        "runtimeArgs": [
        "run-script",
        "dev"
        ],
        "port": 5858
      },
      {
        "type": "node",
        "request": "launch",
        "name": "Launch Webpack",
        "cwd": "${workspaceFolder}/qogirShopClient-web/",
        "program": "${workspaceFolder}/qogirShopClient-web/node_modules/webpack/bin/webpack.js",
        "env": {
          "NODE_ENV": "local"
        },
        "args": [
        "-p",
        "--config",
        "build/webpack.config.js",
        "u"
        ]
       },
        {
            "name": "Debug Main Process",
            "type": "node",
            "request": "launch",
            "cwd": "${workspaceRoot}/app/templates/electron",
            "runtimeExecutable": "${workspaceRoot}/app/templates/electron/node_modules/.bin/electron",
            "windows": {
                "runtimeExecutable": "${workspaceRoot}/app/templates/electron/node_modules/.bin/electron.cmd"
            },
            "args": [
                "."
            ]
        },
    {
      "type": "node",
      "request": "launch",
      "name": "Jest All",
      "program": "${workspaceFolder}/node_modules/.bin/jest",
      "args": [
        "--runInBand"
        ],
      "console": "integratedTerminal",
      "internalConsoleOptions": "neverOpen",
      "disableOptimisticBPs": true,
      "windows": {
        "program": "${workspaceFolder}/node_modules/jest/bin/jest",
      }
    },
    ]
}

 vscode的launch.json里添加配置,然后就可以在vscode里打斷點調試node或者RN項目了

 "runtimeExecutable": "/Users/johnzhu/.nvm/versions/node/v13.2.0/bin/node" 可以切換所使用的node版本

  上面的第一個configure是調試node的,比如我的encrypt.js

  第二個是調試npm 腳本

  第三個調試webpack,並且加參數的

  第四個是調試electron的,目錄那么長是因為是我自己的一個腳手架項目(https://github.com/johnzhu12/generator-rocky),electron的目錄比較深

  各個配置的目錄各不相同,對應自己項目的目錄設置
 最后deBugger jest

 5.vscode調試karma

debugging Karma with Visual Studio Code
這里debug的斷點一定要打在sourcemap里,大在源碼里是不會被hit的
6. vscode 配置c/c++環境
  clang編譯c,clang++編譯c++

   launch.json和task.json
  

"configurations": [
        {
            "name": "clang++ build and debug active file",
            "type": "cppdbg",
            "request": "launch",
            "program": "${fileDirname}/${fileBasenameNoExtension}",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": false,
            "MIMode": "lldb",
            "preLaunchTask": "clang++ build active file"
        }
    ]

 

{
    "tasks": [
        {
            "type": "shell",
            "label": "clang++ build active file",
            "command": "/usr/bin/clang++",
            "args": [
                "-g",
                "${file}",
                "-o",
                "${fileDirname}/${fileBasenameNoExtension}"
            ],
            "options": {
                "cwd": "/usr/bin"
            }
        }
    ],
    "version": "2.0.0"
}

 

 c_cpp_properties.json

{
    "configurations": [
        {
            "name": "Mac",
            "includePath": [
                "/usr/local/include",
                "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/usr/include/c++/4.2.1",
                "${workspaceFolder}/**"
            ],
            "defines": [],
            "macFrameworkPath": [
                "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/System/Library/Frameworks"
            ],
            "compilerPath": "/usr/bin/clang++",
            "cStandard": "c11",
            "cppStandard": "c++17",
            "intelliSenseMode": "clang-x64"
        }
    ],
    "version": 4
}

上面配置都自己試過,親測有用


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM