Sei sulla pagina 1di 18

The Java-Dalvik story:

How are our apps run?


Presented by:
Spandana
Spandana K.S
Swathi B.R

Welcome to Java!
The official language for Android development is Java. Large parts of Android
are written in Java and its APIs are designed to be called primarily from Java.
How does it work?

The Java code written by the user is compiled into an


intermediate format called "Java Bytecode" by the
java compiler.
This byte code(java.class) can run on any platform
provided you have a JVM installed on it.So this java
code need not be converted into native processor
code.The original VM on android is called Dalvik.These
VM's will interpret bytecode(set of instructions) and
then execute them.
The VMs use a variety of technologies including
just-in-time
What this compilation
all means is that
can develop
Android apps on Windows, Linux
(JIT)youand
ahead-of-time
or
OS X and(AOT)
the Java
compiler
converts
the source code into bytecode. This in
compilation
to speed
up the
processes.
turn is executed on the VM built-in to Android. This is different to the model used
by iOS which uses a native compiler to turn Objective-C into ARM machine code.

This is how simple java code looks like. But the code for apps is much more complex.

To create android apps Android Software Development Kit (SDK). The Android SDK
provides all the API libraries and tools you need build an Android app.You need to understand how
the Android UI is constructed (using XML), and how to access the different Android subsystems.

Android structure HTML


Parsing

How
is it
done?

The actual process


Java compilation

Conversion to Dalvik
bytecodes:
The .class files contain Java byte-codes. But
Android devices use byte-code format called
Dalvik. Dalvik byte-codes, like Oracle JVM
byte-codes, are machine-code instructions .
The compilation process needs to convert the
.class files, and any .jar libraries into a
singleclasses.dex file containing Dalvik bytecodes done using dx command.The dx
command stitches all of the .class and .jar
files together into a single classes.dex file
written in Dalvik byte-code format.

Put classes.dex and


resources into a package file
The classes.dex file and the
resources from your
application, such as images
and layouts, are then
compressed into a zip-like
file called an Android
Package or .apk file. This is
done with the Android Asset
Packaging Tool or aapt:
This APK file can now be
distributed.

This is how theyre

deployed
The adb server starts if its
not already running
The app will be deployed to
an Android device using the
Android Debug Bridge. This
involves running an adb
server process on your
development client and a
similar adb inside the
Android device. If the adb
process is not running on
your machine, the adb
command will start it.

The .apk file is transferred to


the device
The adb command is used
to transfer the .apk file into
the file system on the
Android device. The location
is defined by the packagename of the app. So, for
example, if the package
iscom .hfad.bitsandpizzas,
then the .apk file will be
placed
in/data/app/com .hfad.bitsan
dpizzas.

A user asks for an app to be launched


A process called Zygote is used to
launch the app. Zygote is an incomplete
version of an Android processits
memory space contains all the core
libraries that are needed by any app,
but it doesnt yet include any of the
code thats specific to a particular app.
Zygote creates a copy of itself using the
fork system call. Android is a Linux
system, and the forkcall can duplicate a
process like Zygote very quickly. This is
the reason Zygote process is used: its a
lot faster to duplicate an half-started
process like Zygote, than it is to load a
new process from the main system files.
Zygote means your app launches faster.

Android converts the .dex code to


native OAT format
The new app process now needs to
load the code thats specific to your
app. So the classes.dex file is
extracted from the .apk and placed
into a separate directory. But rather
than simply place a copyof the
classes.dex file, Android will convert
the Dalvik byte-codes in classes.dex
into native machine code.
The java code is now converted into
a piece of native compiled code.
Technically, the classes.dex will be
converted into an ELF shared
object. Android calls this library
format OAT and the tool that
converts the classes.dex file is
called dex2oat.

The app loads the native library


This native library is then mapped directly into the
memory of app process.

And we are done!

SECURITY:
Androids security architecture ensures no application, by default, has permission to
perform any operations that would adversely impact other applications, the operating
system, or the user. This includes reading or writing the user's private data (such as
contacts or e-mails), reading or writing another application's files, performing network
access, keeping the device awake, etc.14
These features are implemented across the operating system (OS) level and framework
level of Android and not within the Dalvik VM. As mentioned previously, each application
is run within its own instance of the VM, which itself is running in its own OS process. Each
process is assigned its own user ID that can only access a limited set of features within the
system and can only access its own data.Therefore, an application cannot interfere with
other applications. If additional security permissions are required, the application can
request them through its Manifest file. These permissions are verified at application
installation time by the framework and are enforced by the OS at runtime.s, Dalvik shares
core, read-only libraries between VM processes. The sharing is done securely by giving
the VM processes permission to read the code but not edit it.
Since it is not possible for applications to interfere with each other based on the OS level
security and Dalvik VMs are confined to a single OS process, Dalvik itself is not concerned
with runtime security.

Coming to the end...


Java is the official language chosen for android app
development.
The flexibility of "javabyte" code allows itself to be
executed on any platform using a JVM.(Dalvik for android)
.java files are converted to .class files by java
compiler.These files are given to dx tools to generate
single dex file.This dex file is given to Dalvik VM to
generate the final m/c code which is executed by the
processor.
Dalvik is not concerned with runtime security.

Potrebbero piacerti anche