Android Studio guide for BNR Android Programming book


#1

Thought I started this thread on those who are thinking of using Android Studio as the IDE to study BNR Android programming. I initially started off using Eclipse but realized its riddled with so many errors and incompatibility as compared to the book’s instructions at the present moment. For example, creating a Blank Activity in Eclipse will not create an activity layout file in Chapter 1. I found Android Studio to be a lot more stable as compared to Eclipse with far more intelligent coding suggestions for autocomplete.

The problem is that the interface presented in Android Studio seems to be very different to what is specified in the book as it is based on Eclipse. Hence, I hope this thread will provide clear instructions on how to perform the same actions on Android Studio as the book does on Eclipse. I am currently on Chapter 5, and will update this thread as I progress through the chapters.


#2

Sample Device: LG G2

Downloading required device drivers - This portion is a reference only for the above mentioned sample device. Mine was purchased from Singapore.

  1. Plugin Device into PC using USB
  2. Go to lg.com/sg/support/software-manuals
  3. Enter Model Number - See back of phone Eg: LGD802
  4. Select Software Update from Downloads section
  5. Select Download For USB drivers for Windows
  6. Run the executable and install the drivers

Enable Developer Mode

  1. From device, go the settings (General tab) -> About phone->Software information
  2. Tap Build Number (About 4 times) until developer options is enabled
  3. Enable USB debugging
  4. Plugin device to PC using USB
  5. From USB connected notification, tab notification
  6. Change from MTP to PTP
  7. Wait for installing new device drivers to complete
  8. From Windows, Open device manager, check to ensure ADB interface is listed

Restart ADB

  1. From Android Studio, select Android device monitor (Beside question mark)
  2. if devices listed as unknown, open device, check if there is an allow usb debugging console. Select OK
  3. if there is no console appearing on device, select view menu (last option) under device tab, select restart adb. Repeat step 2. Console should appear.

Check targetSdkVersion

  1. From Android studio, navigate to projectname->app->build.gradle
  2. Ensure targetSdkVersion is not listed as ‘L’. It should be set to your device api level or higher. But must not be ‘L’, unless you have configured your device to work with previews.

#3

Set Compile Build SDK

  1. Right click project name, open module settings
  2. Change compile SDK settings from properties tab

Chapter 1 - Locating R.java in Android Studio

  1. Ensure you make the project first (Select Build -> Make Project)
  2. R.java is located at app->build->source->r->packagename

Chapter 1 - Locating strings.xml

  1. strings.xml is located at app->src->main->res->values

Chapter 2 - Android Studio: How to create quick clones or copies of current project

  1. Copy project in the file directory
  2. Open Android Studio and Import the copied project from the file directory

Chapter 2: Generate Getters and Setter on Android Studio

  1. From Android Studio, File->Settings
  2. Under Code Style, select language of choice(Eg: Java)
  3. Select code generation, enter m for Field and s for Static Field under the column Name prefix
  4. Right click activity class (eg: Quizactivity.java), select refractor->encapsulate fields
  5. Select fields to generate getter and/or setter
  6. Select refractor

Chapter 3 - Open Log Cat on Android Studio

  1. Press Alt+5 on Windows
  2. Select the tool icon, select floating mode

Chapter 4 - Android Studio: Opening DDMS

  1. Hit Alt+6 or Click 6:Android at the bottom of the terminal

Chapter 4 - Android Studio: Adding breakpoints

  1. Run -> View Breakpoints
  2. Click the + icon to add a new java exception

Chapter 4 - Android Studio: File Explorer

  1. Open device manager (icon beside question mark)
  2. File explorer is located on the 5th tab to the right

Chapter 4 - Android Studio: Open Android Lint

  1. Analyse->Inspect Code
  2. To find the error as prescribed in the book, look under Android Lint heading on the list of errors and warnings displayed

Chapter 5 - Android Studio: Creating a new layout

  1. Navigate to app->src->res->layout
  2. Right click layout folder, select new->xml->layout xml file
  3. Enter activity_cheat in the layout file name. (Omit the extension of xml as Android studio will figure out for you)

