Differences between revisions 3 and 4
Revision 3 as of 2017-10-13 21:02:30
Size: 5034
Editor: ?FernandaQueiroz
Comment: Changed instruction to acquire SDK licenses
Revision 4 as of 2018-09-28 05:50:26
Size: 5042
Editor: PaulWise
Comment: don't copy the README into the licenses directory
Deletions are marked like this. Additions are marked like this.
Line 69: Line 69:
  ~/Git$ '''sudo cp''' -a android-sdk-licenses/. /usr/lib/android-sdk/licenses   ~/Git$ '''sudo cp''' -a android-sdk-licenses/*-license /usr/lib/android-sdk/licenses

This is a tutorial for building an Android app using only Android SDK and development tools already available into Debian. For this tutorial we will work on debian stretch 9.2 with the source code of F-droid app.

Currently there is only the target platform of API Level 23 packaged, so only apps targeted at android-23 can be built with only Debian packages. We will add more API platform packages via backports afterwards. Only Build-Tools 24.0.0 is available, but we will use the android-sdk-helper package so we won't need to modify the build scripts in order to use the SDK.

Preparing the environment

  • # apt install android-sdk android-sdk-platform-23 git libgradle-android-plugin-java

Obs1: Git is the recommended method to obtain the source code of the android application.

Obs2: The last package is needed to meet the dependency of android-sdk-helper, which is not in stretch repositories yet

Get the android-sdk-helper from the testing repository

Right now, android-sdk-helper is not available in stretch backports, so we will have to add testing/buster repository. Edit the /etc/apt/sources.list file and add the following line:

deb http://ftp.debian.org/debian buster main

You can also find a list of other mirrors at https://www.debian.org/mirror/list

The next step is to create/edit your /etc/apt/preferences file. preferences is where the apt-pinning takes place. Normally, the highest version of an available package wins, but we will override that.

Create/edit the preferences file so it looks like this:

Package: *
Pin: release a=stable
Pin-Priority: 700

Package: *
Pin: release a=testing
Pin-Priority: 650

Note the descending values. Since Stable has the highest pin-priority, it will be installed preferentially over Testing.

Getting F-droid source code

Let's create a Git folder in your home directory and clone the F-droid source code into it


Some tweaks will be necessary so everything can work as expected

Accepting SDK license

To use the android-sdk you must accept its license. At the present moment there are some ways to do so, but none of them is perfect.

In this tutorial we'll clone a git repository containing all the needed licenses and copy them to the right location.

Note that this is a temporary solution. We can expect that in the future there will be offered an automatic solution for accepting the SDK license.

Define your SDK location

In the top folder of your app project, you need to create a file called local.properties that says where your SDK is. In our case, this file needs to have the following single line:

# SDK location

Disabling lint

Since the Lint in this version of Gradle Android Plugin is still problematic, running the :lint tasks might not work. They can be turned off editing the file build.gradle in the app folder.

Open this file with your prefered editor and search for the line that says abortOnError inside the lintOptions method. Then change it to false

Change Heap Size (in case gradle complains about the speed)

After you start builing your app with gradle you might get a warning like this:

To run dex in process, the Gradle daemon needs a larger heap.
It currently has 1024 MB.
For faster builds, increase the maximum heap size for the Gradle daemon to at least 1536 MB.
To do this set org.gradle.jvmargs=-Xmx1536M in the project gradle.properties.

If it happens to you, obey your computer and create the file gradle.properties in the root folder of your project and add the line


Change locale (for some timezones)

There is currently an unexpected behaviour in F-droid building process that results into an error when the project is built in some timezones. If the gradle fails with the message

  • Execution failed for task ':app:testDebugUnitTest'

You can fix it by temporarily changing your timezone to GMT+1 with the command. Run the gradle command, and after everything is done remember to use this command again to return to your regular timezone.

  • # dpkg-reconfigure tzdata

Building the app

After you follow all the past steps, you probably will be able to build the project easily with the following command.

  • ~/Git/fdroidclient$ gradle build --init-script /usr/share/android-sdk-helper/init.gradle