tag:blogger.com,1999:blog-73140619676001661772024-02-08T04:07:41.280-08:00Developing android apps from the linux command lineVicente Oscar Mier Velahttp://www.blogger.com/profile/17554877553762950519noreply@blogger.comBlogger1125tag:blogger.com,1999:blog-7314061967600166177.post-53053192832880779002015-05-09T11:10:00.000-07:002015-05-09T11:38:47.162-07:00How to install the Android Stand-alone SDK Tools on debian linux, and run your first appI'm using a brand new install of Debian Jessie to start developing my first android apps. I haven't found a good how-to on installing the <a href="http://developer.android.com/sdk/installing/index.html?pkg=tools">Android Stand-alone SDK Tools</a> on debian. I had to tweak the ones I've found.<br />
<br />
The first thing I did was to download the file <b><span style="font-family: "Courier New",Courier,monospace;">android-sdk_r24.2-linux.tgz</span> </b>from:<br />
<br />
<a href="http://developer.android.com/sdk/installing/index.html?pkg=tools">http://developer.android.com/sdk/installing/index.html?pkg=tools</a><br />
<br />
Once you've got the file, extract it's contents, <b><span style="font-family: "Courier New",Courier,monospace;">cd</span></b> to the directory containing the extracted tool files and run <b><span style="font-family: "Courier New",Courier,monospace;">android update sdk --no-ui</span></b> like so<span style="font-family: "Courier New",Courier,monospace;">:</span><br />
<b><span style="font-family: "Courier New",Courier,monospace;"><br /></span></b>
<b><span style="font-family: "Courier New",Courier,monospace;">$ tar -xvf android-sdk_r24.2-linux.tgz</span></b><br />
<b><span style="font-family: "Courier New",Courier,monospace;">$ cd android-sdk-linux/tools</span></b><br />
<b><span style="font-family: "Courier New",Courier,monospace;">$ ./android update sdk --no-ui</span></b><br />
<br />
Make sure you have an internet connection when doing this. The command will download and install the command-line sdk to develop android apps. Note that this will probably take a while.<span style="font-family: "Courier New",Courier,monospace;"></span><br />
<span style="font-family: "Courier New",Courier,monospace;"><br /></span>
You must have java installed in order to start developing for android using the command line tools. Don't worry if you didn't install java before installing the android sdk. In debian, you may use synaptic, apt-get, or aptitude to install java. On synaptic I just had to install <span style="font-family: "Courier New",Courier,monospace;"><b>default-jdk</b></span><span style="font-family: "Courier New",Courier,monospace;"><br /></span><br />
If you prefer aptitude, do (as root)<br />
<br />
<b><span style="font-family: "Courier New",Courier,monospace;"># aptitude update</span></b><br />
<b><span style="font-family: "Courier New",Courier,monospace;"># aptitude install default-jdk</span></b><br />
<br />
Or using apt-get<br />
<br />
<span style="font-family: "Courier New",Courier,monospace;"><b># apt-get update</b></span><br />
<span style="font-family: "Courier New",Courier,monospace;"><b># apt-get install default jdk</b></span><br />
<br />
Make sure you have the <a href="https://wiki.debian.org/SourcesList">required repositories</a> to install the package.<br />
<br />
The <a href="http://developer.android.com/training/index.html">official development tutorial for android</a> provides steps for <a href="http://developer.android.com/training/basics/firstapp/creating-project.html">creating a first test project</a>. But I couldn't get it to work on debian the way it was laid out on their page. One thing I had to do differently was to create the project with gradlew support, like this:<br />
<br />
<span style="font-family: "Courier New",Courier,monospace;"><b>$ tools/android create project --target android-16 \</b></span><br />
<span style="font-family: "Courier New",Courier,monospace;"><b>--name MyFirstApp --path workspace/MyFirstApp \</b></span><br />
<span style="font-family: "Courier New",Courier,monospace;"><b>--activity MyActivity \</b></span><br />
<span style="font-family: "Courier New",Courier,monospace;"><b>--package com.example.myfirstapp <span style="color: red;">-g -v 0.11.+</span></b></span><br />
<br />
The options in red are missing from the official android dev tutorial.<br />
<br />
After that, you will be able to compile your <span style="font-family: "Courier New",Courier,monospace;"><b>'Hello World'</b></span> app with:<br />
<br />
<b><span style="font-family: "Courier New",Courier,monospace;">$ ./gradlew assembleDebug</span></b><br />
<br />
To run your android project without an android emulator, you'll have to use your android device. First, <a href="http://www.kingoapp.com/root-tutorials/how-to-enable-usb-debugging-mode-on-android.htm">make sure you enable USB debugging on your device</a>, connect it to your PC via USB, and make sure your device is listed under the <b><span style="font-family: "Courier New",Courier,monospace;">lsusb</span></b> output. My device shows up like this:<br />
<br />
<span style="font-family: "Courier New",Courier,monospace;"><b>Bus 002 Device 004: ID 0fce:5172 Sony Ericsson Mobile Communications AB</b></span><br />
<br />
Then just load your recently compiled project as you normaly would, with<br />
<br />
<b><span style="font-family: "Courier New",Courier,monospace;">$ adb install app/build/outputs/MyFirstApp-debug.apk</span></b><br />
<br />
And just take it from there. Happy android programming!<br />
<br />
<b>NOTE:</b> If you're having trouble with "command not found" errors, make sure to either<span style="font-family: "Courier New",Courier,monospace;"><b> cd</b></span> to the directory where the commands live in your extracted files, or <a href="http://developer.android.com/training/basics/firstapp/creating-project.html">add the appropriate paths to your PATH environment variable</a>. Vicente Oscar Mier Velahttp://www.blogger.com/profile/17554877553762950519noreply@blogger.com0