Вы находитесь на странице: 1из 6

Android APK building using Cordova, Gradle,Android SDK in Linux Platform

Required Software

NVM and Node JS

Cordova CLI - 8.1.2 at the moment

Android SDK and CLI

Java Development Kit 1.8.0

Step1: Installing NVM and Node JS

curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.1


1/install.sh | bash

To install the latest version, get the up-to-date command here.

Re-open the terminal so that npm command would become available and run:

*if facing any error for installing nvm export repo using below command

“export NVM_NODEJS_ORG_MIRROR=http://nodejs.org/dist”

nvm install 11

The above command will install nvm with version 11

Step2: Installing Node global packages

npm i -g cordova

To check installed cordova version we can use

“cordova –version”

Step3: Installing Java Development Kit

The next thing necessary for Cordova/Android development is JDK. Installation command

yum install java-1.8.0-openjdk-devel

You need also set $JAVA_HOME environmental variable to /usr/lib/jvm/java-1.8.0-openjdk-


1.8.0.191.b12-1.el7_6.x86_64. Your path may be different, but $JAVA_HOME should certainly point
to the directory that contains ./bin/java executable. To do this, open your ~/.bash_profile file in Vim
editor and append the following:

export JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.191.b12-1.
el7_6.x86_64
*Please check the correct java version installed.

The changes in .bash_profile do not take place immediately, and to apply them, you need to
reconnect to the server or run source ~/.bash_profile.

Step4: Installing Gradle

Gradle is a build-automation system which is necessary for making Android builds. In order to install
Gradle, we need to download it first

wget https://services.gradle.org/distributions/gradle-5.1-bin.zip

*Install Gradle with certificate only else may get java error later.

Now create the destination folder and unzip Gradle in there:

mkdir /opt/gradle
unzip -d /opt/gradle gradle-5.1-bin.zip

Add Gradle path to your $PATH variable in your ~/.bash_profile file:

PATH=$PATH:$HOME/bin:/opt/gradle/gradle-5.1/bin

Check if Gradle is installed correctly:

source ~/.bash_profile
gradle -v

Step5: Installing Android CLI and SDK packages.

Download the latest Android Command Line tools . Do not download Android Studio, scroll to
command line tools only.

wget https://dl.google.com/android/repository/sdk-tools-linux-433
3796.zip
mkdir -p /opt/android

Move the archive to /opt/android (so that it is available under /opt/android/tools), unzip it in there,
and add to the $PATH environment variable /opt/android/tools and /opt/android/tools/bin.
android, sdkmanager, and other CLI commands should become available, but note that they would
work only if you set $JAVA_HOME environment variable correctly.

Eventually, your $PATH variable should look like the following:

PATH=$PATH:$HOME/bin:/opt/android/tools:/opt/android/tools/bin:/o
pt/gradle/gradle-5.1/bin

Do not forget to source ~/.bash_profile before proceeding to the next step.


Step6: Install SDK packages. To check available packages, run

sdkmanager --list

Among the list, we'd need the latest version of build tools and platform-tools, as well as Google Play
Services – if you use their features such as push notifications. To install Google Play Services, run:

sdkmanager "build-tools;28.0.3" "platform-tools" "platforms;andro


id-28" "extras;google;google_play_services"

Instead of "platforms;android-28" or "build-tools;28.0.3" use the latest version available.

The script will start downloading the updates. Accept the license agreement and wait till installation
finishes.

If you run sdkmanager --list once again, you will see the installed packages at the beginning of the
output. And just in case, If you received Warning: File /root/.android/repositories.cfg could not be
loaded when trying to use sdkmanager, run touch ~/.android/repositories.cfg.

Now add the $ANDROID_HOME variable to your .bash_profile

export ANDROID_HOME=/opt/android

Do not forget to source ~/.bash_profile before proceeding to the next step.

So now we are ready to go.The first Android build would take some time, but the subsequent ones
will finish much faster.

***If getting any java connection error

Please follow below steps.

Copy the certificate using below steps.


Click the green lock in webpage ConnectionsMoreinformationView CertificateDetail

Then select Export certificate

 Then save the certificate


Then copy the certificate to the server/environment and run below command
“keytool -import -alias Gradle1 -keystore $JAVA_HOME/jre/lib/security/cacerts -file
/tmp/gradle_org.crt”

Password for certificate installation:”changeit”


Step7: Add cordova platform

$ cordova platform add ios

$ cordova platform add android

Step8: Check all the cordova requirements are installed .Use below command

“cordova requirements”

Step 9:Run “npm build”

Step10: Make APK using cordova build android

“cordova build android”

Вам также может понравиться