I have an older cordova project that I am updating. As a part of this process, I removed the android platform and readded it.
Now when I try to build the project I get the following error:
C:\App>cordova build android --verbose
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
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 C:\App\platforms\android\res\xml\config.xml
Merging project's config.xml into platform-specific android config.xml
Found "merges/android" folder. Copying its contents into the android project.
Merging and updating files from [www, platforms\android\platform_www, merges\android] to platforms\android\assets\www
Wrote out android application name "App" to C:\App\platforms\android\res\values\strings.xml
android-versionCode not found in config.xml. Generating a code based on version in config.xml (1.0.20): 10020
Wrote out Android package name "com.nge.app" to C:\App\platforms\android\src\com\nge\bca\MainActivity.java
Updating icons at platforms\android\res
Updating splash screens at platforms\android\res
This app does not have additional resource files defined
Prepared android project successfully
No scripts found for hook "after_prepare".
No scripts found for hook "before_compile".
ANDROID_HOME=C:\Android\sdk
JAVA_HOME=C:\Program Files\Java\jdk1.8.0_40
Error: Cannot read property 'length' of undefined
This did work before I removed the platform so I am guessing it is a bug or a config file that changed.
There is a similar issue here: https://pt.stackoverflow.com/questions/219442/cordova-build-android-error-cannot-read-property-length-of-undefined
I found another solution by downgrading Android to version 6.1.2, since the suggestions here (and many other suggestions on various forums, like reinstalling plugins, etc.) didn't work for me:
If that doesn't work at first hand, try the following:
First remove android platform:
Add Android version 6.1.2:
Build Android:
Here are some additional steps I took prior to above (on Mac), just to make sure:
Download the latest JDK and install.
Add JAVA_HOME this way:
Restart shell (CMD+Q and open again)
Make sure
echo $JAVA_HOME
equals to Android Studio -> File -> Project Structure -> JDK LocationFor me, this is the following path and version:
Update Android Studio and all of the SDK packages
Update npm
Note: On OS X 10.11 El Capitan or greater, run:
Update Cordova
If all of this didn't work for you and you are left with no other choice, I suggest you try downgrading Cordova to version 6.4.0:
Resolved an error by following: Hi all, Resolved problem to run cordova run android via command prompt for cordova project attached problem screenshot. To resolve this problem removed all environment variables under Advanced System settings. Uninstalled java and installed again, downloaded old sdk tools to avoid prompt for eclipse now.
Under user variable added JAVA_HOME = C:\Program Files\Java\jdk1.8.0_131
Under System variable ANDROD_HOME = C:\cordova\android-sdk Path = C:\Program Files\Android\Android Studio2\gradle\gradle-3.2\bin\;%JAVA_HOME%\bin to avoid error: No installed build tools found. Install the Android build tools version 19.1.0 or higher. Problem resolved now
You can downgrade cordova cli using
and build the project with give command
no need to add platform, it'll automatically add. If it ask to update cordova cli, then choose no
The problem was that my gradle version was 2.1 where Cordova wanted 3.2. Updating Android Studio (It was at 2.1) and making sure the environment variables are upto date was the main trick to get it to work again.