cordova Android运行时白色离子电容运行SSL

3z6pesqy  于 2022-11-15  发布在  Android
关注(0)|答案(1)|浏览(126)

我在做一个简单的测试我尝试将离子和电容器添加到一个已经存在的Angular 项目。我设法使它正常工作和运行,但当我将SSL命令添加到CLI,使服务器运行HTTPS时,应用程序不再加载,我所能看到的一切都是空白屏幕。此外,如果我从浏览器手动访问URL,一切都正确加载。它会在那里吗?Android Studio或离子/电容器文件中有什么配置错误吗?我已经尝试了不同的配置和不同的模拟设备w/不同的Android版本,但没有使用,我一直无法使它工作。我当然会很感激,如果有人能帮助我与此...
运行ionic capacitor run android --livereload --external
https://i.stack.imgur.com/ljfUT.png
https://i.stack.imgur.com/8LxNV.png
当我将--ssl标志添加到CLI ionic capacitor run android --livereload --external --ssl
https://i.stack.imgur.com/fS0jV.png
https://i.stack.imgur.com/D3sLL.png
https://i.stack.imgur.com/3v5Bx.png

电容器配置

import { CapacitorConfig } from '@capacitor/cli';

const config: CapacitorConfig = {
  appId: 'io.ionic.starter',
  appName: 'iotest',
  webDir: './android/www',
  bundledWebRuntime: false
};

export default config;

Angular .json

{
  "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
  "version": 1,
  "newProjectRoot": "projects",
  "cli": {
    "defaultCollection": "@ionic/angular-toolkit"
  }, 
  "schematics": {
    "@ionic/angular-toolkit:component": {
      "styleext": "scss"
    },
    "@ionic/angular-toolkit:page": {
      "styleext": "scss"
    }
  },
  "projects": {
    "iotest": {
      "projectType": "application",
      "schematics": {
        "@schematics/angular:component": {
          "style": "scss"
        },
        "@schematics/angular:application": {
          "strict": true
        }
      },
      "root": "",
      "sourceRoot": "src",
      "prefix": "app",
      "architect": {
        "build": {
          "builder": "@angular-devkit/build-angular:browser",
          "options": {
            "outputPath": "./android/www",
            "index": "src/index.html",
            "main": "src/main.ts",
            "polyfills": "src/polyfills.ts",
            "tsConfig": "tsconfig.app.json",
            "inlineStyleLanguage": "scss",
            "assets": [
              "src/favicon.ico",
              "src/assets",
              {
                "glob": "**/*.svg",
                "input": "./node_modules/ionicicons/dist/ionicicons/svg",
                "output": "./svg"
              }
            ],
            "styles": [
              "src/styles.scss"
            ],
            "scripts": []
          },
          "configurations": {
            "production": {
              "budgets": [
                {
                  "type": "initial",
                  "maximumWarning": "500kb",
                  "maximumError": "1mb"
                },
                {
                  "type": "anyComponentStyle",
                  "maximumWarning": "2kb",
                  "maximumError": "4kb"
                }
              ],
              "fileReplacements": [
                {
                  "replace": "src/environments/environment.ts",
                  "with": "src/environments/environment.prod.ts"
                }
              ],
              "outputHashing": "all"
            },
            "development": {
              "buildOptimizer": false,
              "optimization": false,
              "vendorChunk": true,
              "extractLicenses": false,
              "sourceMap": true,
              "namedChunks": true
            }
          },
          "defaultConfiguration": "production"
        },
        "serve": {
          "builder": "@angular-devkit/build-angular:dev-server",
          "configurations": {
            "production": {
              "browserTarget": "iotest:build:production"
            },
            "development": {
              "browserTarget": "iotest:build:development"
            }
          },
          "defaultConfiguration": "development"
        },
        "extract-i18n": {
          "builder": "@angular-devkit/build-angular:extract-i18n",
          "options": {
            "browserTarget": "iotest:build"
          }
        },
        "test": {
          "builder": "@angular-devkit/build-angular:karma",
          "options": {
            "main": "src/test.ts",
            "polyfills": "src/polyfills.ts",
            "tsConfig": "tsconfig.spec.json",
            "karmaConfig": "karma.conf.js",
            "inlineStyleLanguage": "scss",
            "assets": [
              "src/favicon.ico",
              "src/assets"
            ],
            "styles": [
              "src/styles.scss"
            ],
            "scripts": []
          }
        }
      }
    }
  },
  "defaultProject": "iotest"
}

离子配置

{
  "defaultProject": "iotest",
  "projects": {
    "iotest": {
      "name": "iotest",
      "integrations": {
        "capacitor": {}
      },
      "type": "angular"
    }
  }
}

Angular

Angular CLI:12.1.4
节点:16.14.0(不支持)
应用程序管理员:国家预防措施8.3.1
操作系统:Windows 7
Angular :12.1.5
...动画、通用、编译器、编译器-客户端、核心、表单
...平台浏览器、平台浏览器动态、路由器
套件版本

  • ———————————————————————————————————————————————————————-
    @Angular 开发工具包/架构师0.1201.4
    @Angular -开发工具包/构建-Angular 12.1.4
    Angular 设备套件/内核12.1.4
    Angular 设备套件/原理图12.1.4
    @角状/陡倾12.1.4
    @示意图/Angular 12.1.4
    rxjs 6.6.7版本
    打字稿4.3.5
    警告:Angular不支持当前版本的Node(16.14.0)。

国家预防管理

第8.3.1版
我的目标是让它使用SSL运行,因为将来我需要将此应用于需要使用HTTPS运行的应用程序

b4lqfgs4

b4lqfgs41#

从capacitor.config.ts进行如下更改:

{
  ... 
  server: {
    url: 'https://your-local-ip:8100' // like: 192.168.1.66:8100
    androidScheme: 'https',
    clearText: true // just for test
  } 
 ... 
}

然后打开两个终端并运行以下命令:

ionic cap run android -l --external --ssl

从第二终端运行:

ionic serve 0.0.0.0 --ssl

毕竟如果你仍然看到空白页面,打开浏览器从移动的设备和去https://your-host-ip:8100,然后确保网址是可信的。

相关问题