Sunlight 1.01 – New Android Studio Project

[Outdated*] Let’s begin the new Sunlight project using Android Studio 1.x.

[*Caution: Outdated content. My sunlight project has been discontinued. It refers to earlier versions of the v7 appcompat Library (21.0.3) and Android Studio (1.1).  I’ll keep the posts online for reference but with the current version of appcompat Library things may be different / easier today, so please refer to more up-to-date sources.]

This article refers to the first half of Lesson 1 of Googles Udacity Course “Developing Android Apps”. Branch 1.01-hello-world on GitHub. I will use the same naming scheme throughout this series.

The “New Project” dialog in Android Studio 1.x is slightly different from the version used in the Udacity video. The Package name is not editable in first place, but there is an “Edit” button at the end of the line. We’ll use the “.app” at the end of the package name to maintain comparability to the original course GitHub repository.

We also choose API 10 (Gingerbread) as Minimum SDK and choose the “Blank Activity with Fragment” Template.

Second difference in project creation: There is an input for “Menu Resource Name” in the last step of the wizard. Change it from “menu_main” to “menu” to keep comparability to the Udacity repo.

After the wizard and the inital gradle build have finished, let’s take a look at the differences in the generated code.
There’s an easy way to explore the differences via git. You may find my Sunlight/Sunhine repo on GitHub at https://github.com/kekiel/Sunlight. The original Sunshine project is located at https://github.com/udacity/Sunshine. Unfortunately is it not possible to compare branches of different repos in GitHub. So you have to do it on your machine.

How to compare two different GitHub repositories

Switch to an empty directory and clone the repo:

Add the Udacity repo and fetch it:

Change to branch you want to compare and view diff:

To list all available branches use

For a more comfortable view, you might want to use a git GUI tool like SourceTree:

Note: The .gitignore generated by Android Studio on enabling git version control is a little “too short”. We’ll take the one from the sunshine repo instead, which is basically what github generates as an Android .gitignore template added with the Android Studio / ItelliJ stuff.

What has changed so far?

Not that much. Let’s take a look at the most important changes:

build.gradle

There were lots of changes to the gradle integration in Android Studio in the pre 1.0 – phase. With the 1.0 release of Studio the gradle integration has finally reached a stable state.
The classpath has changed to com.android.tools.build:gradle:1.0.0 and mavenCetral has been replaced by jcenter as the linked repository.

app/build.gradle

compileSdkVersion and buildToolsVersion have switched to current versions (21). And the runProguard option is now called minifyEnabled

The AppCompat library has also been updated to com.android.support:appcompat-v7:21.0.3 which makes a big difference in the “look an feel” of the action bar as it includes Material Design even for pre Lollipop devices. (The v4 Support Library is included automatically, so its removed from the dependencies list.) You may want to read a detailed feature report in this android-developers blog article.

Visible differences

Thanks to the AppCompat v7:21 the app (with no changes in the main classes) automatically got an ActionBar with Material Design appearence:

What´s next?

OK – not much different in coding, but the visual results differ. In the next post we´ll replace good old ActionBar by the new Toolbar.

Leave a Reply

Your email address will not be published. Required fields are marked *