我用ionic和angular创建了一个项目。现在我想在android studio中现场调试应用程序。
一开始我的机器上安装了最新版本的Java。但是运行ionic capacitor run android
命令总是给我一个奇怪的gradle错误。所以我在谷歌上搜索,发现很多人说Java版本有问题。所以我安装了Java 8,从我的机器上删除了其他版本,并将JAVA_HOME设置为新的位置。到目前为止一切都很好。
在重新启动我的机器并再次运行ionic capacitor run android
命令后,我得到了以下错误:
? 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] phonegap-plugin-barcodescanner@8.1.0
[capacitor] √ copy android in 1.60s
[capacitor] √ Updating Android plugins in 9.35ms
[capacitor] [info] Found 5 Capacitor plugins for android:
[capacitor] @capacitor/app@1.1.1
[capacitor] @capacitor/haptics@1.1.4
[capacitor] @capacitor/keyboard@1.2.2
[capacitor] @capacitor/share@1.1.2
[capacitor] @capacitor/status-bar@1.0.8
[capacitor] [info] Found 1 Cordova plugin for android:
[capacitor] phonegap-plugin-barcodescanner@8.1.0
[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.
归结起来就是:Supplied javaHome must be a valid directory. You supplied: C:\Program Files\Java\jdk-18.0.1.1
但是,提到的JAVA_HOME变量是旧位置,我已经将JAVA_HOME更新为JAVA 8的当前安装。
所以我试了几种方法。
- 在VS代码设置中设置JAVA_HOME
- 已清理Windows和VS代码缓存并重新启动计算机
- 在命令提示符窗口中运行离子电容器run android
- 已重新安装VS代码
- 已重新安装离子
- 删除了我的ionic项目中的android文件夹,并再次运行
ionic capacitor run android
命令 - 已卸载Java
- Deleted gradle cache
但没有工作,我总是得到相同的错误与旧的JAVA_HOME变量。
1条答案
按热度按时间368yc8dk1#
经过大量的尝试和错误,我找到了一些解决办法。
我不得不删除
C:\Users\MyUser\.gradle
下的.gradle
文件夹。之后我执行了命令,并创建了一个新的文件夹,其中使用了新的JAVA_HOME
。