-
Book Overview & Buying
-
Table Of Contents
-
Feedback & Rating

Android Studio Cookbook
By :

After downloading Android Studio, install it and go through the setup wizards. The wizard checks for some requirements, whether the Java Development Kit (JDK) is available, and other important elements that the installation wizards guide you through.
Once the installation is complete, it is time to develop your first Android app using Android Studio, just to check whether everything has been installed correctly and works the way it should. It probably will be no surprise that this is where the Hello Android Studio recipe comes in.
To go through this recipe, you will need a running Android Studio IDE, an Android Software Development Kit (SDK), and an Android device. No other prerequisites are required.
Let's create our first Android app using Android Studio to check whether everything works fine with the help of the following steps:
HelloAndroidStudio
; and for the Company domain field, enter packtpub.com
(or use the domain name of your own company if you prefer to do so).packtpub.com
and helloandroidstudio
are suggested and updated while you type. If you wish, you can edit the Project location before you click on the Next button.build.gradle
file (note that this file also exists on the root level).build.gradle
file to open it and have a look at the values for compileSdkVersion
, minSdkVersion
, and targetSdkVersion
. By default, the compileSdkVersion
value is always related to the latest (available) SDK. The value for minSdkVersion
is the one that you have chosen in the Target Android devices dialog box.If you want, use a different SDK to compile against; you must change the value for compileSdkVersion
. The version you choose might need to be installed first. If you are happy with the current configuration, go to step 14 right away.
build.gradle
file, you can now run your app.If you do not have a real device, I strongly recommend you get one as soon as possible. To get started, you can use an emulator for now. You can use the emulator that comes with the Android SDK or you can read the recipe about Genymotion first to find out how to use emulated devices.
On older Android versions (below 4.2), this step may be skipped, or if the developer options are already available as a menu item in the settings app, this step may be skipped.
The app is now being deployed on your device. If everything goes well, your new app is now shown on your device that says Hello world! Hurrah! I admit this is not really a very exciting app, but at least we know now that Android Studio and your device have been configured correctly.
Android Studio will take care of the basic parts of your app setup. All you need to do is choose the target and minimal SDK for your app. Using the API level 14 (Android 4.0) is currently the best option, as this will allow your app to run on most Android devices.
The app will be compiled against the chosen (compile) SDK by Android Studio.
The app will be copied to your device. Having the USB debugging option enabled will help you troubleshoot any issues, as we will find out later.
Change the font size
Change margin width
Change background colour