Differences between revisions 1 and 2
Revision 1 as of 2017-10-13 17:54:22
Size: 5275
Editor: ?FernandaQueiroz
Comment:
Revision 2 as of 2017-10-13 18:00:52
Size: 5327
Editor: ?FernandaQueiroz
Comment:
Deletions are marked like this. Additions are marked like this.
Line 1: Line 1:
## page was renamed from AndroidTools/BuildingApps

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

Adjustments

Some tweaks will be necessary so everything can work as expected

Accepting SDK license

To use the android-sdk you must accept its license, and right now the best way to do it is to install Android-Studio and copy all the contents from its license folder to the licenses folder inside your regular android-sdk installation path. Usually this command will work:

  • # cp -a /opt/android-studio/license/. /usr/lib/android-sdk/licenses/

Another solution is to create the file /usr/lib/android-sdk/licenses/android-sdk-license. The first line should be blank and the second line will have a hash with the license.

8933bad161af4178b1185d1a37fbf41ea5269c55

Note that this is a temporary solution because the license hash is updated once in a while, which will force you to change this file very soon.

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
sdk.dir=/usr/lib/android-sdk

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

org.gradle.jvmargs=-Xmx1536M

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