Tuesday, July 16, 2024
How to make an Android app on Linux?
In order to program on the Android platform, we must know Java (programming language). Personally, I don't think of learning another programming language. Fortunately, there are several solutions with which you can create an app with HTML/CSS/JS.
Of course, this tutorial is intended for those who use modern technologies =), meaning Linux - that is, Archlinux (or derivatives). Although all this should work on ubuntu/debian systems as well.
First we will install the 'gradle' package and we will also need 'nodejs', so install that too (if you don't already have it):
sudo pacman -S gradle
Debian/Ubuntu
sudo apt-get install gradle
Furthermore, we download the 'Command Line Tools' here. The downloaded file looks like this 'commandlinetools-linux-7583922_latest.zip'.
Open a terminal and 'cd' to the path where you downloaded the file:
cd ~/Downloads
Next, we will create a destination directory and unzip the archive:
sudo mkdir /opt/android-cli-tools/
sudo unzip ./commandlinetools-linux-7583922_latest.zip -d /opt/android-cli-tools/
And finally, we just move everything to the 'tools' directory:
cd /opt/android-cli-tools/cmdline-tools
sudo mkdir tools
sudo mv -i * tools ###ignore message: mv: cannot move 'tools' to a subdirectory of itself, 'tools/tools'
The directory '/opt/android-cli-tools/' looks like this:
android-cli-tools
└── cmdline-tools
└── tools
├── NOTICE.txt
├── bin
├── lib
└── source.properties
We need to give access to tools on a global scale. So we open:
nano ~/.bashrc
Enter at the end of the file:
export ANDROID_HOME=/opt/android-cli-tools
export PATH=$ANDROID_HOME/cmdline-tools/tools/bin/:$PATH
export PATH=$ANDROID_HOME/emulator/:$PATH
export PATH=$ANDROID_HOME/platform-tools/:$PATH
CTRL+O to save the changes in the Nano editor and then activate the changes in the terminal with the command (restart of the computer is required):
source ~/.bashrc
We install the Android SDK (it's slow, so leave it and watch a movie while it downloads):
sudo /opt/android-cli-tools/cmdline-tools/tools/bin/sdkmanager --install "platform-tools" "platforms;android-29" "build-tools;29.0.2" "emulator"
Cordova
Cordova allows us to write code in html/css/js with the possibility of exporting the project to the browser, android or ios platforms.
We install and create the 'hello' project:
sudo npm install -g cordova
cordova create hello com.example.hello HelloWorld
cd hello
Now we can check that we have everything we need:
cordova requirements
# Requirements check results for android:
# Java JDK: installed 1.8.0
# Android SDK: installed true
# Android target: installed android-29
# Gradle: installed /usr/share/java/gradle/bin/gradle
Add platforms:
cordova platform add android
cordova platform add browser
cordova platform add ios
#list platform: cordova platform ls
Project build with:
cordova build
We start the finished browser project with:
cordova run browser
Or for Android (I have scrcpy installed):
cordova run android
UPDATE
If you recieve message:
Package signatures do not match the previously installed version
Uninstall old app from android.
By the way, sometimes it is necessary to install additional: platforms and build-tools with sdkmanager.
Deinstalirajte staru aplikaciju s androida.
Usput, ponekad je potrebno instalirati dodatne: platforms i build-tools sa sdkmanager-om.
A na Debian-u (vjerovatno je isto na Ubuntu) sam ranije trebao instalirati:
And on Debian (probably the same on Ubuntu) I should have installed earlier:
sudo apt install default-jdk
sudo apt install default-jre
If you have in terminal:
No Java files found that extend CordovaActivity.
Enter:
cordova platform rm android
cordova platform add android