How do I generate the "apk" of my IONIC application

Asked

Viewed 13,076 times

2

Following the documentation, should be two simple commands:

  1. To include the platform: ionic platform ios android
  2. To compile: ionic build android

However, I’m getting a lot of red error on the terminal, as shown below:

tela do erro no terminal linux

Edited so far: I solved part of the problem, however, I’m with new mistakes:

Following the tips, I unzipped the Android JDK in the folder /usr/local.

And include at the end of the file ~/.profile the lines below:

export ANDROID_HOME=/usr/local/android-sdk-linux
export PATH=${PATH}:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools

Then I executed the command: source ~/.profile

And then I executed the commands below:

 echo >> /.profile
    echo "export ANDROID_HOME=/usr/local/android-sdk-linux" >> /.profile
    echo "export PATH=${PATH}:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools" >> /.profile
    . /.profile

I followed a few steps through of this reference:

And now it’s displaying the following error:

➜  TesteApp  ionic build android          
Running command: /var/www/html/apps/TesteApp/hooks/after_prepare/010_add_platform_class.js /var/www/html/apps/TesteApp
add to body class: platform-android
Running command: /var/www/html/apps/TesteApp/platforms/android/cordova/build 
[Error: Please install Android target: "android-22".

Hint: Open the SDK manager by running: 
You will require:
1. "SDK Platform" for android-22
2. "Android SDK Platform-tools (latest)
3. "Android SDK Build-tools" (latest)]
ERROR building one of the platforms: Error: /var/www/html/apps/TesteApp/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/apps/TesteApp/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)

I also ran the commands to install android-22:

cordova platforms remove android
cordova platforms add [email protected]

And I got the following message:

Adding android project...
Creating Cordova project for the Android platform:
    Path: platforms/android
    Package: com.ionicframework.ionicgooglemap340659
    Name: TesteApp
    Activity: MainActivity
    Android target: android-22
Copying template files...
Android project created with [email protected]
Running command: /var/www/html/apps/TesteApp/hooks/after_prepare/010_add_platform_class.js /var/www/html/apps/TesteApp
add to body class: platform-android

But when I execute the command ionic build android, still shows the same error.

What needs to be done to make it work without errors, I already have Java JDK installed, need to do some more JAVA configuration?

  • I get the same mistakes. You have to see that there.

  • You have installed the Android SDK ?

  • No, you need to install?

  • I haven’t tested with Android yet. Only iOS.

  • No doubt need to install and do not have to set any path for application, have to set the path to sdk.

  • As @devgaspa said, you need the android and java SDK.

  • In this Tutorial in English it teaches to mount the linux environment for only Cordova so start from the Install Java it teaches to install all dependencies to generate android APK(Java, Ant and Android SDK). Pay close attention and make sure you’re doing it right, mistakes when generating development environment are terribly terrible.

  • @Ivanferrer you installed these 3 items ? 1. "SDK Platform" for android-22 2. "Android SDK Platform-tools (Latest) 3. " Android SDK Build-tools" (Latest)

  • type android on the console, search API 22 and low, or if you prefer can change the version in the manifest file in the android folder of the application.

  • Well, I downloaded from this link: http://dl.google.com/android/android-sdk_r24.4.1-linux.tgz. and unzipped.

  • is the main site of the Android JDK: http://developer.android.com/sdk/installing/index.html

Show 6 more comments

1 answer

1


I was using zsh instead of batch.

I managed to solve by doing the following, I typed in the console:

cd ~/

ls -lha

vi .zshrc

I have included the following lines:

export ANDROID_HOME="/usr/local/android-sdk-linux"
export PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/android-sdk-linux/tools:/usr/local/android-sdk-linux/platform-tools"

I installed Android SDK, and all Java JDK dependencies.

On the terminal I typed only "android" and opened the Android SDK Manager:

There I selected only the items of the Android version that I needed and had installed.
Then I executed the command line:

 ionic build android

And it worked! he created the apk on:

/var/www/html/apps/TesteApp/platforms/android/build/outputs/apk/test-app.apk

Browser other questions tagged

You are not signed in. Login or sign up in order to post.