JDK 1.8 在 ionic cordova build android 上的要求检查失败

Posted

技术标签:

【中文标题】JDK 1.8 在 ionic cordova build android 上的要求检查失败【英文标题】:Requirements check failed for JDK 1.8 in ionic on ionic cordova build android 【发布时间】:2019-08-08 00:40:51 【问题描述】:

我正在研究 ionic 4,

我正在尝试使用 ionic cordova build android 为 Android 创建构建 但为 Android 创建构建失败,原因如下 -->

检测到 Android Studio 项目 ANDROID_HOME=/用户/用户/库/Android/sdk JAVA_HOME=/库/Java/JavaVirtualMachines/jdk-11.jdk/Contents/Home JDK 1.8 的需求检查失败

java 的详细信息

java 版本

users-MacBook-Pro-3:library user$ java -version java版本“11” 2018-09-25 Java(TM) SE 运行时环境 18.9 (build 11+28) Java HotSpot(TM) 64 位服务器 VM 18.9(构建 11+28,混合模式)

- Details of My Mac os

Macbook pro  late 2011
os installed - Ox x ei caption

angular.json 文件


  "$schema": "./node_modules/@angular-devkit/core/src/workspace/workspace-schema.json",
  "version": 1,
  "defaultProject": "app",
  "newProjectRoot": "projects",
  "projects": 
    "app": 
      "root": "",
      "sourceRoot": "src",
      "projectType": "application",
      "prefix": "app",
      "schematics": ,
      "architect": 
        "build": 
          "builder": "@angular-devkit/build-angular:browser",
          "options": 
            "outputPath": "www",
            "index": "src/index.html",
            "main": "src/main.ts",
            "polyfills": "src/polyfills.ts",
            "tsConfig": "src/tsconfig.app.json",
            "assets": [
              
                "glob": "**/*",
                "input": "src/assets",
                "output": "assets"
              ,
              
                "glob": "**/*.svg",
                "input": "node_modules/ionicons/dist/ionicons/svg",
                "output": "./svg"
              
            ],
            "styles": [
              
                "input": "src/theme/variables.scss"
              ,
              
                "input": "src/global.scss"
              
            ],
            "scripts": [],
            "es5BrowserSupport": true
          ,
          "configurations": 
            "production": 
              "fileReplacements": [
                
                  "replace": "src/environments/environment.ts",
                  "with": "src/environments/environment.prod.ts"
                
              ],
              "optimization": true,
              "outputHashing": "all",
              "sourceMap": false,
              "extractCss": true,
              "namedChunks": false,
              "aot": true,
              "extractLicenses": true,
              "vendorChunk": false,
              "buildOptimizer": true,
              "budgets": [
                
                  "type": "initial",
                  "maximumWarning": "2mb",
                  "maximumError": "5mb"
                
              ]
            ,
            "ci": 
              "progress": false
            
          
        ,
        "serve": 
          "builder": "@angular-devkit/build-angular:dev-server",
          "options": 
            "browserTarget": "app:build"
          ,
          "configurations": 
            "production": 
              "browserTarget": "app:build:production"
            ,
            "ci": 
              "progress": false
            
          
        ,
        "extract-i18n": 
          "builder": "@angular-devkit/build-angular:extract-i18n",
          "options": 
            "browserTarget": "app:build"
          
        ,
        "test": 
          "builder": "@angular-devkit/build-angular:karma",
          "options": 
            "main": "src/test.ts",
            "polyfills": "src/polyfills.ts",
            "tsConfig": "src/tsconfig.spec.json",
            "karmaConfig": "src/karma.conf.js",
            "styles": [],
            "scripts": [],
            "assets": [
              
                "glob": "favicon.ico",
                "input": "src/",
                "output": "/"
              ,
              
                "glob": "**/*",
                "input": "src/assets",
                "output": "/assets"
              
            ]
          ,
          "configurations": 
            "ci": 
              "progress": false,
              "watch": false
            
          
        ,
        "lint": 
          "builder": "@angular-devkit/build-angular:tslint",
          "options": 
            "tsConfig": ["src/tsconfig.app.json", "src/tsconfig.spec.json"],
            "exclude": ["**/node_modules/**"]
          
        ,
        "ionic-cordova-build": 
          "builder": "@ionic/angular-toolkit:cordova-build",
          "options": 
            "browserTarget": "app:build"
          ,
          "configurations": 
            "production": 
              "browserTarget": "app:build:production"
            
          
        ,
        "ionic-cordova-serve": 
          "builder": "@ionic/angular-toolkit:cordova-serve",
          "options": 
            "cordovaBuildTarget": "app:ionic-cordova-build",
            "devServerTarget": "app:serve"
          ,
          "configurations": 
            "production": 
              "cordovaBuildTarget": "app:ionic-cordova-build:production",
              "devServerTarget": "app:serve:production"
            
          
        
      
    ,
    "app-e2e": 
      "root": "e2e/",
      "projectType": "application",
      "architect": 
        "e2e": 
          "builder": "@angular-devkit/build-angular:protractor",
          "options": 
            "protractorConfig": "e2e/protractor.conf.js",
            "devServerTarget": "app:serve"
          ,
          "configurations": 
            "ci": 
              "devServerTarget": "app:serve:ci"
            
          
        ,
        "lint": 
          "builder": "@angular-devkit/build-angular:tslint",
          "options": 
            "tsConfig": "e2e/tsconfig.e2e.json",
            "exclude": ["**/node_modules/**"]
          
        
      
    
  ,
  "cli": 
    "defaultCollection": "@ionic/angular-toolkit"
  ,
  "schematics": 
    "@ionic/angular-toolkit:component": 
      "styleext": "scss"
    ,
    "@ionic/angular-toolkit:page": 
      "styleext": "scss"
    
  

【问题讨论】:

【参考方案1】:

两者

java -version

和:

javac -version

应该是 Java 8。可以在 Linux (Debian) 上通过运行以下命令进行更改:

sudo update-alternatives --config java

或:

sudo update-alternatives --config javac

【讨论】:

【参考方案2】:

您已安装 Java JDK 版本 11。对于 ionic cordova,您需要 JDK 8。 Read Installing the Requirements.

你可以download JDK 8 here

【讨论】:

以上是关于JDK 1.8 在 ionic cordova build android 上的要求检查失败的主要内容,如果未能解决你的问题,请参考以下文章

Cordova android 运行/构建错误 - JDK 1.8 的要求检查失败

ionic2/Angularjs cordova node.js

Ionic+Cordova WebApp Android打包及环境搭建

怎么卸载重装ionic cordova

“Ionic cordova build android”错误

安装ionic 以及 cordova 环境配置详细过程,(错误解决)