How to Develop Android Apps in Linux

Android-Studio-Featured-Image

It can be intimidating if you’re just starting out to develop an app for Android. Here you will find everything you need to know about building, publishing, and releasing an app on Android.

Tip: if you just want an Android app without the hard work of coding it yourself, check out these platforms that allow you to create Android apps easily.

How Android Applications Work

Android applications can be built in Java, Kotlin, or C++. Most modern Android applications are built in Kotlin. Both Java and Kotlin can combine into Java-byte code files. This process translates the programming human language to binary computer language.

These files, along with images, layouts, and fonts, are compressed into one package, called an APK file.

How to Set Up the Android Development Environment

A development environment is all the software tools you need to create applications. In Android, this is the Android software development kit, or SDK.

Android Studio

Android Studio is the official IDE for developing Android applications. The simple interface and the fact that it preinstalls all SDK components makes it a popular choice for upcoming developers.

To use snap to install it in Linux, navigate to the snap store and install “Android Studio.”

Android Studio Snap Store Screenshot

The installation package is also available on the Android Studio website. There are alternative PPA’s that you can use, but you may not be getting the latest version and will have to install each individual component.

Install the following dependencies:

sudo apt-get install libc6:i386 libncurses5:i386 libstdc++6:i386 lib32z1 libbz2-1.0:i386

These are 32-bit libraries that you need for developing on 64-bit machines. as many Android devices still use 4GB RAM or less. Download and unpack the Android studio archive to the folder where you want to install the application.

Start the application with the following terminal commands:

cd "<your application folder>/bin"
./studio.sh

From there, you should be able to select your settings and components that you want to install.

Android Studio Installation Screenshot 1

The standard installation will install all the components you need for developing Android applications using Java. Kotlin is integrated into Android Studio and doesn’t require any additional installation.

How to Publish an Android Application

Now that you’ve developed your Android app that will change the world, you need to get it on the app store.

Versioning

Versioning is the simple process of naming and numbering the version of your application. This allows users to know which version of the application they’re installing. As a developer, you can restrict application versions to certain Android distributions. By doing this, you can implement advanced features for the latest Android devices but still allow weaker devices to access the app.

Add the following lines to your “build.gradle” file.

android {
   ...
    defaultConfig {
    ...
        versionCode = 7
        versionName = "7.0"
    }
    productFlavors {
        create("Sun") {
        ...
            versionName = "7.0-Sun"
        }
        create("Moon") {
        ...
        }
    }
}

The versionCode is an internal indicator of how many versions of your application have been released. versionName is how users will see the release name, and productFlavors is to lock a certain version to a flavor. To restrict the versions your application can run on, use the following code:

android {
    ...
    defaultConfig {
        ...
        minSdkVersion(31)
        targetSdkVersion(31)
    }
    productFlavors {
        create("Sun") {
          ...
        }
        create("afterLollipop") {
          ...
          minSdkVersion(21)
        }
    }
}

We restricted our application to Android 12, or SDK version 31 using minSdkVersion . We also said our “Sun” version can run on versions after SDK version 21.

End-User License Agreement (EULA)

An end-user license agreement – or EULA – tells users what they can do with the application. You don’t want someone modifying your code and publishing their own application, but maybe you want to allow users to add their own mods to the application. A EULA allows you to dictate all of this. You can generate your own EULA online or create one of your own.

Cryptographic Keys

In the same way that you have a key that opens your front door, your application needs a key to identify you as the owner. Cryptographic keys also allow other applications and services to know your app is trustworthy. This prevents malware from infecting users’ devices or attacking web services everyone uses.

To generate your key, navigate to “Build” on the top-bar. Select “Generate Signed Bundle,” then “Android app bundle.” From there, create a new key. This will create an upload key. However, to publish an application on the Google Play store, you also need an “app signing key.” These are stored on users’ devices.

Play App Signing

To generate an app signing key, sign in to your Play Console. Create your release and choose a method of release. You can release your app for open testing, closed testing, internal testing or a production release.

Once you’ve done that, enter the “App Integrity” section, which should generate a new key if this is your first time releasing the app.

How to Create an Android App Bundle

If you’re going to upload your app to the app store, users need to be able to download a package with your compiled source code that their devices can install. App bundles allow Google to create APK packages for each version you selected and distribute them just as easily.

You can build it on the command line using these commands:

cd "<your application folder>/bin"
./gradlew bundleRelease
jarsigner -keystore <pathToKeystore> app-release.aab <keyAlias>

Another method is to generate a signed bundle using Android Studio, which you can do by navigating to the Build section on the top-bar. Once you’ve done that, you can drag and drop your app bundle in the “App bundles and APKs” section on the play console. Remember, it has to be under 150MB.

Rollout

It’s finally time to roll out your app for everyone to use. Before doing that, make sure that your app’s pricing and page is correct on the “App Content” page. Navigate to the “Releases Overview” page and select “Start Rollout.”

Frequently Asked Questions

Do I need an Android device to start developing?

No. A device is helpful for testing and making sure your app looks the way you want it to. However, you don’t actually need one to develop applications for Android. Emulation allows you to test on your computer. The whole suite of Android tools is meant to make developing on your PC possible.

Is it possible to develop apps without using Google Play?

You can develop Android apps without Google Play. The tools that Google offers are helpful in distributing applications to a wide range of users and learning the tricks of the trade. Your users will need to allow third-party app installations, but nothing stops them from using your app if you don’t want to use the Google Play Store.

Image credit: The Android robot in the featured image is reproduced or modified from work created and shared by Google and used according to terms described in the Creative Commons 3.0 Attribution License. All Screenshots by Nathan Meyer

Subscribe to our newsletter!

Our latest tutorials delivered straight to your inbox