How to generate .apk file of the app built using ionic framework?

Hi everyone… Good Morning … I am done with my first app developed using ionic framework … Now I need to generate the version 1 of the app with .apk file format to test it in android phones … How can I do it ?? I am new to this ionic framework … Can anyone guide me ?

2 Likes

use the ionic cli or the creator.

run “ionic platform add android” --> this will download all necessary android parts
after that you can add native plugins your need: “ionic plugin add XXXXXX”

if you are finished run “ionic build android”.

Please be sure that your system fullfills the requirements (installed java sdk/jre and android sdk).

1 Like

Hi bengtler … thanks for the reply … I am using ubuntu OS … How to ionic cli or the creator in the terminal … pls guide me as I am very much new to this ionic framework …

Requirements:
NodeJS 4.x
https://nodejs.org/en/

first install latest cordova cli
npm install -g cordova

to install ionic cli
npm install -g ionic

Start a new ionic project
–> replace the sources in www-folder with your app code

There is a nice beginners guide:


And a complete guide:
http://ionicframework.com/docs/guide/

Thanks bengtler … I will check it … and revert back to you …

Error: /opt/lampp/htdocs/firsthive/fhapp.v5/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 emitTwo (events.js:87:13)
at ChildProcess.emit (events.js:172:7)
at maybeClose (internal/child_process.js:818:16)
at Process.ChildProcess._handle.onexit (internal/child_process.js:211:5)

May I know what is the mistake I am doing ??

When I executed $ cordova build command in the terminal within the project directory to rebuild the app, I got the following error messages :

Running command: /opt/lampp/htdocs/{app path}/hooks/after_prepare/010_add_platform_class.js /opt/lampp/htdocs/{app path}
add to body class: platform-android
Running command: /opt/lampp/htdocs/{app path}/platforms/android/cordova/build
[Error: Failed to find ‘ANDROID_HOME’ environment variable. Try setting setting it manually.
Failed to find ‘android’ command in your ‘PATH’. Try update your ‘PATH’ to include path to valid SDK directory.]
ERROR building one of the platforms: Error: /opt/lampp/htdocs/{app path}/platforms/android/cordova/build: Command failed with exit code 2
You may not have the required environment or OS to build this project
Error: /opt/lampp/htdocs/{app path}/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 emitTwo (events.js:87:13)
at ChildProcess.emit (events.js:172:7)
at maybeClose (internal/child_process.js:818:16)
at Process.ChildProcess._handle.onexit (internal/child_process.js:211:5)

Can anyone help me out with the solution ??

Running command: {Cordova Project Path at Home in Ubuntu }/platforms/android/cordova/build
[Error: Failed to find ‘ANDROID_HOME’ environment variable. Try setting setting it manually.
Failed to find ‘android’ command in your ‘PATH’. Try update your ‘PATH’ to include path to valid SDK directory.]
ERROR building one of the platforms: Error: {Cordova Project Path}/platforms/android/cordova/build: Command failed with exit code 2
You may not have the required environment or OS to build this project
Error: {Coordova Project Path}/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 emitTwo (events.js:87:13)
at ChildProcess.emit (events.js:172:7)
at maybeClose (internal/child_process.js:818:16)
at Process.ChildProcess._handle.onexit (internal/child_process.js:211:5)

The last post is what I have tried finally and the error message I have received … Can anyone help me out with the solution ??

where did you installed your android tools/sdk ? --> you have to extend your Path variable so ionic can find it

Ok I doubt I have installed the Android SDK or not … how to check it ?

try the command “whereis adb” or “which adb” --> if you get a path, then the adb-shell of the android tools are installed

Ok I am getting the following result :
adb:

It means ?? Not Installed ?

it seems so… try to install it

Okie … I will get back to you … after installing …

*lay back in the arms of someine… *sing

I did not get what you said … I need to know whether is it mandatory to install JRE and JDK for extracting the .apk file or can we do it without that also ??

nope the build process needs android and android need java, because everything for android is written i java code :wink:

1 Like

Thats Okie … so ultimately we need to install jre and jdk ??

yes you need at least the Java SDK