Slide 1

Slide 1 text

No content

Slide 2

Slide 2 text

Destination:

Slide 3

Slide 3 text

- “Sometimes its the journey that teaches you a lot about your destination.” Destination:

Slide 4

Slide 4 text

Bon Voyage!! • Aim: To compile your Android Code. • Material required: Java files, AndroidManifest.xml, resources, assets(optional) • Procedure: Step 1: Your .java files or .kt files gets converted to .class files that is the ByteCode through “javac” or “kotlinc” command.

Slide 5

Slide 5 text

MainActivity.java File: MainActivity.class ByteCode:

Slide 6

Slide 6 text

ByteCode Execution of: c = 2 * (a+b) • iConst 2 • iLoad a • iLoad b • iAdd • iMul • iStore c a b 42 7 C 0 2

Slide 7

Slide 7 text

ByteCode Execution of: c = 2 * (a+b) • iConst 2 • iLoad a • iLoad b • iAdd • iMul • iStore c a b 42 7 C 0 2 42

Slide 8

Slide 8 text

ByteCode Execution of: c = 2 * (a+b) • iConst 2 • iLoad a • iLoad b • iAdd • iMul • iStore c a b 42 7 C 0 2 42 7

Slide 9

Slide 9 text

ByteCode Execution of: c = 2 * (a+b) • iConst 2 • iLoad a • iLoad b • iAdd • iMul • iStore c a b 42 7 C 0 2 49

Slide 10

Slide 10 text

ByteCode Execution of: c = 2 * (a+b) • iConst 2 • iLoad a • iLoad b • iAdd • iMul • iStore c a b 42 7 C 0 98

Slide 11

Slide 11 text

ByteCode Execution of: c = 2 * (a+b) • iConst 2 • iLoad a • iLoad b • iAdd • iMul • iStore c a b 42 7 C 98

Slide 12

Slide 12 text

• Android does not use this .class file directly. Android has its own byte code format and its own virtual machine that is Dalvik Virtual Machine. • Multiple .class files or class files from any .jar file gets converted to a single classes.dex file. • Dx tool from the build platform tools inside Android SDK converts multiple .class files into single classes.dex .

Slide 13

Slide 13 text

MainActivity.dex MainActivity.java Dx: --dex --output MainActivity.dex

Slide 14

Slide 14 text

Dalvik code of int foo = 1+2 const-1 r0 1 foo Dest Arg0 Arg1

Slide 15

Slide 15 text

Dalvik code of int foo = 1+2 const-1 r0 1 add-int/lit8 r1 Foo Arg1 Arg0 Dest

Slide 16

Slide 16 text

Dalvik code of int foo = 1+2 const-1 r0 1 add-int/lit8 r1 Foo r0 2 Dest Arg0 Arg1

Slide 17

Slide 17 text

Dalvik code of int foo = 1+2 const-1 r0 1 add-int/lit8 r1 Foo r0 2 1 Dest Arg0 Arg1

Slide 18

Slide 18 text

Dalvik code of int foo = 1+2 const-1 r0 1 add-int/lit8 r1 Foo r0 2 1 1+2 Dest Arg0 Arg1

Slide 19

Slide 19 text

Building a story from Why? - “The art and science of asking questions is the source of all knowledge. The more you ask the more you know” • Why does Android not use .class files? • Why does Android not use JVM?

Slide 20

Slide 20 text

Types of Virtual Machine • Virtual machine is a software environment that can be an emulator, an operating system or complete hardware virtualization, that has implementation of resources without the actual hardware. • Two types of VM on basis of architecture: Stack Based architecture and Register Based Architecture.

Slide 21

Slide 21 text

Types of Virtual Machine • Virtual machine is a software environment that can be an emulator, an operating system or complete hardware virtualization, that has implementation of resources without the actual hardware. • Two types of VM on basis of architecture: Stack Based architecture and Register Based Architecture. • And yes, from previous examples you guessed right: JVM: Stack Based Architecture DVM: Register Based Architecture

Slide 22

Slide 22 text

Let’s look numbers • Study on different VM shows that register based architecture requires an 47% less executed VM instructions than stack based. • Register based code is 25% larger in code size than the corresponding stack based code but this overall effects around 1.05% on load of VM. • So overall performance is that Dalvik VM is taking 32.3 % less time to execute standard benchmarks. • Licensing issues from Sun side which also led to have conflicts and thus Android took another VM. • Used because of memory limitations, reduce system overhead, redundancies and bringing optimization to .class files. - And you will have the answer to WHY? 1 2 3 Dalvik VM JVM

Slide 23

Slide 23 text

.class . . . . . . . . .class .class .class . .

Slide 24

Slide 24 text

.class . . . . . . . . .class .class .class . . classes.dex

Slide 25

Slide 25 text

Step 2: Resources Prepared • Drawables (all dpis: xxhdpi, mdpi, xhdpi, hdpi) • Layout files • Menu files (optional) • Anim folder • raw • Color • Styles

Slide 26

Slide 26 text

Putting it all together • Material 3: Android asset Packaging Tool. • It allows to create, update zip compatible archive (apk, zip, jar). It can also compile resources into binary assets. • Printing permissions, printing resources, print configurations supported. • Step 3: aapt zip classes.dex, resources and AndroidManifest.xml into a zip archive called APK.

Slide 27

Slide 27 text

The Final picture to the APK

Slide 28

Slide 28 text

Installation Dalvik ART ???

Slide 29

Slide 29 text

Dalvik • Based on JIT (Just in Time) Compilation • Every time your app runs, part of code important for its execution is going to be translated to machine code at that moment. Further caching while app is running. • DEX to ODEX conversion and copy to dalvik-cache. • Optimizations: • Replace method index with vtable index • Replace field index with byte offset • Replacement with inline calls • Cut Empty methods

Slide 30

Slide 30 text

ART: The next level • Based on AOT (Ahead of time) compilation. • Perform dex2oat to have a elf file. • Solved garbage collection issues. • Improved battery performance as power to interpret line by line is saved.

Slide 31

Slide 31 text

Installation Picture

Slide 32

Slide 32 text

Thank you !