Ionic toturial for building a release.apk


#21

@encodedmirko : Thanks buddy, This is my first mobile app. Had no idea what signing is and all.


#22

So you create this file under platforms/android? And you don’t need to do any of the previous steps outlined in the first post?


#23

Not entirely, you still have to step 1, 2 and 3 @TacoBot


#24

We store those in a secure place and privately document how to retrieve for other developers on the team. In my project, when I get those files I put them in a config folder with a rule in version control to ignore those files (so they never get added to any repo by accident). I have a hooks script that copies the files into platforms/android only when doing a release build.


#25

With the new cordova version it’s possible to simply add a build.json and get everything done automatically:

{
“android”: {
“debug”: {
“keystore”: “…\android.keystore”,
“storePassword”: “android”,
“alias”: “mykey1”,
“password” : “password”,
“keystoreType”: “”
},
“release”: {
“keystore”: “…\android.keystore”,
“storePassword”: “”,
“alias”: “mykey2”,
“password” : “password”,
“keystoreType”: “”
}
}
}

see https://cordova.apache.org/docs/en/5.0.0/guide_platforms_android_tools.md.html

Cheers


#26

Hello @sjerd , You can not say add this line inside the tag to your custom_rules.xml. Because custom_rules.xml has many tags inside it which one exactly you mean??

Regards,


#27

I placed a comment on july 4 That you should read, ionic changed their build process a bit


#28

Is there an updated thread for building release.apk?

It seems the process keeps changing every few months or so, thus someone new is going to be lost for sure.


#29

@sjerd’s comment on July 4th is the correct solution. Just make sure you place the release-signing.properties file in platforms/android/.


#30

@htv It has changed once because Android has switched from ant to Gradle for builds, so really it depends on which version of Cordova you’re currently using. IIRC, Cordova 5.x (latest) is using Gradle now. Im still using Cordova 4.3 so we’re still using ant, thus instructions will be different for ant vs. Gradle builds.


#31

hi, @sjerd
Shall I follow this steps after doing it once? I updated my app code and want to build new release of same app.


#32

only these steps if your ionic version is up to date

You should no longer use ant.properties and secure.properties you should create a 

“release-signing.properties” file with these contents:

key.store=YourApp.keystore
key.store.password=<YourApp keystore password>
key.alias=YourApp
key.alias.password=<YourApp alias password>
no custom-rules.xml just the release-signign.properties and the key.store file 
then use ionic build --release

#33

make sure step by step but it’s not working. I saw error below:

Minifying JS file: ._ion.sound.js
/Users/phanthinh/Public/Projects/buddy/build/***/node_modules/uglify-js/tools/node.js:57
files.forEach(function(file, i){
^

TypeError: Cannot read property ‘forEach’ of undefined
at Object.exports.minify (/Users/***/Public/Projects/buddy/build/***/node_modules/uglify-js/tools/node.js:57:14)
at compress (/Users/***/Public/Projects/***/build/buddy/hooks/after_prepare/ionic-minify.js:63:29)
at /Users/***/Public/Projects/buddy/build/***/hooks/after_prepare/ionic-minify.js:119:11
at FSReqWrap.oncomplete (fs.js:82:15)
Error: Hook failed with error code 1: /Users/***/Public/Projects/buddy/build/buddy/hooks/after_prepare/ionic-minify.js
at /usr/local/lib/node_modules/cordova/node_modules/cordova-lib/src/hooks/HooksRunner.js:195:23
at _rejected (/usr/local/lib/node_modules/cordova/node_modules/q/q.js:797:24)
at /usr/local/lib/node_modules/cordova/node_modules/q/q.js:823:30
at Promise.when (/usr/local/lib/node_modules/cordova/node_modules/q/q.js:1035:31)
at Promise.promise.promiseDispatch (/usr/local/lib/node_modules/cordova/node_modules/q/q.js:741:41)
at /usr/local/lib/node_modules/cordova/node_modules/q/q.js:557:44
at flush (/usr/local/lib/node_modules/cordova/node_modules/q/q.js:108:17)
at doNTCallback0 (node.js:408:9)
at process._tickCallback (node.js:337:13)


#34

Awesome!! It’s worked


#35

why my build erro like this


#36

I also have same error. Please give solution. @nicraboy


#37

@nicraboy

Having following error while building project. I am using Ubuntu.

pc181@pc181-desktop:/var/www/html/ionic/myMap$ ionic build android
Running command: /var/www/html/ionic/myMap/hooks/after_prepare/010_add_platform_class.js /var/www/html/ionic/myMap
add to body class: platform-android
Running command: /var/www/html/ionic/myMap/platforms/android/cordova/build
[Error: ‘ANDROID_HOME’ environment variable is set to non-existent path: /home/dquintana/Android/Sdk
Try update it manually to point to valid SDK directory.]
ERROR building one of the platforms: Error: /var/www/html/ionic/myMap/platforms/android/cordova/build: Command failed with exit code 2
You may not have the required environment or OS to build this project
Error: /var/www/html/ionic/myMap/platforms/android/cordova/build: Command failed with exit code 2
** at ChildProcess.whenDone (/usr/local/lib/node_modules/cordova/node_modules/cordova-lib/src/cordova/superspawn.js:139:23)**
** at ChildProcess.emit (events.js:110:17)**
** at maybeClose (child_process.js:1015:16)**
** at Process.ChildProcess._handle.onexit (child_process.js:1087:5)**


#38

Let me know which approach is the best one to sign and zipalign my app


#39

I tried various approach to sign and zipalign
For example

  1. Ant.properties file setting

  2. Manual processs
    $ jarsigner -verbose -sigalg SHA1withRSA -digestalg SHA1 -keystore my-release-key.keystore HelloWorld-release-unsigned.apk alias_name

Apk file generated but not signed one, I am not getting any errorr

Please provide best workable solutions.

Thanks


#40

Hi @nicraboy. I followed this tutorial for android release.apk and everything worked fine until the --release command. An error came up and suggested that I might not have the required environment or os to build this project. Is this because I did this on a mac?

Here is the error that came up:

Running command: “/Users/LiyangFeng/Desktop/local notification/hooks/after_prepare/010_add_platform_class.js” "/Users/LiyangFeng/Desktop/local notification"
add to body class: platform-android
Running command: “/Users/LiyangFeng/Desktop/local notification/platforms/android/cordova/build” --release
[Error: ANDROID_HOME is not set and “android” command not in your PATH. You must fulfill at least one of these conditions.]
ERROR building one of the platforms: Error: /Users/LiyangFeng/Desktop/local notification/platforms/android/cordova/build: Command failed with exit code 2
You may not have the required environment or OS to build this project
Error: /Users/LiyangFeng/Desktop/local notification/platforms/android/cordova/build: Command failed with exit code 2
at ChildProcess.whenDone (/usr/local/lib/node_modules/cordova/node_modules/cordova-lib/src/cordova/superspawn.js:139:23)
at ChildProcess.emit (events.js:110:17)
at maybeClose (child_process.js:1015:16)
at Process.ChildProcess._handle.onexit (child_process.js:1087:5)


Issue to have signed apk after creating build.json file and feeling details as- Error: Unexpected token / in JSON at position 0