Nov 26, 2018

Cordova build errors and fixes

Creating a new cordova project

This is where we start to create a new project.
cordova create hello com.example.hello HelloWorld
Adding Android platform.
C:\hello>cordova platform add android
Using cordova-fetch for cordova-android@~7.1.1
Adding android project...
Creating Cordova project for the Android platform:
        Path: platforms\android
        Package: com.example.hello
        Name: hello
        Activity: MainActivity
        Android target: android-27
Android project created with cordova-android@7.1.2
Android Studio project detected
Android Studio project detected
Discovered plugin "cordova-plugin-whitelist" in config.xml. Adding it to the project
Installing "cordova-plugin-whitelist" for android

Adding cordova-plugin-whitelist to package.json
Saved plugin info for "cordova-plugin-whitelist" to config.xml
--save flag or autosave detected
Saving android@~7.1.2 into config.xml file ...

Run the following command to build the project for all platforms

cordova build

Build Errors

ERROR1:
Error occurred during initialization of VM
Could not reserve enough space for 2097152KB object heap
Fix
Go to Start->Control Panel->System->Advanced(tab)->Environment Variables->System
Variables->New:
Variable name: _JAVA_OPTIONS   
Variable value: -Xmx512M

Variable name: Path  
Variable value: ;C:\Program Files\Java\jre6\bin;F:\JDK\bin;  
Change this to your appropriate path.
Restart computer!
ERROR2:
File C:\Users\oktay\.android\repositories.cfg could not be loaded.
Checking the license for package Android SDK Build-Tools 26.0.2 in C:\Program Files (x86)\Android\android-sdk\licenses

FAILURE: Build failed with an exception.

* What went wrong:
A problem occurred configuring project ':CordovaLib'.
> You have not accepted the license agreements of the following SDK components:
  [Android SDK Build-Tools 26.0.2].
  Before building your project, you need to accept the license agreements and complete the installation of the missing components using the Android Studio SDK Manager.
  Alternatively, to learn how to transfer the license agreements from one workstation to another, go to http://d.android.com/r/studio-ui/export-licenses.html
Fix
Create license file in %ANDROID_HOME%
mkdir "%ANDROID_HOME%\licenses"
echo |set /p="8933bad161af4178b1185d1a37fbf41ea5269c55" > "%ANDROID_HOME%\licenses\android-sdk-license"
ERROR3:
Warning: License for package Android SDK Build-Tools 26.0.2 not accepted.
Fix
Manually accept the license.
C:\Program Files (x86)\Android\android-sdk\tools\bin>sdkmanager --update && yes | sdkmanager --licenses
ERROR4:
Checking the license for package Android SDK Build-Tools 26.0.2 in C:\Program Files (x86)\Android\android-sdk\licenses
License for package Android SDK Build-Tools 26.0.2 accepted.
Preparing "Install Android SDK Build-Tools 26.0.2 (revision: 26.0.2)".
Warning: Failed to read or create install properties file.

The SDK directory (C:\Program Files (x86)\Android\android-sdk) is not writeable,
  please update the directory permissions.
Fix
Give Full permission to Everyone for sdk folder ( C:\Program Files (x86)\Android\android-sdk)

Giving full permission to "ALL APPLICATION PACKAGES" and "TrustedInstaller" didn't solve my problem.
Checking the license for package Android SDK Build-Tools 26.0.2 in C:\Program Files (x86)\Android\android-sdk\licenses
License for package Android SDK Build-Tools 26.0.2 accepted.
Preparing "Install Android SDK Build-Tools 26.0.2 (revision: 26.0.2)".
...
BUILD SUCCESSFUL in 2m 55s
46 actionable tasks: 46 executed
Built the following apk(s):
        C:\hello\platforms\android\app\build\outputs\apk\debug\app-debug.apk

Build project and Emulate in Andorid

cordova build
cordova emulate android
APPENDIX: A WARNING
C:\Program Files (x86)\Android\android-sdk\tools\bin>sdkmanager
Picked up _JAVA_OPTIONS: -Xmx512M
Warning: cvc-pattern-valid: Value '' is not facet-valid with respect to pattern '[a-zA-Z0-9_-]+' for type 'idType'.
Warning: cvc-type.3.1.3: The value '' of element 'id' is not valid.
Warning: cvc-pattern-valid: Value '' is not facet-valid with respect to pattern '[a-zA-Z0-9_-]+' for type 'idType'.
Warning: cvc-type.3.1.3: The value '' of element 'id' is not valid.
Warning: File C:\Users\oktay\.android\repositories.cfg could not be loaded.
[=======================================] 100% Computing updates...
Error resolved by creating an empty repositories.cfg file.

Cordova installation info is here

0 comments: