I am using ionic 4 for my app whenever I am building or running app I am getting the error saying that "An error occurred while running subprocess cordova. cordova build android --verbose exited with exit code 1." and same command I used ionic cordova build android with verbose I couldn't understand how to solve this problem.
I have already rm and added the android platform and degraded cordova version to 7.
Here is error I am getting after run the code: ionic cordova build android
>Android Studio project detected
ANDROID_HOME=C:\Users\User\AppData\Local\Android\android-sdk
JAVA_HOME=C:\Program Files\Java\jdk1.8
studio
Cannot read property 'length' of undefined
[ERROR] An error occurred while running subprocess cordova.
>cordova build android exited with exit code 1.
>Re-running this command with the --verbose flag may provide more information.
After I tried same with verbose: `ionic cordova build android --verbose`
Wrote out android application name "MyApp" to E:\ionic4\notification\platforms\android\app\src\main\res\values\strings.xml
>android-versionCode not found in config.xml. Generating a code based on version in config.xml (0.0.1): 1
Wrote out Android package name "io.ionic.starterapp" to E:\ionic4\notification\platforms\android\app\src\main\java\io\ionic\starterapp\MainActivity.java
Updating icons at platforms\android\app\src\main\res
Updating splash screens at platforms\android\app\src\main\res
Updating resource files at platforms\android
Prepared android project successfully
Executing script found in plugin cordova-plugin-fcm-with-dependecy-updated for hook "after_prepare": plugins\cordova-plugin-fcm-with-dependecy-updated\scripts\fcm_config_files_process.js
No scripts found for hook "before_compile".
ANDROID_HOME=C:\Users\User\AppData\Local\Android\android-sdk
JAVA_HOME=C:\Program Files\Java\jdk1.8
studio
Cannot read property 'length' of undefined
TypeError: Cannot read property 'length' of undefined
at Object.module.exports.check_gradle (E:\ionic4\notification\platforms\android\cordova\lib\check_reqs.js:138:20)
at StudioBuilder.prepEnv (E:\ionic4\notification\platforms\android\cordova\lib\builders\StudioBuilder.js:217:23)
at Api.module.exports.run (E:\ionic4\notification\platforms\android\cordova\lib\build.js:154:20)
at E:\ionic4\notification\platforms\android\cordova\Api.js:342:43
at _fulfilled (E:\ionic4\notification\platforms\android\cordova\node_modules\q\q.js:834:54)
at E:\ionic4\notification\platforms\android\cordova\node_modules\q\q.js:863:30
at Promise.promise.promiseDispatch (E:\ionic4\notification\platforms\android\cordova\node_modules\q\q.js:796:13)
at (E:\ionic4\notification\platforms\android\cordova\node_modules\q\q.js:137:13)
at flush (E:\ionic4\notification\platforms\android\cordova\node_modules\q\q.js:125:13)
E:\ionic4\notification\platforms\android\cordova\node_modules\q\q.js:604:44
at runSingle
No scripts found for hook "before_build".
No scripts found for hook "before_prepare".
Checking config.xml and package.json for saved platforms that haven't been added to the project
Config.xml and package.json platforms are the same. No pkg.json modification.
Package.json and config.xml platforms are different. Updating config.xml with most current list of platforms.
PlatformApi successfully found for platform android
Android Studio project detected
Checking config.xml for saved plugins that haven't been added to the project
Checking for any plugins added to the project that have not been installed in android platform
No differences found between plugins added to project and installed in android platform. Continuing...
Generating platform-specific config.xml from defaults for android at E:\ionic4\notification\platforms\android\app\src\main\res\xml\config.xml
Merging project's config.xml into platform-specific android config.xml
Merging and updating files from [www, platforms\android\platform_www] to platforms\android\app\src\main\assets\www