Home > database >  Ionic Gradle using old Java_Home value
Ionic Gradle using old Java_Home value

Time:06-21

I created a project with ionic and angular. Now i wanted to live debug the application in android studio.

At first the newest version of Java was installed on my machine. However running the ionic capacitor run android command always gave me a weird gradle error. So i googled and found a lot of people saying the java version is the problem. So i installed Java 8, removed the other version from my machine and set JAVA_HOME to the new location. So far so good.

After restarting my machine and running the ionic capacitor run android command again i got following error:

? Which device would you like to target? Pixel 3 API 30 (emulator) (Pixel_3_API_30)
> ng.cmd run app:build
✔ Browser application bundle generation complete.
✔ Copying assets complete.
✔ Index html generation complete.

Initial Chunk Files                                                     | Names                     |  Raw Size
vendor.js                                                               | vendor                    |   5.84 MB | 
polyfills.js                                                            | polyfills                 | 307.63 kB | 
styles.css                                                              | styles                    |  37.80 kB | 
main.js                                                                 | main                      |  21.51 kB | 
runtime.js                                                              | runtime                   |  13.96 kB | 

                                                                        | Initial Total             |   6.21 MB

Lazy Chunk Files                                                        | Names                     |  Raw Size
node_modules_ionic_core_dist_esm_swiper_bundle-28080340_js.js           | swiper-bundle-28080340-js | 200.26 kB | 
node_modules_ionic_core_dist_esm_ion-datetime_3_entry_js.js             | -                         | 140.67 kB | 
node_modules_ionic_core_dist_esm_ion-item_8_entry_js.js                 | -                         |  93.93 kB | 
polyfills-core-js.js                                                    | polyfills-core-js         |  92.34 kB | 
node_modules_ionic_core_dist_esm_ion-app_8_entry_js.js                  | -                         |  76.45 kB | 
node_modules_ionic_core_dist_esm_ion-modal_entry_js.js                  | -                         |  65.33 kB | 
node_modules_ionic_core_dist_esm_ion-slide_2_entry_js.js                | -                         |  59.81 kB | 
node_modules_ionic_core_dist_esm_ion-popover_entry_js.js                | -                         |  57.79 kB | 
node_modules_ionic_core_dist_esm_ion-refresher_2_entry_js.js            | -                         |  51.26 kB | 
node_modules_ionic_core_dist_esm_ion-alert_entry_js.js                  | -                         |  47.40 kB | 
common.js                                                               | common                    |  43.41 kB | 
node_modules_ionic_core_dist_esm_ion-segment_2_entry_js.js              | -                         |  40.65 kB | 
node_modules_ionic_core_dist_esm_ion-menu_3_entry_js.js                 | -                         |  39.25 kB | 
default-src_app_core_data_game-data_service_ts.js                       | features-home-home-module |  37.95 kB | 
node_modules_ionic_core_dist_esm_ion-nav_2_entry_js.js                  | -                         |  35.49 kB | 
node_modules_ionic_core_dist_esm_ion-searchbar_entry_js.js              | -                         |  34.13 kB | 
node_modules_ionic_core_dist_esm_ion-item-option_3_entry_js.js          | -                         |  34.12 kB | 
node_modules_ionic_core_dist_esm_ion-button_2_entry_js.js               | -                         |  33.88 kB | 
node_modules_ionic_core_dist_esm_ion-route_4_entry_js.js                | -                         |  32.66 kB | 
node_modules_ionic_core_dist_esm_ion-select_3_entry_js.js               | -                         |  31.69 kB | 
node_modules_ionic_core_dist_esm_ion-action-sheet_entry_js.js           | -                         |  30.41 kB | 
node_modules_ionic_core_dist_esm_ion-range_entry_js.js                  | -                         |  29.04 kB | 
src_app_features_game_game_module_ts.js                                 | features-game-game-module |  27.76 kB | 
node_modules_ionic_core_dist_esm_ion-fab_3_entry_js.js                  | -                         |  27.11 kB | 
node_modules_ionic_core_dist_esm_ion-accordion_2_entry_js.js            | -                         |  27.08 kB | 
node_modules_ionic_core_dist_esm_ion-tab-bar_2_entry_js.js              | -                         |  24.02 kB | 
node_modules_ionic_core_dist_esm_ion-toast_entry_js.js                  | -                         |  23.52 kB | 
node_modules_ionic_core_dist_esm_ion-input_entry_js.js                  | -                         |  22.73 kB | 
node_modules_ionic_core_dist_esm_ion-breadcrumb_2_entry_js.js           | -                         |  22.20 kB | 
node_modules_ionic_core_dist_esm_ion-progress-bar_entry_js.js           | -                         |  21.98 kB | 
node_modules_ionic_core_dist_esm_ion-picker-internal_entry_js.js        | -                         |  21.46 kB | 
polyfills-dom.js                                                        | polyfills-dom             |  19.42 kB | 
node_modules_ionic_core_dist_esm_ion-virtual-scroll_entry_js.js         | -                         |  19.28 kB | 
node_modules_ionic_core_dist_esm_ion-textarea_entry_js.js               | -                         |  19.28 kB | 
node_modules_ionic_core_dist_esm_ion-toggle_entry_js.js                 | -                         |  17.80 kB | 
node_modules_ionic_core_dist_esm_ion-back-button_entry_js.js            | -                         |  17.25 kB | 
node_modules_ionic_core_dist_esm_input-shims-4295668e_js.js             | input-shims-4295668e-js   |  17.06 kB | 
node_modules_ionic_core_dist_esm_ion-radio_2_entry_js.js                | -                         |  16.89 kB | 
node_modules_ionic_core_dist_esm_ion-col_3_entry_js.js                  | -                         |  15.80 kB | 
node_modules_ionic_core_dist_esm_ion-card_5_entry_js.js                 | -                         |  15.63 kB | 
node_modules_ionic_core_dist_esm_ion-loading_entry_js.js                | -                         |  15.56 kB | 
node_modules_ionic_core_dist_esm_ion-infinite-scroll_2_entry_js.js      | -                         |  14.09 kB | 
node_modules_ionic_core_dist_esm_ion-picker-column-internal_entry_js.js | -                         |  13.49 kB | 
node_modules_ionic_core_dist_esm_ion-reorder_2_entry_js.js              | -                         |  13.26 kB | 
node_modules_ionic_core_dist_esm_ion-checkbox_entry_js.js               | -                         |  11.45 kB | 
src_app_features_home_home_module_ts.js                                 | features-home-home-module |  10.31 kB | 
node_modules_ionic_core_dist_esm_ion-split-pane_entry_js.js             | -                         |  10.08 kB | 
node_modules_ionic_core_dist_esm_ion-chip_entry_js.js                   | -                         |   9.85 kB | 
node_modules_ionic_core_dist_esm_ion-tab_2_entry_js.js                  | -                         |   9.60 kB | 
node_modules_ionic_core_dist_esm_ion-spinner_entry_js.js                | -                         |   8.22 kB | 
node_modules_ionic_core_dist_esm_ion-ripple-effect_entry_js.js          | -                         |   6.61 kB | 
node_modules_ionic_core_dist_esm_tap-click-89bcc7cc_js.js               | tap-click-89bcc7cc-js     |   5.91 kB | 
node_modules_ionic_core_dist_esm_ion-avatar_3_entry_js.js               | -                         |   5.83 kB | 
node_modules_ionic_core_dist_esm_ion-img_entry_js.js                    | -                         |   4.54 kB | 
node_modules_ionic_core_dist_esm_ion-backdrop_entry_js.js               | -                         |   3.47 kB | 
node_modules_ionic_core_dist_esm_status-tap-e9e23d4e_js.js              | status-tap-e9e23d4e-js    |   2.86 kB | 
node_modules_capacitor_share_dist_esm_web_js.js                         | web                       |   1.94 kB | 
node_modules_ionic_core_dist_esm_ion-text_entry_js.js                   | -                         |   1.76 kB | 