Chapter 6 - Android Studio: Accessing SDK Versions and Compatibility

  1. In Android Studio, the SDK versions for minimum required, target and build are not set in AndroidManifest.xml. They are set in build.gradle. To access build.gradle, go to app->build.gradle
  2. To replicate the SDK error in Android lint, first ensure that the minSdkVersion in build.gradle is set lower than 11. I set mine to 8 as specified in the book.
  3. To run lint, select analyse -> inspect code from the toolbar in Android Studio.
  4. Under Android Lint heading, look for Attribute unused on older versions error. You should find this error message: Attribute “showAsAction” is only used in API level 11 and higher (current min is 8) (at line 7)

#4

Chapter 7 - Configuring build.gradle to work with older builds

Issue: This seems to be a bug with Android Studio. When you configure a project to work with very old APIs (eg: below 11), Android Studio seems to mess up the configuration. You can see example of the issues:

  1. stackoverflow.com/questions/2443 … ersion-142
  2. stackoverflow.com/questions/1658 … io-project
  3. reddit.com/r/androiddev/comm … _versions/

Apparently, the issue seems to arise from compatibility with L sdk.

In any case, the solution is to add compile ‘com.android.support:support-v4:20.+’ and compile ‘com.android.support:appcompat-v7:20.+’ in the dependencies setting in build.gradle (app->build.gradle). If you are using a different targetSDKversion, ensure that the value between the ‘:’ and ‘.+’ is set to your target sdk version. Once you have done that, sync gradle and make the project again.

This is how the build.gradle should look like.

[code]apply plugin: ‘com.android.application’

