[Android-tools-devel] Where is the file build.gradle?
paul_adt at kaffeemitkoffein.de
paul_adt at kaffeemitkoffein.de
Mon Oct 2 08:01:16 UTC 2017
Dear Tizio,
the debian build tools work like a charm, however I found the tutorial
quite short and it took me a couple of hours to get everything to work.
Therefore, I wrote a small "how-to" that explains how to compile an
android app with the debian tools:
Debian stretch, which has been released in July 2017 (see
https://bits.debian.org/2017/06/stretch-released.html), now includes all
the necessarypackages to build android apps from scratch ( see
https://bits.debian.org/2017/03/build-android-apps-with-debian.html).This
means that you can build your Android app without using any proprietary
software from Google.
As explained in the “Bits from Debian” blog
(https://bits.debian.org/2017/03/build-android-apps-with-debian.html),
the Android Tools Team at the current point does not support everything
that is possible with Android Studio and/or the binaries provided by
Google, but it is more than sufficient to build your own open source app
with the now available open source SDK. The available SDK packages make
it possible to build Android apps against the API Level 23
(“Marshmellow”). As Android is an open source operating system, you now
have an open source SDK.
However, I found the explanations given by the Android Tools Team very
compact. In truth, it took me many hours to establish a working build
environment and to build my first app with the Debian tools. For this
reason, I found it worth to give some more explanations on how to do this.
1. Prerequisites
You need to install Debian Stretch. When saying Debian Stretch, I mean
https://www.debian.org/releases/stretch/ . As this stuff is very new to
Debian, I do not know if it is already included in any Debian
derivatelike Ubuntu. Personally, I was not able to install the SDK
successfully on Ubuntu 16.04. You may take a pen drive and install
Debian Stretch on it to test the SDK. That is the way I did it.
After running Debian Stretch, of course, there are some packages you
need to install first:
Do a fresh update of your packages database:
apt-get update
Install the necessary packages to build an Android app:
a) You need the openJDK:
apt-get install default-jdk
b) You need the Android SDK as outlined in
https://bits.debian.org/2017/03/build-android-apps-with-debian.html:
apt-get install android-sdk android-sdk-platform-23
c) You need to install Gradle
apt-get install gradle
d) You need to install the Gradle-Android-Plugin
apt-get install libgradle-android-plugin-java
e) To properly sign your apk file after it is build, you need to install
apksigner:
apt-get install apksigner
2. Short explanation on how the whole thing works with Gradle
Gradle is a build tool that we use to build Android apps. Basically, you
create a file called build.gradle that describes what needs to be done
to build your app. To build Android apps with Gradle and the SDK
provided by the Debian Android Tools Team, you need some basic
understanding on how Gradle works.
To get some understanding about gradle that goes beyond this short
tutorial, you may have a look at
http://tools.android.com/tech-docs/new-build-system/user-guide that
explains why and how Gradle is used for Android.
3. Define where your SDK is
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.dir=/usr/lib/android-sdk
4. The project directory structure
Before building, you need to have a look at the structureof your app
project. If you are coming from the eclipse plugin, you will notice that
the default directory structure that gradle expects is a little bit
different than what you are used to. This is well described here
http://tools.android.com/tech-docs/new-build-system/user-guide in the
section “Project Structure”. Basically, you have to say Gradle in the
build.gradlefile what your structure looks like.
The typical and minimalistic structure of your Android app should look
like this:
MyAppProject
+src/main/AndroidMaifest.xml (your AndroidManifest.xml file)
+src/main/java/ (your java source code goes here)
+res/ (your resources go here)
+build.gradle (your build.gradle file, see later)
+local.properties (a file saying where your SDK is)
5. Write the build.grade file for your app project
In the top folder of your app project, you need to create a file called
build.gradle. This file describes what Gradle needs to do to build your
app. For the needs of an Android app, the basic structure of this file
is quite simple:
buildscript {
repositories {
// this defines a local maven repository that is installed with the sdk
maven {url “file:///usr/share/maven-repo” }
}
dependencies {
// this tells Gradle to use the gradle android plugin installed locally
classpath “com.android.tools.build:gradle:debian”
}
}
// this tells Gradle to use the android plugin defined above
apply plugin: “com.android.application”
android {
// here goes the specific android stuff for your app.
CompileSDKVersion = 23
buildtoolsVersion=”24.0.0”
// we define that Lint errors do not abort the build process.
lintOptions {
abortOnError false
}
// we define our directory structure, because it is not 100% what Gradle
expects
souceSets {
main {
java.srcDirs =[“src”]
res.srcDirs=[“res”]
}
}
}
6. Build your project
Go into the top folder of your project (where the build.gradle file is)
and run
gradle build
If everything went fine, you will find your unsigned apk file in
build/outputs/apk/ named MyAppProject-unsigned.apk.
7. Sign your app before installation / publication
To install the apk file on an android device, you need to sign it with
your key first. At this point, we assume you have a key to use for
signing an app. (A self-signed key pair is sufficient! If you do not
have one, please see the documentation of apksigner for details.)
In the build/outputs/apk/ directory, do the following:
apksigner sign --ks yourkey.keystore MyAppProject-unsigned.apk
8. End
You have done it!
Am 02.10.2017 um 01:04 schrieb tizio incognito:
> Acording to the tutorial in AndroidTools - Debian Wiki I should edit the file build.gradle, but I don't know where to find it.
>
> |
> |
> |
> | | |
>
> |
>
> |
> |
> | |
> AndroidTools - Debian Wiki
> | |
>
> |
>
> |
>
>
>
>
>
> _______________________________________________
> Android-tools-devel mailing list
> Android-tools-devel at lists.alioth.debian.org
> http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/android-tools-devel
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.alioth.debian.org/pipermail/android-tools-devel/attachments/20171002/9c75ff2c/attachment-0001.html>
More information about the Android-tools-devel
mailing list