Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Expert Android Programming

You're reading from   Expert Android Programming Master skills to build enterprise grade Android applications

Arrow left icon
Product type Paperback
Published in Sep 2017
Publisher Packt
ISBN-13 9781786468956
Length 404 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Author (1):
Arrow left icon
Prajyot Mainkar Prajyot Mainkar
Author Profile Icon Prajyot Mainkar
Prajyot Mainkar
Arrow right icon
View More author details
Toc

Table of Contents (17) Chapters Close

Preface 1. Understanding the Gradle System FREE CHAPTER 2. Exploring Android Studio Developer Tools 3. Leap into the Android Support Library 4. Google Play Services 5. Material Design 6. SOLID Android Development and Its Design Principles 7. Understanding MVC, MVP, MVVM and Clean Arch Patterns 8. Decision Making 9. Performance Matters 10. Building Restaurant finder 11. Backend Service 12. App Quality Service 13. Grow Up 14. Testing 15. Preparing for Google Play 16. Understanding App Store Analytics for Optimization

Adding a new Gradle library

Making Android Development more awesome, Gradle allows us to incorporate libraries in to Android Studio in different ways. Using these, developers can easily include their libraries using Gradle dependencies. In this section we will discuss the following techniques:

  • Adding a Gradle identifier
  • Adding as a module

Adding a Gradle identifier

To add a new Gradle library, find the Gradle identifier for the third party library, and add it to the dependencies list.

When you make changes to the build configuration files in your project, Android Studio requires that you sync your project files so that it can import your build configuration changes and run some checks to make sure your configuration won't create build errors.

To sync your project files, click Sync Now (as seen in the following figure) in the notification bar (this appears when you make a change), or click Sync Project from the menu bar. If Android Studio notices any errors with your configuration--for example, if your code uses API features that are only available in an API level higher than your compileSdkVersion-- the Messages window appears to describe the issue:

Next, we will discuss how libraries can be added using a module.

Adding as a module

You can also add a library in Android Studio by adding it as a module. To add the module:

  1. First, place the library code in any folder of your choice
  2. Then, you need to Import the library as a module in your app. The figure below shows the steps to add the library as a Module:

This will open a new window where you need to select the library that you have saved to the directory. When you have selected the directory, click on Done. This will import the external library into your project.
As an example, I have added the module crop image to my project, which appears in my project folder.

Next, we need to add the module to the app's dependency list. To do this, right click on the module that has been added and click on the Open Module Settings option:

It will open a new window with your app module and library module in the list. Choose you app module, and then select the dependency list.

Next, click on the plus icon which will open another dialog with the module name. Select it and click OK:

This will build the Gradle and add the module to the build.gradle, and it will be seen as a compiled project here:

Note that Core, UI and Util sub projects can also have their own build.gradle file, depending on their specific needs. Alternatively, you can also define the dependencies of a project in the root build.gradle file, as discussed in the preceding section. In this case, we won't be focusing on these points.

You have been reading a chapter from
Expert Android Programming
Published in: Sep 2017
Publisher: Packt
ISBN-13: 9781786468956
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 $19.99/month. Cancel anytime