Home » Android » Cannot build signed android package through visual studio cordova

# Cannot build signed android package through visual studio cordova

Questions:

I am trying to build a signed release package for my Android application using Visual Studio 2015 Cordova Tools.
I am using Cordova 5.1.1, which requires that I supply the build process with a build.json file, telling the application where the keystore are and what password is using.
However when I add the build.json file, I am not able to make a successful build to release.

I followed this guide: https://github.com/Microsoft/cordova-docs/tree/master/tutorial-package-publish#android

And got this error (with path edited out):

1>  ANDROID_HOME=C:\Program Files (x86)\Android\android-sdk (TaskId:11)
1>  SyntaxError: Unexpected token ﻿ (TaskId:11)
1>  Command finished with error code 1: cmd /s /c ""\platforms\android\cordova\build.bat" --release "--buildConfig=\build.json"" (TaskId:11)
1>ERROR building one of the platforms : error : cmd: Command failed with exit code 1
1>  You may not have the required environment or OS to build this project (TaskId:11)
1>MDAVSCLI : error : cmd: Command failed with exit code 1


What am I doing wrong? It seems like it cant parse the JSON?

This issue is caused because the default build.json has a BOM that the NodeJS JSON parser doesn’t like. You can fix this in a number of ways, but the simplest is to open the file using Visual Studio’s Binary editor.

Right-click build.json, select “Open With…”, then choose the “Binary Editor” from the list. You should see something like this:

Select the first three bytes as in the screenshot, and delete them, then save the file. The parser should now accept the file, and signing will work as expected.

I tried this approach as well following the same documentation. and getting exactly the same error.

After looking at the android build documentation, i.e the Signing Your App Manually

I realised that it should be possible to build the application in release mode (i.e an apk that is unsigned is generated 1st), so i removed build.json and tried this, and I got errors. I did a few google searches and came up this [post][2].

[2]: Error when running cordova build –release android In summary this my advice.

1. Remove the build.json file.
2. Clean the solution set it to debug mode and make sure you can a successful build.
3. Clean the solution set it to release mode.
5. Create a new file build-extras.gradle, i got this suggestion from one of the on the [post][2] [2]: Error when running cordova build –release android you don’t want to be editing the auto generated build.gradle file.

disable MissingTranslation
} }
7. Now go and build your solution, it should work and you’ll get an unsigned apk i.e android-release-unsigned.apk in your bin\Android\release folder.
1. Sign your apk manually by following android build – signing your app manually steps

Additionally to the reason @dlev posted I found another reason that could cause this:

I was using a path containing folder names foo\bar. This worked before, but it seems now (I have no idea if node, cordova or whatever got updated) this doesn’t work any more and you have to escape the directory seperator: foo\\bar.

After adding this, I can build my project again.

Another hack is to leverage android’s build system. In platforms\android put your keystore file and inside your build-extras.gradle. the following

 android {
lintOptions {
checkReleaseBuilds false
abortOnError false
}
signingConfigs {
release {
keyAlias = ""
keyPassword = "yourpassword" // And these must be set to non-empty in order to have the signing step added to the task graph.
storeFile = file("yourfile.keystore")
}