Upgrade to Pro — share decks privately, control downloads, hide ads and more …

How Instant Run works @DroidKaigi2016

Atsushi Eno
February 18, 2016

How Instant Run works @DroidKaigi2016

Atsushi Eno

February 18, 2016
Tweet

More Decks by Atsushi Eno

Other Decks in Technology

Transcript

  1. Instant Run is only About Debug Build Type Debug Release

    Exec. Environment only developer anywhere Build Frequency very often few times Build Perf. Requirement should be fast doesn't matter App Size doesn't matter should be small
  2. Android Debug Build ◇ can Package only for Developer's Device

    ◇ can Skip Proguard ◇ can Copy and Install Any Support Files on Developer's Device cf. iOS debug build
  3. What is a "Build System"? ◇ describe a set of

    Tasks to get build Outputs ■ from build Inputs ■ (each Task has Inputs and Outputs) ◇ describe Dependencies of each build Task. ◇ Tasks Cache their Outputs and Skip execution, if not needed. ■ should be carefully implemented. [example bug] ◇ deployment can also be a part of the tasks. make, cmake, rake, ant, gradle, gyp, msbuild...
  4. APK: Android Build Output ◇ AndroidManifest.xml ◇ App Code as

    Dalvik Bytecode (classes.dex) ◇ Compiled and Zipped Resources and Assets (resources- debug.ap_) ◇ Native Libraries (libFooBarBaz.so) APK build takes ALL of those as Inputs. Any changes on them will trigger the build and update APK.
  5. Android Build Tasks and events ◇ aapt to process res.,

    9-patch, generate R.java ◇ javac (*.java -> *.class) ◇ proguard, if used ◇ scan all *.class-es for multidex.keep, if used ◇ dx (*.class, *.jar -> *.dex) ◇ zip and zipalign into .apk ◇ sign .apk *.java *.class classes.dex *.jar multidex.keep res/* assets resources-debug.ap_ patched res/* R.java Foo -signed .apk AndroidManifest.xml aapt javac (proguard) (multidex) dx
  6. Android Deployment Tasks and events ◇ Transmit APK to the

    Device (via TCP, for emulator) ◇ Uninstall Previously Installed APK, if any ◇ the Device will... ■ Create and Adjust Permissions for the app. ■ Run `dex2oat` for ART Device.
  7. FD

  8. Fast Deployment What needs improvements: ◇ Reduce APK Installation occurrences.

    ◇ Reduce task execution as much as we can. To achieve that...
  9. Write Code Compile One-Time APK Setup Package Push APK Push

    dex/res Debug ◇ install APK only once (only when required) ◇ While debugging, push only code and data to somewhere. 1st. 2nd. ...
  10. Altered Application ◇ AndroidManifest is injected to use BootstrapApplication ◇

    monkey patching ■ replaces the path to dex, in app data path {ApplicationInfo.datadir}/files/studio-fd/dex/slice-*/*.dex ■ IncrementalClassLoader loads .dex-es from there ■ replaces the path to res and native libs similarly ■ using non-public Android API via reflection...
  11. Split Dex Uploads Keep changes and uploaded units as small

    as possible. ◇ APP code -> small, frequently changed ◇ Library jars -> big, rarely changed ◇ Non-Instant-Build: everything is in one classes.dex. ◇ Instant Build ■ libraries are compiled to one different .dex. ■ Dex Sharding: split .dex to multiple files (default: 10) ■ Skip .dex-ing / uploading / dex2oat if input is older!
  12. Lessons Learned - Be careful when designing adding build tasks.

    - Data Binding - Kotlin - App bootstrap difference may trigger some problems. - PackageManager - Instrumentation
  13. Launch App Navigate to target Activity Launch target Activity Operate

    "Instant" Run Basics Hot Swap Warm Swap Cold Swap ◇ Run code without Restarting App ◇ or, even without Restarting Activity
  14. Detecting Changes ◇ Hot Swap: only when Java classes structures

    haven't changed ◇ Warm Swap: need to identify which resource values matter ◇ Changes to Manifest or referenced values: reinstallation There is some Gradle Task that scans changes and detects them. If it is buggy, Instant Run misbehaves. (InstantRunVerifier.java in Gradle 2.0 source tarball)
  15. Instant: past, present and future? ◇ "Inventing on Principle" (2012)

    → Xcode Playground ◇ "Making Instant C# Viable" (2012) → Xamarin Sketches ◇ Continuous Coding (2015) "The Evolution of Interactive C#" -> Change app code and see results instantly.