Mobile Development Dr Msury Mahunnah email msury mahunnahifm
Mobile Development Dr. Msury Mahunnah e-mail: msury. mahunnah@ifm. ac. tz course website: https: //mahunnah. wordpress. com/
Lecture 3 Development Fundamentals
Outline • • Structure of an Android application Android build system Android app manifest App resources
Structure of an Android application • A bunch of files in a particular folder structure • Android Studio sets all these files for you automatically when you create a new app
• Java & XML files • Activity and layout files • Android generated Java files • Extra Java files automatically created for you (no need to touch) • Resource files • Default image files for icons, styles, string values • Android libraries • Relevant Android libraries needed (depending on min specified SDK) • Configuration files • What’s in the app and how it should run
Android build system • Toolkit used to build, test, run and package apps • Run as an integrated tool from the Android studio menu or independently from the command line • Handled by Gradle Build System • Used to – Customize, configure & extend the build process – Create multiple APKs with different features from the same project and modules – Reuse code and resources across source sets
Android build process
Gradle Build System • Handles the build process of Android projects • Gradle build scripts are automatically generated when new project is created • Android Studio wraps the Gradle runtime – no additional installation needed • build. gradle file
Building in Android Studio
Building via the command line • Execute the following commands from the directory of the associated project (or use the gradle wrapper – gradlew) • This command creates the output in the build folder • Two. apk files in build/outputs/apk
Android app manifest • Describes the components & settings of an Android application • Android. Manifest. xml • Also specifies additional metadata e. g. icon & version number of the application • Read by the Android system during installation of the app • Components – – Activities Services Content Providers Broadcast Receivers
Android manifest details • Version and package – package => defines base package for the Java objects. Should be unique – android: version. Name & android: version. Code => specify app version • Application and components – <application> => section that allows to define app metadata. Also, defines explicit application class. Container for declaring Android components. – <activity> => defines activity component. Has name attribute • Intent filter part indicates activity should be registered as possible entry point into the app – @string/app_name => resource file which contains actual name of the app • Minimum and Target SDK • Permissions • Required device configuration
Android manifest details • Minimum and Target SDK • Permissions • Declare permission with the <permission> and <uses-permission> tag • Required device configuration • <uses-configuration> section allows to specify required input methods for device • E. g. <uses-configuration android: req. Hard. Keyboard=“true” /> OR <uses-feature android: name=“android. hardware. camera” />
App resources • Android allows to create static resources like images & XML config files • Allows to keep resources separate from the source code • Resource files must be placed in /res folder in a predefined sub-directory • Sub-directory depends on the type of resource
Resource sub-folders
Example
- Slides: 20