What We Concern?
Faster Build Time
More Productivity
Smaller APK size
Benefits Users and Product
Run Time Performance
Closer Look at Android Run Time
Kotlin source
code
(.kt)
Kotlin compiler
(JIT)
Compiler
(AoT)
Android Studio does not support all Java 8 language features,
Supported Java 8 language features and APIs
https://developer.android.com/studio/write/java8-support
Desugaring History
Goal : Allow newer language features to run on all devices
https://android-developers.googleblog.com/2014/12/hello-world-meet-our-new-experimental.html
Jack &Jil ToolChain
 Transforms .java to .dex
 Supports lambda functions & method refs all
android versions.
 Supports Android API 26+
 Does not support java.time.*
 Failed to convert to .dex directly with no bytecode
in between.
 Slow in compilation
RetroLambda
Back Support of Java 8’s lambda expressions to Java 7,6 and 5.
class Java8 {
interface Logger {
void log(String s);
}
public static void main(String... args) {
sayHi(s -> System.out.println(s));
}
private static void sayHi(Logger logger) {
logger.log("Hello!");
}
}
$ javac *.java
$ ls
Java8.java Java8.class Java8$Logger.class
$ $ANDROID_HOME/build-tools/28.0.2/dx --dex --output . *.class Uncaught translation error:
com.android.dx.cf.code.SimException:
ERROR in Java8.main:([Ljava/lang/String;)V: invalid opcode ba - invokedynamic requires --min-sdk-version
>= 26 (currently 13)
1 error; aborting
Sample class
Button button = (Button)findViewById(R.id.button);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(this, "Button clicked",
Toast.LENGTH_LONG).show();
}
});
without lambda expression
with lambda expressions
Button button = (Button)findViewById(R.id.button);
button.setOnClickListener(v -> Toast.makeText(this, "Button
clicked", Toast.LENGTH_LONG).show());
D8 Dexer
 Replacement for Dx.
 Faster Compared to Dx.
 Reducing build time and generated small apk size.
 Optimised .dex means more performance.
https://android-developers.googleblog.com/2017/08/next-generation-dex-compiler-now-in.html
Default toolchain desugaring
D8 integrated desugaring
Just Use Kotlin
 Provides Lambdas
 Method references
 Default and static (-Like) functions on interfaces
 Source transformation
 All of those features are actually implemented by kotlinc is exactly same way that D8
desugars the java 8 byte code
Increases team efficiency
Complies with existing Java code
Easily maintainable
Less buggy
Reduced mobile app development cost
Safe and secure
Resources
 https://developer.android.com/studio/write/java8-support
 https://android-developers.googleblog.com/2017/08/next-generation-dex-compiler-now-in.html
 https://law.justia.com/cases/federal/appellate-courts/cafc/17-1118/17-1118-2018-03-27.html (Google vs Oracle copy right case)
 https://android-developers.googleblog.com/2017/04/java-8-language-features-support-update.html
 https://jakewharton.com/androids-java-8-support/
 https://pusher.com/state-of-kotlin#kotliners
 https://insights.stackoverflow.com/survey/2018/
 https://kotlinlang.org/docs/reference/faq.html
 https://www.appbrain.com/stats/libraries/details/kotlin/kotlin
15
THANK YOU
Phani Gullapalli

D8 Dexer

  • 2.
    What We Concern? FasterBuild Time More Productivity Smaller APK size Benefits Users and Product Run Time Performance
  • 3.
    Closer Look atAndroid Run Time Kotlin source code (.kt) Kotlin compiler
  • 4.
  • 5.
    Android Studio doesnot support all Java 8 language features, Supported Java 8 language features and APIs https://developer.android.com/studio/write/java8-support
  • 6.
    Desugaring History Goal :Allow newer language features to run on all devices https://android-developers.googleblog.com/2014/12/hello-world-meet-our-new-experimental.html Jack &Jil ToolChain  Transforms .java to .dex  Supports lambda functions & method refs all android versions.  Supports Android API 26+  Does not support java.time.*  Failed to convert to .dex directly with no bytecode in between.  Slow in compilation
  • 7.
    RetroLambda Back Support ofJava 8’s lambda expressions to Java 7,6 and 5.
  • 8.
    class Java8 { interfaceLogger { void log(String s); } public static void main(String... args) { sayHi(s -> System.out.println(s)); } private static void sayHi(Logger logger) { logger.log("Hello!"); } } $ javac *.java $ ls Java8.java Java8.class Java8$Logger.class $ $ANDROID_HOME/build-tools/28.0.2/dx --dex --output . *.class Uncaught translation error: com.android.dx.cf.code.SimException: ERROR in Java8.main:([Ljava/lang/String;)V: invalid opcode ba - invokedynamic requires --min-sdk-version >= 26 (currently 13) 1 error; aborting Sample class
  • 9.
    Button button =(Button)findViewById(R.id.button); button.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Toast.makeText(this, "Button clicked", Toast.LENGTH_LONG).show(); } }); without lambda expression with lambda expressions Button button = (Button)findViewById(R.id.button); button.setOnClickListener(v -> Toast.makeText(this, "Button clicked", Toast.LENGTH_LONG).show());
  • 10.
    D8 Dexer  Replacementfor Dx.  Faster Compared to Dx.  Reducing build time and generated small apk size.  Optimised .dex means more performance. https://android-developers.googleblog.com/2017/08/next-generation-dex-compiler-now-in.html
  • 11.
    Default toolchain desugaring D8integrated desugaring
  • 12.
  • 13.
     Provides Lambdas Method references  Default and static (-Like) functions on interfaces  Source transformation  All of those features are actually implemented by kotlinc is exactly same way that D8 desugars the java 8 byte code Increases team efficiency Complies with existing Java code Easily maintainable Less buggy Reduced mobile app development cost Safe and secure
  • 14.
    Resources  https://developer.android.com/studio/write/java8-support  https://android-developers.googleblog.com/2017/08/next-generation-dex-compiler-now-in.html https://law.justia.com/cases/federal/appellate-courts/cafc/17-1118/17-1118-2018-03-27.html (Google vs Oracle copy right case)  https://android-developers.googleblog.com/2017/04/java-8-language-features-support-update.html  https://jakewharton.com/androids-java-8-support/  https://pusher.com/state-of-kotlin#kotliners  https://insights.stackoverflow.com/survey/2018/  https://kotlinlang.org/docs/reference/faq.html  https://www.appbrain.com/stats/libraries/details/kotlin/kotlin
  • 15.