Android Studio notes

Russell Bateman
December 2015
last update:



Years ago, on Eclipse Galileo and Helios, in 2010, I wrote some Android applications. This is me trying to resurrect that knowledge, but using Android Studio (IntelliJ IDEA).


Android tools

http://developer.android.com/sdk/index.html —can take some time to download (380940715) at work where things are slow. I got to reading around and dicovered that, if one's already using IDEA, there's no point to getting the whole Android Studio.

—might be better to go look for Android plug-ins, then download the smaller, Android SDK. See Prerequisites for Android Development


Links worth listing...

Equipping IntelliJ IDEA with Android plug-ins...

...if you are already using this IDE before beginning to develop Android applications with it.

  1. File → Settings... → Plugins.

  2. Click Android Support if not checked already.

Install Android SDK
  1. Download the right one for your platform and explode it into your filesystem; see the Android Studio download page.

Create new Android project, Android Quickstart

This section includes how to get stuff set up except that it assumes you've already got Intelli IDEA and also the Android SDK download (not Android Studio, just the SDK).

I already had IntelliJ IDEA installed and didn't want to download and install the whole Android Studio shebang. After all, Android Studio is but the community edition of IntelliJ IDEA.

  1. With IntelliJ IDEA already up, do File → New → Project...,

  2. ...and click Android in the left pane.

  3. Ignore Gradle, just choose Application Module, and...

  4. click Next.

  5. Give your application a name, Hello (if you're following the tutorial that's at this link: Android Video Tutorials.

  6. Click Next. (If you're using a later version of IDEA than the tutorial, which is likely, you may find the project-creation wizard dialogs have changed, just roll with it, it will work out. I'm using IDEA 15 as I write this.)

  7. For Location, I'm using /home/russ/dev/new-android/Hello.

  8. For Project SDK:, I click the New... button and navigate to where I downloaded and exploded the SDK tarball. I get an error, "Cannot find any Android targets in this SDK." I click Open SDK Manager. I see this rather bewildering dialog (click to see full size):

    This is treated by JetBrains on at IntelliJ IDEA 15.0 Help / Prerequisites for Android Development and there is a link reference to detailed instructions for Adding SDK Packages where you're told, first off, that by default the Android SDK does not include everything you will need.

    In short, this means that you will need to make some choices in this dialog. Important note: when this linked page says, "Tools directory" or "Android folder," etc., "directory" and "folder" really mean sections to be expanded with options to click on inside this dialog.

  9. As I found that Android SDK Tools were noted as "already installed", I selected Android SDK Platform-tools (already selected actually) and also Android SDK Build-tools. Similarly, under Android 6.0 API (API 32), everything including SDK Platform (as noted at the link just above) was also already selected (including the ARM system image). Under Extras, Android Support Repository was not selected (so, I selected it), but Android Support Library was.

    Don't dismiss this dialog just yet.

  10. I didn't know whether I would want the extra Google helps. In general, I do not like the idea of "extra" stuff and here, knowing that these Google extras will not be on all tablets and phones, I decided against the temptation to use Google Play services, but I did in fact select Google Repository for whatever use that will be to me (mostly because this page told me to.

  11. Next, I clicked Install X packages.... In my case, this amounted to 19 packages. However, an alert came up telling me, confusingly, about some dependencies which my selctions would resolve anyway. Really, this is an end-user license agreement and what it needs isn't intelligence in making better or different choices in the (huge) main dialog, it just needed me to click the Accept License button, then click Install.

    I saw one error, "Stopping ADB server failed (code -1). I happen to know that this is the Android debugger. It probably tried to stop it; it wasn't running in the first place. (While the installation proceded, my host became sluggish and I lost my gvim cursor.)

    My host is pretty fast (i7 4GHz with SSD), but this took about 5 minutes. Ultimately, there was no button to dismiss this dialog except the close-window box.

  12. Back in the new-project wizard, I reclicked Project SDK: drop-down, but there was still nothing listed. I had expected to see Android 6.0 Plaform. Assuming that this was just some kind of bug, I clicked Finish instead, but an alert said, "An SDK is required for compiling, debugging and running applications, as well as for the standard SDK classes resolution."

    As the dialog offered me no SDK choices, except to navigate (but to where?), I'm stuck and have to resort to Google. Here's what I ended up doing:

  13. For Project SDK:, I clicked New, navigated to and selected ~/dev/new-android/android-sdk-linux, which was the explosion of android-sdk_r24.4.1-linux.tgz into my filesystem.

  14. I clicked OK then saw a dialog entitled, Create New Android SDK with:
    Java SDK:      1.7
    Build target: Android 6.0
    

    I clicked OK.

  15. Then, I saw Project SDK: "Android API 23 Platform (java version "1.7.0_67").

  16. In Target device:, based on what I was seeing in the JetBrains tutorial, I selected "Emulator".

  17. Then I clicked Finish and it replaced my previous workbench project with a new project named Hello. After a few seconds, the project was created. I expanded it to see:

    I put a comment on this here.

  18. At this point, I returned to tutorial with the fast-speaking Italian narrator and finished it.

Second beginning tutorial, Using the Android Visual Designer
  1. I note that it's apparently no use to use a JPeG in the first exercise. I found one in Google images, a 3D Droid, but had to convert it to PNG (and I made the background transparent while I was at it).

  2. Adding a text view (or label)...
  3. For the Textview widget, it appears now to be called Plain Textview. Here are the steps to using it:
    1. Drag the Plain Textview to the center (underneath the droid).
    2. Scroll down in Properties to text, but don't type in the value. Instead...
    3. Click in the ellipsis to get a Resources dialog,
    4. click the New Resource button,
    5. choose New String Value..., then...
    6. name this string resource (Resource name:), e.g.: "welcomeText", then
    7. fill in the Resource value: with something like "I'm so cool!".

    This string ends up on the path res/values/strings.xml.

  4. Next, we adjust the look of this new test...
    1. In Properties, expand padding and give all the size "10dp".
    2. For color (for instance), it's possible to introduce a new resource, just as we did for the text, and come up with some funky name like "greenMachine", with value #739C02, then reuse "greenMachine" elsewhere in your work. That way, you only have to change the value in one place to affect all uses.
    3. Similarly, create a resource name for large text that can be used here and there.

  5. I note that the "themes" stuff is very different in my version of the Android SDK designer. Simply put, I couldn't find the Theme control the instructor used to get rid of the application name at the top of the window. So, for example, if I want to get rid of the application name at window's top, I have to go into src/com/example/CoolDroid/MyActivity and add:
    requestWindowFeature( Window.FEATURE_NO_TITLE );
    
    by hand to the code to make this happen though I will not see this in the designer.

  6. Creating special preview versions aren't done at all the way the version of the designer he was using was shown.

At this point, I note that the formal Android Video Tutorials page has additional, useful stuff to cover:

  1. Events and the Android Coding Experience
  2. Android Unit Testing
  3. Packaging App[lications] for the Store
  4. Using Android SDK Tools from IntelliJ IDEA

And, I'm interested in all of them, though I'm acquainted with the events thing.

However, I'm tired of this and I think I'll move on to my friend, Lars Vogel.


Vogella: Lars Vogel's tutorial

I thought I'd try out Lars' new tutorial. I once wrote a page like this one alongside his original Android tutorial, but that one's been lost. I don't know how useful those notes will be.

http://www.vogella.com/tutorials/Android/article.html#androiddevelopment.

Lars states that "Android tooling uses Gradle as [its] build system". This does not appear to be true in the sense that you don't have to if you do not want to. Maybe I'll discover this to be true anyway. So far, I haven't used Gradle and I certainly do not plan to.


Android Unit Testing

JUnit works, but it can't be used to test Android-specific components for which there are wrappers. I haven't done this tutorial yet.


Using Android SDK Tools from IntelliJ IDEA

I want to make some observations on this.

  1. The list of SDKs I got (File → Project Structure → Platform Settings → SDKs) did not include anything like what the tutorial shows. For now, because I haven't set anything else up, I see only "Android API 23 Platform" (and no Android OS versions).

  2. When I did Tools → Android → AVD Manager, I couldn't see anything happen for the longest time. Ultimately, I discovered that the Android Virtual Device Manager comes up as nearly nothing, but an almost invisible booger in the top-left corner of my desktop, just under the menu bar (I'm running Cinnamon with just a top panel). I had to grab it and throw it open to see the list of virtual devices.

  3. Importantly, the instructor points out, by showing File → Android → Enable ADB Integration, that as long as this is checked, which it is by default, other Android debugging tools (he listed DDMS and Dalvik Monitor Server) cannot be used.

  4. There is no Draw 9-patch.

Android software component parts—at a glance
  1. Application, an Android application can have one Application class instance, instantiated as soon as the applications starts (and the last to stop when shutting down).
  2. Activity, the visual representation of an application; there can be several. Activities are the basis for the user interface.
  3. Context, connects to the Android system executing the application.

Additional notes breaking down Android development...

  1. AndroidManifest.xml, for configuring the application.
  2. Resource files
    • /res/drawables, images or XML files describing Drawable objects.
    • /res/values, definitions of strings, colors, dimensions, etc. via XML. (E.g.: /res/values/strings.xml.) Files that define the appearance of the application.
    • /res/layout,
    • /res/animator, definitions of animations in XML.
    • /res/raw, arbitrary files saved in their raw forms to be accessed via InputStream.
    • /res/menu, definitions of actions that can be used in the application toolbar.

Technology lists...

...toward functionality I know I'll need in an application I'm considering.


Fedora library issues

https://ask.fedoraproject.org/en/question/40247/how-to-install-android-development-libraries-on-fedora-2064bit/.