Build at: 2022-06-18T09:32:04.572Z - Hash: 4ca02a5c6d11ecb3 - Time: 5858ms
> capacitor.cmd run android --target Pixel_3_API_30
[capacitor] √ Copying web assets from www to android\app\src\main\assets\public in 1.52s
[capacitor] √ Creating capacitor.config.json in android\app\src\main\assets in 1.40ms
[capacitor] [info] Found 1 Cordova plugin for android:
[capacitor]        [email protected]
[capacitor] √ copy android in 1.60s
[capacitor] √ Updating Android plugins in 9.35ms
[capacitor] [info] Found 5 Capacitor plugins for android:
[capacitor]        @capacitor/[email protected]
[capacitor]        @capacitor/[email protected]
[capacitor]        @capacitor/[email protected]
[capacitor]        @capacitor/[email protected]
[capacitor]        @capacitor/[email protected]
[capacitor] [info] Found 1 Cordova plugin for android:
[capacitor]        [email protected]
[capacitor] √ update android in 98.85ms
[capacitor] × Running Gradle build - failed!
[capacitor] [error] 
[capacitor]         FAILURE: Build failed with an exception.
[capacitor]
[capacitor]         * What went wrong:
[capacitor]         Supplied javaHome must be a valid directory. You supplied: C:\Program Files\Java\jdk-18.0.1.1
[capacitor]
[capacitor]         * Try:
[capacitor]         Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
[capacitor]
[capacitor]         * Get more help at https://help.gradle.org
[capacitor]
[ERROR] An error occurred while running subprocess capacitor.

        capacitor.cmd run android --target Pixel_3_API_30 exited with exit code 1.

        Re-running this command with the --verbose flag may provide more information.

Which comes down to: Supplied javaHome must be a valid directory. You supplied: C:\Program Files\Java\jdk-18.0.1.1

However, the mentioned JAVA_HOME variable is the old location, i already updated JAVA_HOME to the current installation of JAVA 8.

So i tried a few things.

  • Set JAVA_HOME in VS Code Settings
  • Cleaned Windows and VS Code Cache and restarted my machine
  • Run the ionic capacitor run android in a Command Prompt Window
  • Reinstalled VS Code
  • Reinstalled Ionic
  • Deleted the android folder in my ionic project and run the ionic capacitor run android command again
  • Uninstalled Java
  • Deleted gradle cache

But nothing worked, i always get the same error with the old JAVA_HOME variable.

CodePudding user response:

After a lot of try and error i found somewhat of a solution.

I had to delete the .gradle folder under C:\Users\MyUser\.gradle. After that i executed the command and a new folder was created, which used the new JAVA_HOME.

  • Related