IES Jaume II el Just
Tavernes de la Valldigna
Mobile
development
Vicent Selfa
Curs 2020/2021
Android
Studio
Android Studio
● Interesting links
● Android Studio installation
● Linux
● Windows
● A first project
● Android Studio features
● Gradle
● Lint
● Proguard
● Firebase
● GIT
● GITHUB
● Annexes:
● Running the project in a USB connected device
● Installing Java 8
● Changing editor font size, colors ….
● Solving problems
• Version control of notes
Android Studio
● Interesting links
• The best starting point to use Android Studio
• A lot videos related with Android Studio
Video: www.youtube.com/watch?v=Z98hXV9GmzY
Learn how to get started with Android and Android Studio in this short tutorial.
It demonstrates how to install Android Studio (Google’s official Android IDE)
and create your first Android app.
Android Studio installation:
Linux
Different ways:
● From the Software Manager application
● From the official web page
○ An stable version
● A Canary version:
○ If you want early access to the next version of Android Studio.
○ More info here and here.
Android Studio installation
• From the Software Manager application
Android Studio installation
• Installation for Linux: Download.
• https://developer.android.com/studio
Android Studio installation
• Installation for Linux: How to?
• https://developer.android.com/studio
Android Studio installation
• Installation for Linux: How to?
1. Unpack the tar.gz file you downloaded to an appropriate location for your
applications, such as within /usr/local/ for your user profile, or /opt/ for shared users.
If you're using a 64-bit version of Linux, make sure you first install the required libraries
for 64-bit machines.
2.To launch Android Studio, open a terminal, navigate to the android-studio/bin/
directory, and execute studio.sh.
3.Select whether you want to import previous Android Studio settings or not, then click
OK.
4.The Android Studio Setup Wizard guides you through the rest of the setup, which
includes downloading Android SDK components that are required for development.
Android Studio installation
• Installation for Linux: How to?
$ sudo tar zxvf android-studio-ide-191.5791312-linux.tar.gz.tar.gz -C /opt
$ sudo apt-get update
$ sudo apt-get install libc6:i386 libncurses5:i386 libstdc++6:i386 lib32z1 libbz2-1.0:i386
$ cd /opt/android-studio/bin/
$ sh studio.sh
Android Studio installation: Linux
• Completing installation
$ /opt/android-studio/bin/./studio.sh
Android Studio installation: Linux
• Completing installation
Android Studio installation: Linux
• Completing installation
Android Studio installation: Linux
• 1.- Adding a shortcut to run the program
• 2.- Creating a little script
#!/bin/bash
bash /home/alumne/android-studio/bin/studio.sh
Android Studio installation: Linux
• Installation for Linux.- Another way: Canary version
sudo add-apt-repository ppa:maarten-fonville/android-studio
sudo apt-get update
sudo apt-get install android-studio
sudo apt-get install android-studio-preview
More info
• Android Studio
Android Studio installation: Linux
• Completing installation
Next slide: The
first project
Android Studio
installation:
Windows
Android Studio installation: Windows
• Installation for Windows: Download stable package version
• All Android Studio Packages: https://developer.android.com/sdk/installing/studio.html
Android Studio installation: Windows
• Installation for Windows:
○ Or take a look to the latest versions
Android Studio installation: Windows
• Installation for Windows: Install
• All Android Studio Packages: https://developer.android.com/sdk/installing/studio.html
android-studio-ide-[num. Version]-windows.exe
Android Studio installation: Windows
• Installation for Windows: Install
The first project
The first project
The first project
The first project
The first project
• The view:
The first project
• Configure your project
What about Kotlin?
The first project
• What’s new in your version?
The first project
• Project structure
Android studio framework File system
The first project
• The AndroidManifest file
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.myapplication">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category
android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
The first project
• The Main Activity
package selfa.v.myapplication;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout. activity_main);
}
}
The first project
● The layout editor
Toolbar
Attributes
Design
editor
Palette
Component
Tree
Android Studio layout editor
The first project
• The activity_main layout: Using the layout editor
The first project
• The activity_main layout: Text
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>
The first project
• Running the project
• Other options to run the project
The first project
Pay attention to this in Linux
And check for a solution here
The first project
The first project
• Running the project in an emulator
The first project
• Changing the text and running again using
The first project
• Running the project in an emulator: Using strings
The first project
• Install platforms and tools: SDK manager
The first project
• Install platforms and tools: SDK manager
The first project
• Building an APK
Android Studio features
Android Studio is a new Android development environment based on IntelliJ
IDEA. It provides new features and improvements over Eclipse ADT and it is the
official Android IDE. On top of the capabilities you expect from IntelliJ, Android
Studio offers:
● Flexible Gradle-based build system.
● Build variants and multiple APK generation.
● Expanded template support for Google Services and various device types.
● Rich layout editor with support for theme editing.
● Lint tools to analyze your code, improving performance, usability, version
compatibility and solving other problems.
● ProGuard and app-signing capabilities.
● Built-in support for Firebase services, making it easy to include and manage
Firebase projects from your Android Studio framework
● Built-in support for GIT Control Version System.
● IntelliJ IDEA: Providing intelligent coding and framework-specific assistance
for Java
Android Studio features
• Flexible Gradle-based build system.-
Gradle is build automation evolved. Gradle can automate the
building, testing, publishing, deployment and more of software
packages or other types of projects such as generated static
websites, generated documentation or indeed anything else.
http://www.gradle.org/
More information:
•Configuring gradle
•Gradle tutorials
Interesting video about Gradle:
•Deep Dive Into the Gradle Based Android Build System
Android Studio features
• Flexible Gradle-based build system.-
Compilation process
for a module app
Android Studio features
Flexible Gradle-based build system. Scripts.-
For the project
For each module
Android Studio features
Flexible Gradle-based build system.
Build.gradle for each module
apply plugin: 'com.android.application'
android {
compileSdkVersion 23 buildToolsVersion "23.0.2"
defaultConfig {
applicationId "com.example.profe"
minSdkVersion 19 targetSdkVersion 23 versionCode 1 versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12‘ compile 'com.android.support:appcompat-v7:23.1.1'
}
Android Studio features
• Lint tools to catch performance, usability, version
compatibility, and other problems.
The Android lint tool is a static code analysis tool that checks
your Android project source files for potential bugs and
optimization improvements for correctness, security,
performance, usability, accessibility, and internationalization.
http://developer.android.com/tools/help/lint.html
Android Studio features
• ProGuard and app-signing capabilities
The ProGuard tool shrinks, optimizes, and obfuscates your
code by removing unused code and renaming classes, fields,
and methods with semantically obscure names. The result is a
smaller sized .apk file that is more difficult to reverse engineer.
• http://developer.android.com/tools/help/proguard.html
An example: Reducing code for compilation
Android Studio features
• IntelliJ IDEA
○ Designed to maximize developer productivity.
○ Together, intelligent coding assistance and ergonomic
design make development not only productive but also
enjoyable.
○ Instant and clever code completion, on-the-fly code analysis
Android Studio features
What is Firebase?
Firebase is a platform for mobile developers to develop awesome-quality apps,
quickly grow a user base, and monetize apps. It includes a hell lot of features, that
developers can use to fulfill their goals. Let’s discuss some of these features.
Firebase helps developers in development, growth and monetization of your mobile
applications.
It provides the following features for the Development phase
• Integration with Cloud Messaging.
• Robust Authentication for added security.
• Realtime Database for Realtime storage of app data.
• Storage support for files.
• Support for on the fly Remote Configuration.
• Test Lab to deliver high quality apps.
• Crash Reporting to keep your apps stable and free from bugs.
More info
• Starting with Firebase
• The YouTube Firebase channel
Android Studio features
Different tools in Firebase
Android Studio features
Accessing Firebase from Android Studio
Android Studio features
● What is GIT?
Git is a version control system for tracking changes in
computer files and coordinating work on those files among
multiple people. It is primarily used for source code
management in software development, but it can be used to
keep track of changes in any set of files. As a distributed
revision control system it is aimed at speed, data integrity,
and support for distributed, non-linear workflows.
Git was created by Linus Torvalds in 2005 for development of
the Linux kernel, with other kernel developers contributing to
its initial development.
• https://git-scm.com/
Android Studio features
Enabling Version Control System Integration with Android Studio
Android Studio features
Adding files to the git index
Committing files to the git object store
A Git project
GitHub and Android Studio
• How to integrate an Android Studio project into GitHub
• How to clone a GitHub project into Android Studio
GitHub and Android Studio
• Creating a github account
vselfa
[email protected]
GitHub and Android Studio
• Creating a GitHub account
GitHub and Android Studio
• Creating a remote repository
GitHub and Android Studio
GitHub settings: User and password for repositories
GitHub and Android Studio
Sharing project on GitHub.-
a.- Connect to GitHub and create a new repository
In case you didin’t add them
GitHub and Android Studio
Sharing project on GitHub.-
a.- Connect to GitHub and create a new repository
Created automatically in GitHub
GitHub and Android Studio
Sharing project on GitHub.-
b.- Connect to an existing GitHub repository
GitHub and Android Studio
Sharing Project on GitHub.- Connect to GitHub
GitHub and Android Studio
Sharing Project on GitHub.- Push commits to GitHub remote
GitHub and Android Studio
Sharing Project on GitHub.- Push commits to GitHub remote
GitHub and Android Studio
Import a repository from GitHub with Android Studio
GitHub and Android Studio
Import a repository from GitHub with Android Studio
GitHub and Android Studio
• Import a repository from GitHub with Android Studio
Annexes
The first project
• Running the project in a USB connected device:
General aspects:
• Verify that your device is in USB Debugging Mode:
• Settings -> System -> Development options
• If the Development options doesn’t appear click 7 times on:
• Device information -> Compilation number
Run apps on a hardware device
If you have a OnePlus 6 click here
The first project
• Running the project in a USB connected device:
Look for something like this in your mobile phone:
And give permission to run the apk in your mobile.
The first project
• Running the project in a USB connected device:
Select the device that you want
Your AndroidStudio framework Your mobile device
Annexes
• Installing Java 8
http://www.oracle.com/technetwork/java/javase/downloads/index.html
$ tar –xvf [package]
$ sudo mv [package] /opt
Annexes
• Changing editor font size, colors ….
Annexes
• Showing editor line numbers
Annexes
Solving problems with gradle
Error:(16, 0) Gradle DSL method not found: 'runProguard()'
buildTypes {
release {
// runProguard false
minifyEnabled false // new version
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
Annexes
Solving problems with devices
Error: The selected device is incompatible
defaultConfig {
applicationId "com.enriquegilboix.examen2tnumeros"
minSdkVersion 19
}
Annexes
• Solving problems:
http://tools.android.com/knownissues
The current inotify watch limit is too low
Add the next line to the /etc/sysctl.conf file
/etc/sysctl.conf
fs.inotify.max_user_watches = 5242881
And then run the sentence:
$ sudo sysctl -p
Annexes
•Solving problems: Disable spell checking
Annexes
Version control of notes
• 1.0.- First version