android {
compileSdkVersion 20
buildToolsVersion “20.0.0”

defaultConfig {
    applicationId "android.bignerdranch.com.criminalintent"
    minSdkVersion 8
    targetSdkVersion 20
    versionCode 1
    versionName "1.0"
}
buildTypes {
    release {
        runProguard false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}

}

dependencies {
compile fileTree(dir: ‘libs’, include: [’*.jar’])
compile 'com.android.support:support-v4:20.+'
compile ‘com.android.support:appcompat-v7:20.+’
}[/code]

Chapter 7 - Creating the CrimeFragment class in Android Studio
Unfortunately in Android Studio, there does not seem to be a wizard to set superclass as specified in the book on page 139. Hence, my approach was to add them in manually. If I’m wrong, please feel free to correct me.

  1. Right click package name (app->src->main->java->packagename)
  2. Select new->java class
  3. Enter CrimeFragment
  4. import android.support.v4.app.Fragment;

Chapter 7 - Adding FragmentManager class in Android Studio

  1. On page 143 of the book, when you enter FragmentManager in CrimeActivity, Android Studio will present 2 options in the autocomplete option.
  2. For the purpose of following the book instructions for pre-honeycomb builds, select the one with (android.support.v4.app). Not the one with android.app. (see screenshot)
  3. Alternatively, you can just import android.support.v4.app.FragmentManager;

Chapter 7 - Adding and deleting strings

  1. In Android Studio, “menu_settings” in the book refers to “action_settings”.
  2. Go to menu file, app->src->main->res->menu
    (Update: if menu folder is not existent, right click res directory, choose New->Android resource directory, and change the “Resource type:” drop down menu to be “menu” and press OK. Then right click the new res/menu directory, and choose New>Menu resource file, and fill in criminal_intent.xml in the New Menu Resource dialog.)
  3. Delete the entire item node of criminal_intent.xml in the menu folder (see below)

<item android:id="@+id/action_settings" android:title="@string/action_settings" android:orderInCategory="100" app:showAsAction="never" />

Chapter 8 - Using the Graphical Layout Tool in Android Studio
Note: The layout for the graphical layout tool in Android Studio is exactly the same as Eclipse, with the exception of minor differences in naming.

  1. Folder is called directory in Android Studio. Hence, to create the folder layout-land, right click res (app->src->main->res), and select new->directory
  2. Enter layout-land in the dialog.

Other notes: Outline is called Component Tree in Android Studio. The ‘Graphical Layout’ Tab is called ‘Design’ Tab in Android Studio. With the exception in naming, their positions are all exactly the same as in Eclipse.

Chapter 8 - Editing attributes in properties in Android Studio
The properties display seems a little different from Eclipse. The screenshot shows my corresponding values to the book’s instructions. You can switch to the text tab and verify the XML values.

Note: No Android Studio Specific configuration required for Chapter 9 to 10


#5

Chapter 11 - Creating Android XML resource file in Android Studio

  1. Right click values folder (app->src->main->res->values), select new-> values resources file
  2. Enter ids
    Note: In android studio, there is no need to include the xmlns attribute in the resource element as seen in the book.

Note: No Android Studio configuration required for Chapter 12

Chapter 13 - Configuring project in Android Studio for Chapter 13

  1. After creating a new project, include the following code in your build.gradle. Note: This is only required for following books instructions if you intend to use minimum APIs below 11.

compile 'com.android.support:support-v4:20.+' compile 'com.android.support:appcompat-v7:20.+'

The build gradle should look exactly this:

[code]apply plugin: ‘com.android.application’

android {
compileSdkVersion 20
buildToolsVersion “20.0.0”

defaultConfig {
    applicationId "android.bignerdranch.com.hellomoon"
    minSdkVersion 8
    targetSdkVersion 20
    versionCode 1
    versionName "1.0"
}
buildTypes {
    release {
        runProguard false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}

}

dependencies {
compile fileTree(dir: ‘libs’, include: [’*.jar’])
compile 'com.android.support:support-v4:20.+'
compile ‘com.android.support:appcompat-v7:20.+’
}
[/code]

  1. Go to HelloMoonActivity.java, change extends ActionBarActivity to extends FragmentActivity (for book compatibility) or Activity. This step is very important if you intend to use the same theme as prescribed in the book. Otherwise, you will get the following error when you try to run your project.
  1. Now there are 2 ways to configure the Holo Dark theme for this exercise.

Option 1 (recommended for min api 11 and above. But seems to work for below 11):

  1. Go to styles.xml.
  2. Change the parent value attribute to android:Theme.Holo. The styles.xml should look like the following. Note: If you are using minimum api below 11, you will get a validation error from Android Studio. Nevertheless, I tried it on minimum api 8 and it seems to work fine. Theme.Holo is the name for the Holo dark theme.
    Note: AppBaseTheme in Eclipse as showing on page 231 of book is called AppTheme in Android Studio.

[code]

<!-- Base application theme. -->
<style name="AppTheme" parent="android:Theme.Holo">
    <!-- Customize your theme here. -->
</style>

[/code]

Option 2

  1. Go to AndroidManifest.xml, remove the android:theme attribute. Note: As per book instructions on page 231, the android theme attribute is not required and is only used if an existing theme is not declared
  2. Go to activity_hello_moon.xml in the layout folder and click this icon .
  3. Select Holo Dark at the side, and Holo on the right view. See screenshot.
  4. Click Ok

Personally, I went with option 2, because I do not like Android Studio screaming at me for validation errors for option 1. But as mentioned, if you are using minimum API level 11 and above, feel free to use option 1.

Note: Chapter 14-15 (no Android specific configuration required)


#6

Note: No Android Specific configuration required for Chapter 15.

Chapter 16 - Creating the options menu
If you are using Android studio, you will get an warning to use "should use app:showAsAction with the appcompat library with xmlns:app=“schemas.android.com/apk/res-auto”. The warning will not affect the app in any way, and you should be able to produce the same results as the book. In any case, this is my xml configuration for me CrimeListFragment as shown on page 255.

[code]<?xml version="1.0" encoding="utf-8"?>

[/code]

I am still getting the warning though, but the app still works exactly as prescribed in the book. So I’m not sure if it is an Android Studio bug. In any case, if there is a better approach to handling this, please feel free to comment!

Update: To suppress the warning, simply add tools:ignore=“AppCompatResource” to the item element. Otherwise, click the alert notification icon next to the warning, and select the suppress option.


#7

Note: Nothing specific to Android Studio for Chapter 20 - 23

Chapter 24: Listing 24.7 for Android Studio
Just specify the layout width and layout height to wrap content to prevent to rendering warning from Android Studio.

[code]<?xml version="1.0" encoding="utf-8"?>

<Button style="@style/RemoteButton"/>
<Button style="@style/RemoteButton"/>
<Button style="@style/RemoteButton"/>

[/code]

Chapter 24: Listing 24.8 for Android Studio
You will get a Layout parameter layout_weight ignored unless both layout_width and layout_height are also specified on tag if you follow the book listing exactly. All you need to do is to add xmlns:tools=“http://schemas.android.com/tools” tools:ignore=“all” to the xml root (credits to chibakun: http://forums.bignerdranch.com/viewtopic.php?f=421&t=9165).

[code]

<TextView
    android:id="@+id/fragment_remote_control_selectedTextView"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="2"
    android:gravity="center"
    android:text="0"
    android:textSize="50dp"
    />

<TextView
    android:id="@+id/fragment_remote_control_workingTextView"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="1"
    android:layout_margin="15dp"
    android:background="#555555"
    android:gravity="center"
    android:text="0"
    android:textColor="#cccccc"
    android:textSize="20dp"
    />

<include
    android:layout_weight="1"
    layout="@layout/button_row" />

<include
    android:layout_weight="1"
    layout="@layout/button_row" />

<include
    android:layout_weight="1"
    layout="@layout/button_row" />
[/code]

#8

Thanks a bunch, robert, for putting together this guide. I haven’t messed with Android in a while and moving to Android Studio is my next move for coming back into Android programming. Thanks!


#9

Thanks for the compliments debutante!

This is the final guide for Chapter 36. There were no specific configuration in between the chapters that I have not already covered in the earlier guides.

Chapter 36: Install and use the Google Play services SDK with Android Studio

Note: You don’t need to import any jar or add any project library nor add any new module under android studio. What you have to do is to add the correct dependencies into the build.gradle file. (source: Estornino stackoverflow.com/questions/1662 … y-services)

Note: Before following the steps below, first navigate to settings -> Apps -> Google Play Services on your Android Device. Ensure Google Play Services is updated to the latest version. Note down the version number. Eg: version 5.0.89

  1. Ensure Android support repository, Google play services and Google repository is installed under the extras segment of SDK Manager.
  2. Open build.gradle from ProjectName -> app
  3. Add compile 'com.google.android.gms:play-services:version_number_you_note_down under dependencies. If Android Studio bugs you about a latest version, ignore it. Your version number must match the latest version of your Google Play services on the selected device, not the latest version that Android Studio recommends you! Otherwise, Android Studio will throw ConnectionResult.SERVICE_VERSION_UPDATE_REQUIRED result code in the onCreateView of Listing 36.2 and your getMap will return null.

(Update: In the event that you update your Google Play service version on your device to be higher than the one which Android Studio recommends, than just default to the version number that Android Studio recommends. Eg: My Google Play Services on my device was 6.1.09 and Android Studio could not find this version. So I fall back to 5.2.08 which was the latest that Android Studio recommended.)

See my build.gradle configuration below.

[code]apply plugin: ‘com.android.application’

android {
compileSdkVersion 20
buildToolsVersion “20.0.0”

defaultConfig {
    applicationId "android.bignerdranch.com.runtracker"
    minSdkVersion 9
    targetSdkVersion 20
    versionCode 1
    versionName "1.0"
}
buildTypes {
    release {
        runProguard false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}

}

dependencies {
compile fileTree(dir: ‘libs’, include: [’*.jar’])
compile 'com.android.support:appcompat-v7:20.0.0’
compile ‘com.google.android.gms:play-services:5.0.89’
}
[/code]

Chapter 36: Update RunTracker’s Manifest

  1. Add within the application node.
  2. Add (Not stated in the book because the listing 36.1 is outdated. The permission is now required or Android Studio will throw an exception.) See code below for how my AndroidManifest looks like (I have removed my API Key value)

[code]<?xml version="1.0" encoding="utf-8"?>

<permission android:name="android.bignerdranch.com.runtracker.permission.MAPS_RECEIVE" 
            android:protectionLevel="signature" />
<uses-permission android:name="android.bignerdranch.com.runtracker.permission.MAPS_RECEIVE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-feature android:required="true" android:name="android.hardware.location.gps" />
<uses-feature android:required="true" android:glEsVersion="0x00020000" />

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <meta-data
        android:name="com.google.android.gms.version"
        android:value="@integer/google_play_services_version" />
    <activity
        android:name=".RunListActivity"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity android:name=".RunActivity"
              android:label="@string/app_name" />
    <activity android:name=".RunMapActivity" android:label="@string/app_name" />
    <receiver android:name=".TrackingLocationReceiver" android:exported="false">
        <intent-filter>
            <action android:name="android.bignerdranch.com.runtracker.ACTION_LOCATION" />
        </intent-filter>
    </receiver>
    <meta-data android:name="com.google.android.maps.v2.API_KEY"
               android:value="your-maps-API-key-here" />
</application>
[/code]

Chapter 36: Obtain a Google Maps API Key - Obtaining SHA-1 fingerprint
Follow instructions here: developers.google.com/maps/docu … ps_api_key. You will come to a point where you are required to enter your SHA-1 finger print along with your package name.

This segment isn’t really specific to Android Studio. However, I found the instructions for finding the SHA-1 key to be so vague amongst all the instructions on the web. I assume that you are using a Windows platform with Android Studio installed.

  1. Open up cmd
  2. Enter cd “Path where jdk/bin is installed”. Example: cd C:\Program Files\Java\jdk1.7.0_65\bin
  3. To find the SHA-1 path, you need to first locate the path of your debug.keystore file. Mine was located at the .android directory. Example: C:\Users\AdminCOOP.android
  4. Enter the following command: keytool -list -v -keystore C:\Users\AdminCOOP.android\debug.keystore
    If the paths are valid, you should see the SHA-1 key displayed in the output under the section Certificate fingerprints.
  5. Enter the SHA-1 key value plus your package name. Eg: BB:0D:AC:74:D3:21:E1:43:67:71:9B:62:91:AF:A1:66:6E:44:5D:75;android.bignerdranch.com.runtracker
  6. You will receive 2 API Keys, 1 for Key for Android apps (with certificates) and the other for Key for browser apps (with referers). You need the API Key under Key for Android apps (with certificates). Enter this API Key in your Android Manifest.

IMPT UPDATE: Before you upload your app to Google Play, for steps 3, and 4, you need to change keytool -list -v -keystore C:\Users\AdminCOOP.android\debug.keystore to the path where your private key (not debug) is located. See this guide for more info on how to publish your APK http://developer.android.com/tools/publishing/app-signing.html
Example replacement for Step 4: keytool -list -v -keystore C:\Users\AdminCOOP.android\keystore_name.jks -alias keystore_alias. When you get the new SHA-1 key, Create a New Android Key for release (https://developers.google.com/maps/documentation/android/start#get_an_android_certificate_and_the_google_maps_api_key). You also need to replace the development API key in Step 6, which was signed with your debug keystore with the new API key generated by your private key.


#10

This isn’t really pertinent to the book chapters, but I discovered something useful in Android Studio. Sometimes, when you are trying to import a library dependency for a 3rd party library, you might have an incorrect coordinate, or either that, the github repo that host the library did not update the coordinate. An example is github.com/lucasr/twoway-view where my Android Studio had difficulty finding org.lucasr.twowayview:core:0.1.1 as specified in the master repo since my compileSdkVersion was 20 instead of ‘android-L’ which the active master branch was using.

Android Studio allows you to search the coordinate on the Maven Central. Simply right click your Project, select Open Module Settings. Click the dependencies tab. Click the ‘+’ icon, select library dependency. You will be presented with a dialog to search Maven Central. Here, I had trouble finding the coordinate the above specified coordinate. Hence, I entered org.lucasr.twowayview and click the search icon to see if I could pull something out. Lo and behold, I found the coordinate for my specified compileSdkVersion.

Click Ok to add the dependency to build.gradle.


#11

Sometimes, you might encounter trouble adding dependencies via build.gradle. In this example, I had trouble getting Android Studio to detect the Jake Wharton’s ViewPagerIndicator Library by just adding the dependencies in build.gradle. After syncing gradle, Android Studio still could not locate the package com.viewpagerindicator.TitlePageIndicator.

This is what I did initially - Failed Approach

Added the following in my top level build.gradle.

allprojects { repositories { maven { url "http://dl.bintray.com/populov/maven" } mavenCentral() } }

Added the dependency in my module build.gradle

dependencies { // ... compile 'com.viewpagerindicator:library:2.4.1' // ... }

This approach did not worked. Hence, this was my alternative approach

  1. Downloaded the zip file from viewpagerindicator.com/
  2. Extracted the zip file
  3. Navigate to jake_wharton\JakeWharton-Android-ViewPagerIndicator-XXXXXX of extracted file
  4. Renamed library folder to ViewPagerIndicatorLibrary
  5. From Android Studio, File->import module
  6. Select the source of the ViewPagerIndicatorLibrary folder you just named. Example: C:\Users\AdminCOOP\Downloads\code_samples_ui_design_android\jake_wharton\JakeWharton-Android-ViewPagerIndicator-XXXXXX\ViewPagerIndicatorLibrary
  7. Select Next, Next (Accept all checkmarks), and Finish.
  8. Once the module has been imported, you might get a build.gradle sync error, depending on your module build.gradle settings.
  9. If error happens, navigate to the ViewPagerIndicator build.gradle. Example: MakanKaki->app->viewPagerIndicatorLibrary
  10. Ensure the compileSDKVersion, buildToolsVersion, minSdkVersion, targetSdkVersion and dependencies correspond to your module build.gradle. Please see below from some reference.

module build.gradle

[code]apply plugin: ‘com.android.application’

android {
compileSdkVersion 20
buildToolsVersion “20.0.0”

defaultConfig {
    applicationId "com.yourpackagename.yourappname"
    minSdkVersion 11
    targetSdkVersion 20
    versionCode 1
    versionName "1.0"
}
buildTypes {
    release {
        runProguard false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}

}

dependencies {
compile fileTree(dir: ‘libs’, include: [’*.jar’])
compile 'com.android.support:appcompat-v7:20.0.0’
compile(‘com.doomonafireball.betterpickers:library:1.5.2’) {
exclude group: ‘com.android.support’, module: ‘support-v4’
}
compile ‘org.lucasr.twowayview:twowayview:0.1.1’
}
[/code]

viewPagerLibrary build.gradle

[code]apply plugin: ‘com.android.library’

android {
compileSdkVersion 20
buildToolsVersion “20.0.0”

defaultConfig {
    applicationId "com.viewpagerindicator"
    minSdkVersion 11
    targetSdkVersion 20
}

buildTypes {
    release {
        runProguard false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
    }
}

}

dependencies {
compile ‘com.android.support:support-v4:20.+’
}
[/code]

  1. Sync Gradle. Tools->Android->Sync Project With Gradle Files

  2. Right Click Project App name (eg: MakanKaki), Open Module Settings, select app module under Modules, and Dependencies Tab

  3. Select the + icon, and module dependency

  4. In the dialog, select the viewPagerIndicatoryLibrary module and Ok

  5. Alternatively, in place of steps 12-14, you can simply add compile project(’:viewPagerIndicatorLibrary’) to your module build.gradle under dependencies.

  6. You’re done and can start using the module using the instructions given here: viewpagerindicator.com/#usage


#12

After 2 months of hard work with BNR Android programming as my loyal guide, I have finally published my first android app, Makan Kaki on Android! (https://play.google.com/store/apps/details?id=com.makankaki.makankaki). Its an app that helps you plan gatherings a lot more effectively, and its a recipient of 10,000 SGD in funding from the National University of Singapore, and an incubatee at Google Developer Startup Launch and Microsoft Bizspark.

I built the app using purely Android Studio, and you can find some familiar components listed in my previous posts on two-way views, view pager components, and better pickers (github.com/derekbrameyer/android-betterpickers). In general, all chapters from BNR were extremely useful in the building of my app, but here were the chapters that were highly relevant. (Note: Excluding chapters on fragments, fragment arguments, activities or earlier chapters because they form the bedrock foundation of any Android app)

Chapter 8: Creating User Interfaces with Layouts and Widgets (RelativeLayouts are critical for dynamic content and reducing the problems caused by Fragmentation)
Chapters 26, and 27 were used extensively for fetching rich images using web services for my listviews. - Chapter 27, loopers were used extensively for my galleries and search images
Chapter 28: I used a slightly different approach for search, since I wanted to populate my search view with auto-complete suggestions from a web service. (check out this tutorial: http://stackoverflow.com/questions/21585326/implementing-searchview-in-action-bar) - if you need the sample code, feel free to PM me or reply to this thread.
Chapters 31, and 33 and 36 were critical to enabling me to display context aware venues to users based on their device location. The maps section was useful, but I had to make a couple of edits. See my earlier post on Google maps for Android studio.

New Domains:
Google Cloud Messaging: Instead of using local notifications, I used Google Cloud Messaging on my server because continuous polling for data from the app is highly intensive on the battery life and not very efficient. https://github.com/GoogleCloudPlatform/gradle-appengine-templates/tree/master/GcmEndpoints, http://stackoverflow.com/questions/11242743/gcm-with-php-google-cloud-messaging and https://cloud.google.com/mobile/messaging/add_module are highly relevant tutorials. Again, if you get stuck, feel free to let me know and I will try to provide some code examples.

Filtering apps from Chooser: I did not want all apps to respond to my ACTION_SEND implicit intent. See this link for how to filter these apps programmatically in code. http://stackoverflow.com/questions/9730243/android-how-to-filter-specific-apps-for-action-send-intent

URL schemes Check out this tutorial for how to get your app to respond to a particular html url. For example, getting the Google Play Store to appear in the Intent Chooser when you click on the Google Play Link. http://fokkezb.nl/2013/09/20/url-schemes-for-ios-and-android-2/

I apologize if I cannot send out my entire source code, as they are proprietary. But if you need any help, again please let me know, and I will provide some sample code if it is appropriate.

Please feel free to check out the above app, and I appreciate any feedback!


#13

Hi, I just got the book and was thinking “damn, it is using eclipse, but I’m using android studio”, then a saint of a human being in the form of robertqin86 comes a long and dissects each chapter with multiple resources and explanations. Thank you very much for doing this. My faith in humanity has been restored :slight_smile:


#14

Thanks MrMeemus for the generous compliments! I did this guide for myself too and I’m glad you found it useful as well.

Abit out of touched with this guide for awhile, as I decided to refocused my attention to iOS development. However, there are couple of small changes required needed to be done to build.gradle if you decided to update to Android Studio 1.0 (latest at of this time of writing). You will noticed that if you decided to follow through all aspects of the upgrade, including updating all the files recommended, you will at some point encounter this error when syncing your build.gradle (Gradle DSL method not found: ‘runProguard()’).

The solution is simple to replace runProguard in all your build.gradle files, including 3rd party modules, with minifyEnabled. For example, runProguard false should be replaced with minifyEnabled false // new version - credits to ruan65 http://stackoverflow.com/questions/27016385/error26-0-gradle-dsl-method-not-found-runproguard.

Replace this segment in all your build.gradle files, including dependencies from this:

buildTypes {
        release {
            runProguard false // this line has to be changed
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

To this.

buildTypes { release { minifyEnabled false // new version - replacement completed proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } }

After the replacement, is completed, just follow through with Android Studio recommended solutions if you encountered any errors in your existing projects during the update and syncing process.

You might also encounter this error: Error:Library projects cannot set applicationId. applicationId is set to ‘com.viewpagerindicator’ in default config.. in the some of your 3rd party modules build.gradle files. The solution is to simply comment out the applicationId in those build.gradle files. In the above case, I simply commented out applicationId of my view pager indicator library module build.gradle file.

[code]apply plugin: ‘com.android.library’

android {
compileSdkVersion 20
buildToolsVersion “20.0.0”

defaultConfig {
    // applicationId "com.viewpagerindicator"
    minSdkVersion 11
    targetSdkVersion 20
}

buildTypes {
    release {
        minifyEnabled false // new version
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
    }
}

}

dependencies {
compile ‘com.android.support:support-v4:20.+’
}[/code]

After implementing to above features, I got my project to run well with the latest version of Android Studio.


#15

I would also like to thank robertqin86 for such detailed posts on using Android Studio with the BNR Android programming book. Just wanted to post some additional info with respects to using v1.0 of Android Studio. Many of you may run into other needed changes with the ide or gradle and the following page gives a good list of needed changes when upgrading to Android Studio 1.0.

tools.android.com/tech-docs/new- … g-to-1-0-0


#16

I signed up specifically for the reason of thanking you robertqin86 for such a detailed and thought out guide to using this book with Android Studio, I have finally purchased this book after a long time thinking about it but my main concern was what problems would I run into if I used Android studio, but with your guide I have no troubles at all!

Thanks again dude.


#17

Thanks for this guide. Very helpful!


#18

Thanks for the compliments everyone!

This guide might be a little dated, given the release of Android Studio 1.1.0, and hence, I will be updating this guide instructions with the latest screenshots from the IDE and new features if I find any. Given that the 2nd edition of BNR Android Programming will only be out till August 2015, this guide might be useful for the time being to familiarize with Android Studio using the BNR Android programming book. I’m currently reading the latest version (v6.5) of the The Busy Coder’s Guide to Android Development and the updates are mainly based from that book.

Classic vs Project view
If you’ve have just import or created a new Android project, the first thing you want to do is to switch from Android project view to classic project view, in order to follow the guide.

Click the “Android” drop down button and select Project, as show in the below screenshot.

Drawables vs Mipmaps
When you create a project through the Android Studio new project wizard, you may not find the usual drawable directories (for example: drawable-hdpi or drawable-mdpi and etc…) Instead, you will find for example midmap-hdpi, midmap-mdpi and etc… Midmaps are the same as drawables, but instead of referring as for eg: “@drawable/ic_launcher”, you use “@midmap/ic_launcher”.

Busy Coder’s Android guide recommends that you still place most drawables in the respective res/drawable-* directories (drawable-hdpi or drawable-mdpi and etc…) even if you have to manually create them yourself. From Google Blog Post http://android-developers.blogspot.sg/2014/10/getting-your-apps-ready-for-nexus-6-and.html, midmap folders are for placing app icons only.

From Google Blog Post:

Changing Project Name
Simply change the app_name value in res/values/strings.xml. Eg:

[code]<?xml version="1.0" encoding="utf-8"?>

<!--<string name="app_name">MakanKaki</string>-->
<string name="app_name">Makan Kaki</string>-
<string name="hello_world">Hello world!</string>

[/code]


#19

Options Menu not working with Target SDK 21

Option 1: within the Android Studio Layout “Design” window click on App Themes and select a theme, such as Holo Light
Option 2: in the AndroidManifest.xml modify the line for App theme to something like “android:theme=”@android:style/Theme.Holo" >"

viewtopic.php?f=431&t=9620


#20

[size=150]Chapter 1: Finding R.java in Android Studio 1.1.0[/size]

In the Project level hierarchy…

YOUR_APP_NAME_HERE > app > build > generated > source > r > debug > YOUR_APP_REVERSE_DOMAIN > R