Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Android Things Projects

You're reading from  Android Things Projects

Product type Book
Published in Jun 2017
Publisher Packt
ISBN-13 9781787289246
Pages 232 pages
Edition 1st Edition
Languages
Author (1):
Francesco Azzola Francesco Azzola
Profile icon Francesco Azzola

Table of Contents (15) Chapters

Title Page
Credits
About the Author
About the Reviewers
www.PacktPub.com
Customer Feedback
Preface
Getting Started with Android Things Creating an Alarm System Using Android Things How to Make an Environmental Monitoring System Integrate Android Things with IoT Cloud Platforms Create a Smart System to Control Ambient Light Remote Weather Station Build a Spying Eye Android with Android Things

Creating the first Android Things project


Considering that Android Things derives from Android, the development process and the app structure are the as same we use in a common Android app. For this reason, the development tool to use for Android Things is Android Studio. If you have already used Android Studio in the past, reading this section will help you to discover the main differences between an Android Things app and an Android app. Otherwise, if you are new to Android development, this section will guide you step by step to create your first Android Things app.

Android Studio is the official development environment to develop Android Things apps, therefore, before starting, it is necessary you have installed it. If not, go to https://developer.android.com/studio/index.html, to download and install it. The development environment must adhere to these prerequisites:

  • SDK tools version 24 or higher
  • Update the SDK with Android 7 (API level 24)
  • Android Studio 2.2 or higher

If your environment does not meet the previous conditions, you have to update your Android Studio using the Update manager.

Now there are two alternatives to starting a new project:

  • Clone a template project from GitHub and import it into Android Studio
  • Create a new Android project in Android Studio

To better understand the main differences between Android and Android Things you should follow option number 2, at least the first time.

Cloning the template project

This is the fastest path because with a few steps you are ready to develop an Android Things app:

  1. Go to https://github.com/androidthings/new-project-template and clone the repository. Open a terminal and write the following:
git clone https://github.com/androidthings/new-project-template.git
  1. Now you have to import the cloned project into Android Studio.

Create the project manually

This step is longer in respect to the previous option, but it is useful to know the main differences between these two worlds:

  1. Create a new Android project. Do not forget to set the Minimum SDK to level API 24:
  1. By now, you should create a project with empty activity. Confirm and create the new project.

There are some steps you have to follow before your Android app project turns into an Android Things app project:

  1. Open the Gradle scripts folder and modify build.gradle (app-level) and replace the dependency directive with the following lines:
dependencies {
  provided 'com.google.android.things:androidthings:
    0.2-devpreview'
}
  1. Open the res folder and remove all the files under it except strings.xml.
  2. Open Manifest.xml and remove the android:theme attribute in the application tag.
  3. In Manifest.xml add the following line inside the application tag:
<uses-library android:name="com.google.android.things"/>
  1. In the layout folder, open all the layout files created automatically and remove the references to values.
  2. In the activity created by default (MainActivity.java) remove this line:
import android.support.v7.app.AppCompatActivity;
  1. Replace AppCompatActivity with Activity.
  2. Under the folder java remove all the folders except the one with your package name.

That's all. You have now transformed an Android app project into an Android Things app project. Compiling the code you will have no errors. In future, you can simply clone the repository holding the project template and start coding.

You have been reading a chapter from
Android Things Projects
Published in: Jun 2017 Publisher: Packt ISBN-13: 9781787289246
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime}