Share
Embed
R8/ProGuard 徹底比較
DroidKaigi2019:
R8はJavaコードを最適化されたdexコードに変換するためのシュリンカーです。Proguardを置き換える目的で作成されました。R8ではコンパイルタイムの軽減、dexコードのさらなる最適化を目指しています。
dexコードのさらなる最適化とは具体的にどのようなものでしょうか?
本セッションでは、R8でどのような最適化が行われているかをバイトコードレベルから説明します。また、Kotlinに関する最適化など、R8の特徴について説明し、Proguardと比べどこが進化したのかを紹介します。
具体的に以下のことを学ぶことが出来ます。
- R8の内部実装
- R8とProguardの違い
- R8ではどのような最適化が行われているか?
Sato Shun
February 07, 2019
Transcript
143 slides
-
௨ৗͷϏϧυ Dalvik όΠτίʔυ (.dex) javac kotlinc D8 Java όΠτίʔυ (.class)
ιʔε ίʔυ (.java/.kt) -
ProGuardΛͬͨϏϧυ Optimized Dalvik όΠτίʔυ (.dex) javac kotlinc D8 Java όΠτίʔυ
(.class) ιʔε ίʔυ (.java/.kt) Optimized Java όΠτίʔυ (.class) ProGuard -
R8ΛͬͨϏϧυ Optimized Dalvik όΠτίʔυ (.dex) javac kotlinc R8 Java όΠτίʔυ
(.class) ιʔε ίʔυ (.java/.kt) -
addconfigurationdebuggingͷྫ • GsonͰઆ໌͢Δ • GsonҎԼͷProGuardઃఆ͕ඞཁ • -keep class * implements
com.google.gson.JsonDeserializer • ͜ͷઃఆ͕ͳ͍߹ʹͲ͏ͳΔ͔? -
E Process: com.github.satoshun.example, PID: 11495 E java.lang.RuntimeException: Unable to start
activity ComponentInfo{com.github.satoshun.example/com.github.satoshun.example.MainActivity}: java.lang.Il legalArgumentException: Invalid attempt to bind an instance of com.github.satoshun.example.TestDeserializer as a @JsonAdapter for com.github.satoshun. example.Hoge. @JsonAdapter value must be a TypeAdapter, TypeAdapterFactory, JsonSerializer or JsonDeserializer. E at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2913) E at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3048) -
E Process: com.github.satoshun.example, PID: 11495 E java.lang.RuntimeException: Unable to start
activity ComponentInfo{com.github.satoshun.example/com.github.satoshun.example.MainActivity}: java.lang.Il legalArgumentException: Invalid attempt to bind an instance of com.github.satoshun.example.TestDeserializer as a @JsonAdapter for com.github.satoshun. example.Hoge. @JsonAdapter value must be a TypeAdapter, TypeAdapterFactory, JsonSerializer or JsonDeserializer. E at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2913) E at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3048) -addconfigurationdebuggingΛ ઃఆʹՃ -
ProGuard W The class 'com.google.gson.internal.ConstructorConstructor' is calling Class.getDeclaredConstructor W on
class 'com.github.satoshun.example.TestDeserializer' to retrieve W the constructor with signature (), but the latter could not be found. W It may have been obfuscated or shrunk. W You should consider preserving the constructor, with a setting like: W -keepclassmembers class com.github.satoshun.example.TestDeserializer { W public <init>(); W } -
ProGuard W The class 'com.google.gson.internal.ConstructorConstructor' is calling Class.getDeclaredConstructor W on
class 'com.github.satoshun.example.TestDeserializer' to retrieve W the constructor with signature (), but the latter could not be found. W It may have been obfuscated or shrunk. W You should consider preserving the constructor, with a setting like: W -keepclassmembers class com.github.satoshun.example.TestDeserializer { W public <init>(); W } -
checkdiscard • ରͷΫϥεɺϝϯόʔ͕ ফ͍͑ͯΔ͔Λ֬ೝ͢Δ • ΠϯϥΠϯԽͰ͋ͬͨΓɺ unusedͰফ͞Ε͍ͯΕ͓̺ fun noInline(i: Int)
{ … } —- -checkdiscard class ** { *** noInline(***); } —- Item void CheckDiscardKt.noInline(int) was not discarded. Error: Discard checks failed. -
assumevaluesͷྫ ͜ͷͱ͖ɺminSdk͕16ͩ ͱɺelse۟ʹདྷΔ͜ͱͳ ͍ if (Build.VERSION.SDK_INT >= 16) { println("true")
} else { println("false") } -
assumevaluesͷྫ if (Build.VERSION.SDK_INT >= 16) { println("true") } else {
println("false") } -assumevalues class android.os.Build$VERSION { int SDK_INT return 16..2147483647; } -
assumevaluesͷྫ if (Build.VERSION.SDK_INT >= 16) { println("true") } else {
println("false") } -assumevalues class android.os.Build$VERSION { int SDK_INT return 16..2147483647; } if (true) { println("true") } else { println("false") } -
assumevaluesͷྫ if (Build.VERSION.SDK_INT >= 16) { println("true") } else {
println("false") } -assumevalues class android.os.Build$VERSION { int SDK_INT return 16..2147483647; } if (true) { println("true") } else { println("false") } -
assumevaluesͷྫ if (Build.VERSION.SDK_INT >= 16) { println("true") } else {
println("false") } -assumevalues class android.os.Build$VERSION { int SDK_INT return 16..2147483647; } println("true") CompatܥͷϥΠϒϥϦͰԼҐޓʹྀ͍ͯ͠Δ ίʔυ͕ଟ͍ͨΊɺ͔ͳΓͷίʔυݮ͕ظͰ͖ Δɻ ·ͨɺAGP 3.4.0-beta02͔Β্هͷઃఆ͕σ ϑΥϧτͰೖΔΑ͏ʹͳͬͨʂʂ -
public class HelloWorld { private int a = 111; public
void main() { System.out.println("Hello World!!" + a); } } -
$ javac *.java $ ls HelloWorld.class … $ java -jar
$R8_HOME/build/libs/d8.jar \ --release \ *.class $ ls classes.dex … -
$ javac *.java $ ls HelloWorld.class … $ java -jar
$R8_HOME/build/libs/d8.jar \ --release \ *.class $ ls classes.dex … $ $ANDROID_HOME/build-tools/28.0.3/dexdump -d classes.dex Opened 'classes.dex', DEX version '035' Class #0 - Class descriptor : ‘LHelloWorld;' … -
Class #0 - Class descriptor : 'LHelloWorld;' Access flags :
0x0001 (PUBLIC) Superclass : 'Ljava/lang/Object;' Interfaces - Static fields - Instance fields - #0 : (in LHelloWorld;) name : 'a' type : 'I' access : 0x0002 (PRIVATE) … -
Class #0 - Class descriptor : 'LHelloWorld;' Access flags :
0x0001 (PUBLIC) Superclass : 'Ljava/lang/Object;' Interfaces - Static fields - Instance fields - #0 : (in LHelloWorld;) name : 'a' type : 'I' access : 0x0002 (PRIVATE) class HelloWorld -
Class #0 - Class descriptor : 'LHelloWorld;' Access flags :
0x0001 (PUBLIC) Superclass : 'Ljava/lang/Object;' Interfaces - Static fields - Instance fields - #0 : (in LHelloWorld;) name : 'a' type : 'I' access : 0x0002 (PRIVATE) public class HelloWorld -
Class #0 - Class descriptor : 'LHelloWorld;' Access flags :
0x0001 (PUBLIC) Superclass : 'Ljava/lang/Object;' Interfaces - Static fields - Instance fields - #0 : (in LHelloWorld;) name : 'a' type : 'I' access : 0x0002 (PRIVATE) public class HelloWorld -
Class #0 - Class descriptor : 'LHelloWorld;' Access flags :
0x0001 (PUBLIC) Superclass : 'Ljava/lang/Object;' Interfaces - Static fields - Instance fields - #0 : (in LHelloWorld;) name : 'a' type : 'I' access : 0x0002 (PRIVATE) public class HelloWorld -
Class #0 - Class descriptor : 'LHelloWorld;' Access flags :
0x0001 (PUBLIC) Superclass : 'Ljava/lang/Object;' Interfaces - Static fields - Instance fields - #0 : (in LHelloWorld;) name : 'a' type : 'I' access : 0x0002 (PRIVATE) public class HelloWorld -
Class #0 - Class descriptor : 'LHelloWorld;' Access flags :
0x0001 (PUBLIC) Superclass : 'Ljava/lang/Object;' Interfaces - Static fields - Instance fields - #0 : (in LHelloWorld;) name : 'a' type : 'I' access : 0x0002 (PRIVATE) public class HelloWorld { private int a; } -
Direct methods - #0 : (in LHelloWorld;) name : '<init>'
type : '()V' access : 0x10001 (PUBLIC CONSTRUCTOR) … [000194] HelloWorld.<init>:()V 0000: invoke-direct {v1}, Ljava/lang/Object;.<init>:()V // method@0003 0003: const/16 v0, #int 111 // #6f 0005: iput v0, v1, LHelloWorld;.a:I // field@0000 0007: return-void … -
Direct methods - #0 : (in LHelloWorld;) name : '<init>'
type : '()V' access : 0x10001 (PUBLIC CONSTRUCTOR) … [000194] HelloWorld.<init>:()V 0000: invoke-direct {v1}, Ljava/lang/Object;.<init>:()V // method@0003 0003: const/16 v0, #int 111 // #6f 0005: iput v0, v1, LHelloWorld;.a:I // field@0000 0007: return-void … public class HelloWorld { private int a; public HelloWorld() { } } -
… [000194] HelloWorld.<init>:()V 0000: invoke-direct {v1}, Ljava/lang/Object;.<init>:()V // method@0003 0003:
const/16 v0, #int 111 // #6f 0005: iput v0, v1, LHelloWorld;.a:I // field@0000 0007: return-void … -
… [000194] HelloWorld.<init>:()V 0000: invoke-direct {v1}, Ljava/lang/ Object;.<init>:()V // method@0003
0003: const/16 v0, #int 111 // #6f 0005: iput v0, v1, LHelloWorld;.a:I // field@0000 0007: return-void … public class HelloWorld { private int a; public HelloWorld() { super(); } } -
… [000194] HelloWorld.<init>:()V 0000: invoke-direct {v1}, Ljava/lang/Object;.<init>:()V // method@0003 0003:
const/16 v0, #int 111 // #6f 0005: iput v0, v1, LHelloWorld;.a:I // field@0000 0007: return-void … public class HelloWorld { private int a; public HelloWorld() { super(); int v0 = 111; } } -
… [000194] HelloWorld.<init>:()V 0000: invoke-direct {v1}, Ljava/lang/Object;.<init>:()V // method@0003 0003:
const/16 v0, #int 111 // #6f 0005: iput v0, v1, LHelloWorld;.a:I // field@0000 0007: return-void … public class HelloWorld { private int a; public HelloWorld() { super(); (int v0 = 111;) this.a = v0; } } -
… [000194] HelloWorld.<init>:()V 0000: invoke-direct {v1}, Ljava/lang/Object;.<init>:()V // method@0003 0003:
const/16 v0, #int 111 // #6f 0005: iput v0, v1, LHelloWorld;.a:I // field@0000 0007: return-void … public class HelloWorld { private int a; public HelloWorld() { super(); (int v0 = 111;) this.a = v0; } } -
Virtual methods - #0 : (in LHelloWorld;) name : 'main'
type : '()V' access : 0x0001 (PUBLIC) … [0001b4] HelloWorld.main:()V 0000: sget-object v0, Ljava/lang/System;.out:Ljava/io/PrintStream; // field@0001 0002: new-instance v1, Ljava/lang/StringBuilder; // type@0005 0004: invoke-direct {v1}, Ljava/lang/StringBuilder;.<init>:()V // method@0004 0007: const-string v2, "Hello World!!" // string@0001 0009: invoke-virtual {v1, v2}, Ljava/lang/StringBuilder;.append:(Ljava/lang/String;)Ljava/ lang/StringBuilder; // method@0006 000c: iget v2, v3, LHelloWorld;.a:I // field@0000 000e: invoke-virtual {v1, v2}, Ljava/lang/StringBuilder;.append:(I)Ljava/lang/ StringBuilder; // method@0005 0011: invoke-virtual {v1}, Ljava/lang/StringBuilder;.toString:()Ljava/lang/String; // method@0007 0014: move-result-object v1 0015: invoke-virtual {v0, v1}, Ljava/io/PrintStream;.println:(Ljava/lang/String;)V // method@0002 0018: return-void … -
Virtual methods - #0 : (in LHelloWorld;) name : 'main'
type : '()V' access : 0x0001 (PUBLIC) … [0001b4] HelloWorld.main:()V 0000: sget-object v0, Ljava/lang/System;.out:Ljava/io/PrintStream; // field@0001 0002: new-instance v1, Ljava/lang/StringBuilder; // type@0005 0004: invoke-direct {v1}, Ljava/lang/StringBuilder;.<init>:()V // method@0004 0007: const-string v2, "Hello World!!" // string@0001 0009: invoke-virtual {v1, v2}, Ljava/lang/StringBuilder;.append:(Ljava/lang/String;)Ljava/ lang/StringBuilder; // method@0006 000c: iget v2, v3, LHelloWorld;.a:I // field@0000 000e: invoke-virtual {v1, v2}, Ljava/lang/StringBuilder;.append:(I)Ljava/lang/ StringBuilder; // method@0005 0011: invoke-virtual {v1}, Ljava/lang/StringBuilder;.toString:()Ljava/lang/String; // method@0007 0014: move-result-object v1 0015: invoke-virtual {v0, v1}, Ljava/io/PrintStream;.println:(Ljava/lang/String;)V // method@0002 0018: return-void … public class HelloWorld { private int a; … public void main() { } } -
[0001b4] HelloWorld.main:()V 0000: sget-object v0, Ljava/lang/System;.out:Ljava/io/PrintStream; // field@0001 0002: new-instance
v1, Ljava/lang/StringBuilder; // type@0005 0004: invoke-direct {v1}, Ljava/lang/StringBuilder;.<init>:()V // method@0004 0007: const-string v2, "Hello World!!" // string@0001 0009: invoke-virtual {v1, v2}, Ljava/lang/StringBuilder;.append:(Ljava/lang/String;)Ljava/ lang/StringBuilder; // method@0006 000c: iget v2, v3, LHelloWorld;.a:I // field@0000 000e: invoke-virtual {v1, v2}, Ljava/lang/StringBuilder;.append:(I)Ljava/lang/ StringBuilder; // method@0005 0011: invoke-virtual {v1}, Ljava/lang/StringBuilder;.toString:()Ljava/lang/String; // method@0007 0014: move-result-object v1 0015: invoke-virtual {v0, v1}, Ljava/io/PrintStream;.println:(Ljava/lang/String;)V // method@0002 0018: return-void … -
[0001b4] HelloWorld.main:()V 0000: sget-object v0, Ljava/lang/System;.out:Ljava/ io/PrintStream; // field@0001 0002:
new-instance v1, Ljava/lang/StringBuilder; // type@0005 0004: invoke-direct {v1}, Ljava/lang/StringBuilder;.<init>:()V // method@0004 0007: const-string v2, "Hello World!!" // string@0001 0009: invoke-virtual {v1, v2}, Ljava/lang/StringBuilder;.append:(Ljava/lang/String;)Ljava/ lang/StringBuilder; // method@0006 000c: iget v2, v3, LHelloWorld;.a:I // field@0000 000e: invoke-virtual {v1, v2}, Ljava/lang/StringBuilder;.append:(I)Ljava/lang/ StringBuilder; // method@0005 0011: invoke-virtual {v1}, Ljava/lang/StringBuilder;.toString:()Ljava/lang/String; // method@0007 0014: move-result-object v1 0015: invoke-virtual {v0, v1}, Ljava/io/PrintStream;.println:(Ljava/lang/String;)V // method@0002 0018: return-void … public class HelloWorld { private int a; … public void main() { java.io.PrintStream v0 = System.out; } } -
[0001b4] HelloWorld.main:()V 0000: sget-object v0, Ljava/lang/System;.out:Ljava/io/PrintStream; // field@0001 0002: new-instance
v1, Ljava/lang/StringBuilder; // type@0005 0004: invoke-direct {v1}, Ljava/lang/ StringBuilder;.<init>:()V // method@0004 0007: const-string v2, "Hello World!!" // string@0001 0009: invoke-virtual {v1, v2}, Ljava/lang/StringBuilder;.append:(Ljava/lang/String;)Ljava/ lang/StringBuilder; // method@0006 000c: iget v2, v3, LHelloWorld;.a:I // field@0000 000e: invoke-virtual {v1, v2}, Ljava/lang/StringBuilder;.append:(I)Ljava/lang/ StringBuilder; // method@0005 0011: invoke-virtual {v1}, Ljava/lang/StringBuilder;.toString:()Ljava/lang/String; // method@0007 0014: move-result-object v1 0015: invoke-virtual {v0, v1}, Ljava/io/PrintStream;.println:(Ljava/lang/String;)V // method@0002 0018: return-void … public class HelloWorld { private int a; … public void main() { java.io.PrintStream v0 = System.out; java.lang.StringBuilder v1 = new StringBuilder(); } } -
[0001b4] HelloWorld.main:()V 0000: sget-object v0, Ljava/lang/System;.out:Ljava/io/PrintStream; // field@0001 0002: new-instance
v1, Ljava/lang/StringBuilder; // type@0005 0004: invoke-direct {v1}, Ljava/lang/StringBuilder;.<init>:()V // method@0004 0007: const-string v2, "Hello World!!" // string@0001 0009: invoke-virtual {v1, v2}, Ljava/lang/StringBuilder;.append:(Ljava/lang/String;)Ljava/ lang/StringBuilder; // method@0006 000c: iget v2, v3, LHelloWorld;.a:I // field@0000 000e: invoke-virtual {v1, v2}, Ljava/lang/StringBuilder;.append:(I)Ljava/lang/ StringBuilder; // method@0005 0011: invoke-virtual {v1}, Ljava/lang/StringBuilder;.toString:()Ljava/lang/String; // method@0007 0014: move-result-object v1 0015: invoke-virtual {v0, v1}, Ljava/io/PrintStream;.println:(Ljava/lang/String;)V // method@0002 0018: return-void … public class HelloWorld { private int a; … public void main() { java.io.PrintStream v0 = System.out; java.lang.StringBuilder v1 = new StringBuilder(); String v2 = "Hello World!!”; } } -
… 0009: invoke-virtual {v1, v2}, Ljava/lang/ StringBuilder;.append:(Ljava/lang/String;)Ljava/ lang/StringBuilder; // method@0006
000c: iget v2, v3, LHelloWorld;.a:I // field@0000 000e: invoke-virtual {v1, v2}, Ljava/lang/StringBuilder;.append:(I)Ljava/lang/ StringBuilder; // method@0005 0011: invoke-virtual {v1}, Ljava/lang/StringBuilder;.toString:()Ljava/lang/String; // method@0007 0014: move-result-object v1 0015: invoke-virtual {v0, v1}, Ljava/io/PrintStream;.println:(Ljava/lang/String;)V // method@0002 0018: return-void … public class HelloWorld { private int a; … public void main() { java.io.PrintStream v0 = System.out; java.lang.StringBuilder v1 = new StringBuilder(); String v2 = "Hello World!!”; v1.append(v2); } } -
… lang/StringBuilder; // method@0006 000c: iget v2, v3, LHelloWorld;.a:I //
field@0000 000e: invoke-virtual {v1, v2}, Ljava/lang/StringBuilder;.append:(I)Ljava/lang/ StringBuilder; // method@0005 0011: invoke-virtual {v1}, Ljava/lang/StringBuilder;.toString:()Ljava/lang/String; // method@0007 0014: move-result-object v1 0015: invoke-virtual {v0, v1}, Ljava/io/PrintStream;.println:(Ljava/lang/String;)V // method@0002 0018: return-void … public class HelloWorld { private int a; … public void main() { java.io.PrintStream v0 = System.out; java.lang.StringBuilder v1 = new StringBuilder(); String v2 = "Hello World!!”; v1.append(v2); int v2 = this.a; } } -
… 000e: invoke-virtual {v1, v2}, Ljava/lang/ StringBuilder;.append:(I)Ljava/lang/ StringBuilder; // method@0005
0011: invoke-virtual {v1}, Ljava/lang/StringBuilder;.toString:()Ljava/lang/String; // method@0007 0014: move-result-object v1 0015: invoke-virtual {v0, v1}, Ljava/io/PrintStream;.println:(Ljava/lang/String;)V // method@0002 0018: return-void … public class HelloWorld { private int a; … public void main() { java.io.PrintStream v0 = System.out; java.lang.StringBuilder v1 = new StringBuilder(); String v2 = "Hello World!!”; v1.append(v2); int v2 = this.a; v1.append(v2); } -
… 0011: invoke-virtual {v1}, Ljava/lang/ StringBuilder;.toString:()Ljava/lang/String; // method@0007 0014: move-result-object
v1 0015: invoke-virtual {v0, v1}, Ljava/io/PrintStream;.println:(Ljava/lang/String;)V // method@0002 0018: return-void … public class HelloWorld { private int a; … public void main() { … v1.append(v2); v1.toString(); } } -
[0001b4] HelloWorld.main:()V … 0014: move-result-object v1 0015: invoke-virtual {v0, v1},
Ljava/io/PrintStream;.println:(Ljava/lang/String;)V // method@0002 0018: return-void … public class HelloWorld { private int a; … public void main() { … v1.append(v2); v1.toString(); } } -
[0001b4] HelloWorld.main:()V … 0015: invoke-virtual {v0, v1}, Ljava/io/ PrintStream;.println:(Ljava/lang/String;)V //
method@0002 0018: return-void … public class HelloWorld { private int a; … public void main() { … v1.append(v2); v0.println(v1.toString()); } } -
[0001b4] HelloWorld.main:()V 0000: sget-object v0, Ljava/lang/System;.out:Ljava/io/PrintStream; // field@0001 0002: new-instance
v1, Ljava/lang/StringBuilder; // type@0005 0004: invoke-direct {v1}, Ljava/lang/StringBuilder;.<init>:()V // method@0004 0007: const-string v2, "Hello World!!" // string@0001 0009: invoke-virtual {v1, v2}, Ljava/lang/StringBuilder;.append:(Ljava/lang/String;)Ljava/ lang/StringBuilder; // method@0006 000c: iget v2, v3, LHelloWorld;.a:I // field@0000 000e: invoke-virtual {v1, v2}, Ljava/lang/StringBuilder;.append:(I)Ljava/lang/ StringBuilder; // method@0005 0011: invoke-virtual {v1}, Ljava/lang/StringBuilder;.toString:()Ljava/lang/String; // method@0007 0014: move-result-object v1 0015: invoke-virtual {v0, v1}, Ljava/io/PrintStream;.println:(Ljava/lang/String;)V // method@0002 0018: return-void … -
public class HelloWorld { private int a; public HelloWorld() {
super(); (int v0 = 111;) this.a = v0; } public void main() { java.io.PrintStream v0 = System.out; java.lang.StringBuilder v1 = new StringBuilder(); String v2 = "Hello World!!”; v1.append(v2); int v2 = this.a; v1.append(v2); v0.println(v1.toString()); } } -
class CompanionTest { companion object { fun show(i: Int) {
println("started show method") println("processing show method action $i") println("finished show method") } } } -
public final class CompanionTest { public static final Companion Companion
= new Companion(); public static final class Companion { private Companion() { } public /* synthetic */ Companion(DefaultConstructorMarker defaultConstructorMarker) { this(); } public final void show(int i) { System.out.println("started show method"); StringBuilder stringBuilder = new StringBuilder(); stringBuilder.append("processing show method action "); stringBuilder.append(i); System.out.println(stringBuilder.toString()); System.out.println("finished show method"); } } } -
public final class CompanionTest { public static final Companion Companion
= new Companion(); public static final class Companion { private Companion() { } public /* synthetic */ Companion(DefaultConstructorMarker defaultConstructorMarker) { this(); } public final void show(int i) { System.out.println("started show method"); StringBuilder stringBuilder = new StringBuilder(); stringBuilder.append("processing show method action "); stringBuilder.append(i); System.out.println(stringBuilder.toString()); System.out.println("finished show method"); } } } CompanionΠϯελϯε͕ੜ͞ΕΔ & NestedΫϥε͕ఆٛ͞ΕΔ -
public final class CompanionTest { public static final Companion Companion
= new Companion(); public static final class Companion { private Companion() { } public /* synthetic */ Companion(DefaultConstructorMarker defaultConstructorMarker) { this(); } public final void show(int i) { System.out.println("started show method"); StringBuilder stringBuilder = new StringBuilder(); stringBuilder.append("processing show method action "); stringBuilder.append(i); System.out.println(stringBuilder.toString()); System.out.println("finished show method"); } } } CompanionΠϯελϯε͕ੜ͞ΕΔ & NestedΫϥε͕ఆٛ͞ΕΔ ͜ΕΛR8ͰίϯύΠϧ͢Δ -
public abstract class CompanionTest { public static final void show(int
i) { System.out.println("started show method"); StringBuilder stringBuilder = new StringBuilder(); stringBuilder.append("processing show method action "); stringBuilder.append(i); System.out.println(stringBuilder.toString()); System.out.println("finished show method"); } } -
public abstract class CompanionTest { public static final void show(int
i) { System.out.println("started show method"); StringBuilder stringBuilder = new StringBuilder(); stringBuilder.append("processing show method action "); stringBuilder.append(i); System.out.println(stringBuilder.toString()); System.out.println("finished show method"); } } Πϯελϯεੜ͕ແ͘ͳͬͨ & NestedΫϥε͕ແ͘ͳͬͨ -
public abstract class CompanionTest { public static final void show(int
i) { System.out.println("started show method"); StringBuilder stringBuilder = new StringBuilder(); stringBuilder.append("processing show method action "); stringBuilder.append(i); System.out.println(stringBuilder.toString()); System.out.println("finished show method"); } } R8Ͱstaticϝιουʹม͞ΕΔͨΊɺ ΠϯελϯεΛੜ͠ͳͯ͘ྑ͘ͳ͍ͬͯΔ -
public final class CompanionTest { public static final Companion Companion
= new Companion(); public static final class Companion { private Companion() { } public /* synthetic */ Companion(byte b) { this(); } public static void show(int i) { System.out.println("started show method"); System.out.println("processing show method action ".concat(String.valueOf(i))); System.out.println("finished show method"); } } } -
public final class CompanionTest { public static final Companion Companion
= new Companion(); public static final class Companion { private Companion() { } public /* synthetic */ Companion(byte b) { this(); } public static void show(int i) { System.out.println("started show method"); System.out.println("processing show method action ".concat(String.valueOf(i))); System.out.println("finished show method"); } } } -
public final class CompanionTest { public static final Companion Companion
= new Companion(); public static final class Companion { private Companion() { } public /* synthetic */ Companion(byte b) { this(); } public static void show(int i) { System.out.println("started show method"); System.out.println("processing show method action ".concat(String.valueOf(i))); System.out.println("finished show method"); } } } ProGuradͰCompanionΠϯελϯε͕ফ͑ͳ͍ & NestedΫϥεఆٛ͞Εͨ·· -
Companion Object·ͱΊ • KotlinͰstaticϝιουΛදݱ͢ΔͷʹCompanion ObjectΛ ͏ͱɺJavaΑΓύϑΥʔϚϯε໘ͰෆརʹͳΔ • R8ͦͷΛߟྀ͠ɺ࠷దԽΛߦ͏ • Javaͷstaticϝιουͱಉ͍͡ํΛ͍ͯ͠Δͱ͖ͷΈ༗ޮͳ
࠷దԽ • ΠϯλʔϑΣʔεͷ࣮Λ͍ͯ͠Δ߹ʹCompanionΠϯελϯεফ ͑ͳ͍ -
fun main() { lambdaTest { println("Kotlin lambda1") } lambdaTest {
println("Kotlin lambda2") } lambdaTest { println("Kotlin lambda3") } } private fun lambdaTest(body: () -> Unit) { println("before lambdaTest") body() println("after lambdaTest") } -
sget-object v0, LLambdaTestKt$main$1;.INSTANCE:LLambdaTestKt$main$1; invoke-static {v0}, LLambdaTestKt;.lambdaTest:(Lkotlin/jvm/functions/ Function0;)V sget-object v0, LLambdaTestKt$main$2;.INSTANCE:LLambdaTestKt$main$2;
invoke-static {v0}, LLambdaTestKt;.lambdaTest:(Lkotlin/jvm/functions/ Function0;)V sget-object v0, LLambdaTestKt$main$3;.INSTANCE:LLambdaTestKt$main$3; invoke-static {v0}, LLambdaTestKt;.lambdaTest:(Lkotlin/jvm/functions/ Function0;)V -
sget-object v0, LLambdaTestKt$main$1;.INSTANCE:LLambdaTestKt$main$1; invoke-static {v0}, LLambdaTestKt;.lambdaTest:(Lkotlin/jvm/functions/ Function0;)V sget-object v0, LLambdaTestKt$main$2;.INSTANCE:LLambdaTestKt$main$2;
invoke-static {v0}, LLambdaTestKt;.lambdaTest:(Lkotlin/jvm/functions/ Function0;)V sget-object v0, LLambdaTestKt$main$3;.INSTANCE:LLambdaTestKt$main$3; invoke-static {v0}, LLambdaTestKt;.lambdaTest:(Lkotlin/jvm/functions/ Function0;)V -
sget-object v0, LLambdaTestKt$main$1;.INSTANCE:LLambdaTestKt$main$1; invoke-static {v0}, LLambdaTestKt;.lambdaTest:(Lkotlin/jvm/functions/ Function0;)V sget-object v0, LLambdaTestKt$main$2;.INSTANCE:LLambdaTestKt$main$2;
invoke-static {v0}, LLambdaTestKt;.lambdaTest:(Lkotlin/jvm/functions/ Function0;)V sget-object v0, LLambdaTestKt$main$3;.INSTANCE:LLambdaTestKt$main$3; invoke-static {v0}, LLambdaTestKt;.lambdaTest:(Lkotlin/jvm/functions/ Function0;)V 3ͭͷΫϥε͕ੜ͞Εͨ - ϥϜμຖʹΫϥε͕ੜ͞ΕΔ -
sget-object v0, L-$ $LambdaGroup$ks$BpS7w8o_KOkdSUy0gHGt84S7irI;.INSTANCE$0:L-$ $LambdaGroup$ks$BpS7w8o_KOkdSUy0gHGt84S7irI; invoke-static {v0}, LLambdaTestKt;.lambdaTest:(Lkotlin/jvm/functions/ Function0;)V sget-object
v0, L-$ $LambdaGroup$ks$BpS7w8o_KOkdSUy0gHGt84S7irI;.INSTANCE$1:L-$ $LambdaGroup$ks$BpS7w8o_KOkdSUy0gHGt84S7irI; invoke-static {v0}, LLambdaTestKt;.lambdaTest:(Lkotlin/jvm/functions/ Function0;)V sget-object v0, L-$ $LambdaGroup$ks$BpS7w8o_KOkdSUy0gHGt84S7irI;.INSTANCE$2:L-$ $LambdaGroup$ks$BpS7w8o_KOkdSUy0gHGt84S7irI; invoke-static {v0}, LLambdaTestKt;.lambdaTest:(Lkotlin/jvm/functions/ Function0;)V -
sget-object v0, L-$ $LambdaGroup$ks$BpS7w8o_KOkdSUy0gHGt84S7irI;.INSTANCE$0:L-$ $LambdaGroup$ks$BpS7w8o_KOkdSUy0gHGt84S7irI; invoke-static {v0}, LLambdaTestKt;.lambdaTest:(Lkotlin/jvm/functions/ Function0;)V sget-object
v0, L-$ $LambdaGroup$ks$BpS7w8o_KOkdSUy0gHGt84S7irI;.INSTANCE$1:L-$ $LambdaGroup$ks$BpS7w8o_KOkdSUy0gHGt84S7irI; invoke-static {v0}, LLambdaTestKt;.lambdaTest:(Lkotlin/jvm/functions/ Function0;)V sget-object v0, L-$ $LambdaGroup$ks$BpS7w8o_KOkdSUy0gHGt84S7irI;.INSTANCE$2:L-$ $LambdaGroup$ks$BpS7w8o_KOkdSUy0gHGt84S7irI; invoke-static {v0}, LLambdaTestKt;.lambdaTest:(Lkotlin/jvm/functions/ Function0;)V -
sget-object v0, L-$ $LambdaGroup$ks$BpS7w8o_KOkdSUy0gHGt84S7irI;.INSTANCE$0:L-$ $LambdaGroup$ks$BpS7w8o_KOkdSUy0gHGt84S7irI; invoke-static {v0}, LLambdaTestKt;.lambdaTest:(Lkotlin/jvm/functions/ Function0;)V sget-object
v0, L-$ $LambdaGroup$ks$BpS7w8o_KOkdSUy0gHGt84S7irI;.INSTANCE$1:L-$ $LambdaGroup$ks$BpS7w8o_KOkdSUy0gHGt84S7irI; invoke-static {v0}, LLambdaTestKt;.lambdaTest:(Lkotlin/jvm/functions/ Function0;)V sget-object v0, L-$ $LambdaGroup$ks$BpS7w8o_KOkdSUy0gHGt84S7irI;.INSTANCE$2:L-$ $LambdaGroup$ks$BpS7w8o_KOkdSUy0gHGt84S7irI; invoke-static {v0}, LLambdaTestKt;.lambdaTest:(Lkotlin/jvm/functions/ Function0;)V LambdaGroupͱݺΕΔ࠷దԽ 1ͭͷΫϥεʹϥϜμΛ·ͱΊΔ͜ͱͰɺ ΫϥεɺϝιουΛݮΒ͢͜ͱ͕Ͱ͖Δ -
// R8.java … IRConverter converter = new IRConverter(appView, options, timing,
printer, mainDexClasses, rootSet); converter.optimize(application, executorService); -
// R8.java … IRConverter converter = new IRConverter(appView, options, timing,
printer, mainDexClasses, rootSet); converter.optimize(application, executorService); IR: Intermediate Representations ιʔείʔυͱ࠷ऴՌͷؒʹ͋Δதؒදݱܗࣜ -
// R8.java … IRConverter converter = new IRConverter(appView, options, timing,
printer, mainDexClasses, rootSet); converter.optimize(application, executorService); -
// IRConverter.java public DexApplication optimize( DexApplication application, ExecutorService executorService )
throws ExecutionException { computeReachabilitySensitivity(application); removeLambdaDeserializationMethods(); collectLambdaMergingCandidates(application); collectStaticizerCandidates(application); … -
// IRConverter.java public DexApplication optimize( DexApplication application, ExecutorService executorService )
throws ExecutionException { computeReachabilitySensitivity(application); removeLambdaDeserializationMethods(); collectLambdaMergingCandidates(application); collectStaticizerCandidates(application); … -
private void collectLambdaMergingCandidates( DexApplication application ) { if (lambdaMerger !=
null) { lambdaMerger.collectGroupCandidates( application, appInfo.withLiveness(), options ); } } -
private void collectLambdaMergingCandidates( DexApplication application ) { if (lambdaMerger !=
null) { lambdaMerger.collectGroupCandidates( application, appInfo.withLiveness(), options ); } } -
private void collectLambdaMergingCandidates( DexApplication application ) { if (lambdaMerger !=
null) { lambdaMerger.collectGroupCandidates( application, appInfo.withLiveness(), options ); } } LambdaMerger: ෳͷϥϜμΛ1ͭͷάϧʔϓʹϚʔδ͢Δ -
// LambdaMerger.collectGroupCandidates app.classes() .stream() .filter(cls -> !infoWithLiveness.isPinned(cls.type)) .filter(cls -> cls.hasKotlinInfo()
&& cls.getKotlinInfo().isSyntheticClass() && cls.getKotlinInfo().asSyntheticClass().isLambda()) .sorted((a, b) -> a.type.slowCompareTo(b.type)) .forEachOrdered(lambda -> { try { LambdaGroupId id = KotlinLambdaGroupIdFactory.create(kotlin, lambda, options); LambdaGroup group = groups.computeIfAbsent(id, LambdaGroupId::createGroup); group.add(lambda); lambdas.put(lambda.type, group); } catch (LambdaStructureError error) { … } }); -
app.classes() .stream() .filter(cls -> !infoWithLiveness.isPinned(cls.type)) .filter(cls -> cls.hasKotlinInfo() && cls.getKotlinInfo().isSyntheticClass()
&& cls.getKotlinInfo().asSyntheticClass().isLambda()) .sorted((a, b) -> a.type.slowCompareTo(b.type)) .forEachOrdered(lambda -> { try { LambdaGroupId id = KotlinLambdaGroupIdFactory.create(kotlin, lambda, options); LambdaGroup group = groups.computeIfAbsent(id, LambdaGroupId::createGroup); group.add(lambda); lambdas.put(lambda.type, group); } catch (LambdaStructureError error) { … } }); -
app.classes() .stream() .filter(cls -> !infoWithLiveness.isPinned(cls.type)) .filter(cls -> cls.hasKotlinInfo() && cls.getKotlinInfo().isSyntheticClass()
&& cls.getKotlinInfo().asSyntheticClass().isLambda()) .sorted((a, b) -> a.type.slowCompareTo(b.type)) .forEachOrdered(lambda -> { try { LambdaGroupId id = KotlinLambdaGroupIdFactory.create(kotlin, lambda, options); LambdaGroup group = groups.computeIfAbsent(id, LambdaGroupId::createGroup); group.add(lambda); lambdas.put(lambda.type, group); } catch (LambdaStructureError error) { … } }); pin͞Ε͍ͯͳ͍ == มܗ͕ՄೳͳΫϥεΛநग़ -
app.classes() .stream() .filter(cls -> !infoWithLiveness.isPinned(cls.type)) .filter(cls -> cls.hasKotlinInfo() && cls.getKotlinInfo().isSyntheticClass()
&& cls.getKotlinInfo().asSyntheticClass().isLambda()) .sorted((a, b) -> a.type.slowCompareTo(b.type)) .forEachOrdered(lambda -> { try { LambdaGroupId id = KotlinLambdaGroupIdFactory.create(kotlin, lambda, options); LambdaGroup group = groups.computeIfAbsent(id, LambdaGroupId::createGroup); group.add(lambda); lambdas.put(lambda.type, group); } catch (LambdaStructureError error) { … } }); Kotlin && ߹Ϋϥε && ϥϜμࣜ -
app.classes() .stream() .filter(cls -> !infoWithLiveness.isPinned(cls.type)) .filter(cls -> cls.hasKotlinInfo() && cls.getKotlinInfo().isSyntheticClass()
&& cls.getKotlinInfo().asSyntheticClass().isLambda()) .sorted((a, b) -> a.type.slowCompareTo(b.type)) .forEachOrdered(lambda -> { try { LambdaGroupId id = KotlinLambdaGroupIdFactory.create(kotlin, lambda, options); LambdaGroup group = groups.computeIfAbsent(id, LambdaGroupId::createGroup); group.add(lambda); lambdas.put(lambda.type, group); } catch (LambdaStructureError error) { … } }); classͷॱ൪Λιʔτ -
app.classes() .stream() .filter(cls -> !infoWithLiveness.isPinned(cls.type)) .filter(cls -> cls.hasKotlinInfo() && cls.getKotlinInfo().isSyntheticClass()
&& cls.getKotlinInfo().asSyntheticClass().isLambda()) .sorted((a, b) -> a.type.slowCompareTo(b.type)) .forEachOrdered(lambda -> { try { LambdaGroupId id = KotlinLambdaGroupIdFactory.create(kotlin, lambda, options); LambdaGroup group = groups.computeIfAbsent(id, LambdaGroupId::createGroup); group.add(lambda); lambdas.put(lambda.type, group); } catch (LambdaStructureError error) { … } }); LambdaGroupIdͱLambdaGroup Λ࡞Δ -
app.classes() .stream() .filter(cls -> !infoWithLiveness.isPinned(cls.type)) .filter(cls -> cls.hasKotlinInfo() && cls.getKotlinInfo().isSyntheticClass()
&& cls.getKotlinInfo().asSyntheticClass().isLambda()) .sorted((a, b) -> a.type.slowCompareTo(b.type)) .forEachOrdered(lambda -> { try { LambdaGroupId id = KotlinLambdaGroupIdFactory.create(kotlin, lambda, options); LambdaGroup group = groups.computeIfAbsent(id, LambdaGroupId::createGroup); group.add(lambda); lambdas.put(lambda.type, group); } catch (LambdaStructureError error) { … } }); LambdaGroupIdΠϯελϯεͷग़ྗ capture: interface: Lkotlin/jvm/functions/Function0; package: signature: null main method name: invoke main method: Proto V void main annotations: com.android.tools.r8.graph.DexAnnotationSet@1 main param annotations: com.android.tools.r8.graph.ParameterAnnotationsList@1 inner: none -
app.classes() .stream() .filter(cls -> !infoWithLiveness.isPinned(cls.type)) .filter(cls -> cls.hasKotlinInfo() && cls.getKotlinInfo().isSyntheticClass()
&& cls.getKotlinInfo().asSyntheticClass().isLambda()) .sorted((a, b) -> a.type.slowCompareTo(b.type)) .forEachOrdered(lambda -> { try { LambdaGroupId id = KotlinLambdaGroupIdFactory.create(kotlin, lambda, options); LambdaGroup group = groups.computeIfAbsent(id, LambdaGroupId::createGroup); group.add(lambda); lambdas.put(lambda.type, group); } catch (LambdaStructureError error) { … } }); -
// IRConverter.java public DexApplication optimize( DexApplication application, ExecutorService executorService )
throws ExecutionException { computeReachabilitySensitivity(application); removeLambdaDeserializationMethods(); collectLambdaMergingCandidates(application); collectStaticizerCandidates(application); … -
// IRConverter.java public DexApplication optimize( DexApplication application, ExecutorService executorService )
throws ExecutionException { … printPhase("Lambda merging finalization"); finalizeLambdaMerging( application, feedback, builder, executorService, synthesizedClasses ); … -
private void finalizeLambdaMerging( DexApplication application, OptimizationFeedback directFeedback, Builder<?> builder, ExecutorService
executorService, Map<DexType, DexProgramClass> synthesizedClasses) throws ExecutionException { if (lambdaMerger != null) { lambdaMerger.applyLambdaClassMapping( application, this, directFeedback, builder, executorService, synthesizedClasses); } } -
private void finalizeLambdaMerging( DexApplication application, OptimizationFeedback directFeedback, Builder<?> builder, ExecutorService
executorService, Map<DexType, DexProgramClass> synthesizedClasses) throws ExecutionException { if (lambdaMerger != null) { lambdaMerger.applyLambdaClassMapping( application, this, directFeedback, builder, executorService, synthesizedClasses); } } -
// LambdaMerger.java private void rewriteLambdaReferences(…) { … for (DexEncodedMethod method
: methods) { DexEncodedMethod mappedMethod = converter.graphLense().mapDexEncodedMethod( method, converter.appInfo, synthesizedClasses); … } -
// LambdaMerger.java private void rewriteLambdaReferences(…) { … for (DexEncodedMethod method
: methods) { DexEncodedMethod mappedMethod = converter.graphLense().mapDexEncodedMethod( method, converter.appInfo, synthesizedClasses); … } -
// LambdaMerger.java private void rewriteLambdaReferences(…) { … for (DexEncodedMethod method
: methods) { DexEncodedMethod mappedMethod = converter.graphLense().mapDexEncodedMethod( method, converter.appInfo, synthesizedClasses); … } GraphLense: ίʔυใΛ֨ೲ͓ͯ͠Γɺ ϝιουɺϑΟʔϧυͷҠಈɺ ΫϥεͷmappingͳͲΛߦ͏ɻ -
private void rewriteLambdaReferences(…) { … for (DexEncodedMethod method : methods)
{ DexEncodedMethod mappedMethod = converter.graphLense().mapDexEncodedMethod( method, converter.appInfo, synthesizedClasses); … } mapDexEncodedMethod: ੜͨ͠߹ΫϥεʢLambdaGroupʣΛGraphLenseʹ ొ͢Δ -
private void rewriteLambdaReferences(…) { … for (DexEncodedMethod method : methods)
{ DexEncodedMethod mappedMethod = converter.graphLense().mapDexEncodedMethod( method, converter.appInfo, synthesizedClasses); … } -
… val retrofit = Retrofit .Builder() .build() val api =
retrofit.create(Api::class.java) api.hoge().execute() } interface Api { @GET fun hoge(): Call<Void> } -
.method public onCreate(Landroid/os/Bundle;)V .line 1 sget-object p1, Lretrofit2/Platform;->a:Lretrofit2/Platform; .line 2
new-instance p1, Ljava/util/ArrayList; invoke-direct {p1}, Ljava/util/ArrayList;-><init>()V new-instance p1, Ljava/util/ArrayList; invoke-direct {p1}, Ljava/util/ArrayList;-><init>()V .line 3 new-instance p1, Ljava/lang/IllegalStateException; const-string v0, "Base URL required." invoke-direct {p1, v0}, Ljava/lang/IllegalStateException;- ><init>(Ljava/lang/String;)V throw p1 .end method -
... Platform platform = Platform.a; ArrayList arrayList = new ArrayList();
arrayList = new ArrayList(); throw new IllegalStateException("Base URL required."); } -
... Platform platform = Platform.a; ArrayList arrayList = new ArrayList();
arrayList = new ArrayList(); throw new IllegalStateException("Base URL required."); } IllegalStateExceptionͰϝιου͕ ऴΘͬͯΔ -
public static final class Builder { private @Nullable HttpUrl baseUrl;
public Builder baseUrl(String baseUrl) { checkNotNull(baseUrl, "baseUrl == null"); return baseUrl(HttpUrl.get(baseUrl)); } public Retrofit build() { if (baseUrl == null) { throw new IllegalStateException("Base URL required."); } … } } -
public static final class Builder { private @Nullable HttpUrl baseUrl;
public Builder baseUrl(String baseUrl) { checkNotNull(baseUrl, "baseUrl == null"); return baseUrl(HttpUrl.get(baseUrl)); } public Retrofit build() { if (baseUrl == null) { throw new IllegalStateException("Base URL required."); } … } } baseUrl͕nullͳΒthrow͍ͯ͠Δ -
… val retrofit = Retrofit .Builder() .build() val api =
retrofit.create(Api::class.java) api.hoge().execute() } -
… Platform platform = Platform.a; ArrayList arrayList = new ArrayList();
arrayList = new ArrayList(); if (baseUrl == null) { throw new IllegalStateException("Base URL required."); } val api = retrofit.create(Api::class.java) api.hoge().execute() } -
… Platform platform = Platform.a; ArrayList arrayList = new ArrayList();
arrayList = new ArrayList(); if (null == null) { throw new IllegalStateException("Base URL required."); } val api = retrofit.create(Api::class.java) api.hoge().execute() } -
… Platform platform = Platform.a; ArrayList arrayList = new ArrayList();
arrayList = new ArrayList(); if (true) { throw new IllegalStateException("Base URL required."); } val api = retrofit.create(Api::class.java) api.hoge().execute() } -
… Platform platform = Platform.a; ArrayList arrayList = new ArrayList();
arrayList = new ArrayList(); throw new IllegalStateException("Base URL required."); } -
class MainActivity : AppCompatActivity() { @Inject lateinit var appService: AppService
@Inject lateinit var appService2: AppService2 override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) val appComponent = DaggerAppComponent.builder().build() appComponent.inject(this) appService.test().execute() appService2.test().execute() } } interface AppService { @GET("todos/1") fun test(): Call<TestData> } interface AppService2 { @GET("todos/1") fun test(): Call<TestData> } -
method public onCreate(Landroid/os/Bundle;)V .registers 3 invoke-super {p0, p1}, La/b/e/a/m;->onCreate(Landroid/os/Bundle;)V const
p1, 0x7f09001c invoke-virtual {p0, p1}, La/b/e/a/m;->setContentView(I)V .line 1 new-instance p1, Lcom/github/satoshun/example/AppModule1; invoke-direct {p1}, Lcom/github/satoshun/example/AppModule1;-><init>()V .line 2 invoke-virtual {p1}, Lcom/github/satoshun/example/AppModule1;->a()Lcom/github/satoshun/example/AppService; move-result-object p1 const-string v0, "Cannot return null from a non-@Nullable @Provides method" invoke-static {p1, v0}, La/b/b/a/a/a;->a(Ljava/lang/Object;Ljava/lang/String;)Ljava/lang/Object; .line 3 iput-object p1, p0, Lcom/github/satoshun/example/MainActivity;->o:Lcom/github/satoshun/example/AppService; .line 4 invoke-static {}, Lcom/github/satoshun/example/AppModule2_ProvideService2Factory;->a()Lcom/github/satoshun/example/AppService2; move-result-object p1 .line 5 iput-object p1, p0, Lcom/github/satoshun/example/MainActivity;->p:Lcom/github/satoshun/example/AppService2; .line 6 iget-object p1, p0, Lcom/github/satoshun/example/MainActivity;->o:Lcom/github/satoshun/example/AppService; const/4 v0, 0x0 if-eqz p1, :cond_3d invoke-interface {p1}, Lcom/github/satoshun/example/AppService;->a()Lretrofit2/Call; move-result-object p1 invoke-interface {p1}, Lretrofit2/Call;->execute()Lretrofit2/Response; iget-object p1, p0, Lcom/github/satoshun/example/MainActivity;->p:Lcom/github/satoshun/example/AppService2; if-eqz p1, :cond_37 invoke-interface {p1}, Lcom/github/satoshun/example/AppService2;->a()Lretrofit2/Call; -
public final class MainActivity extends m { public AppService o;
public AppService2 p; public void onCreate(Bundle bundle) { super.onCreate(bundle); setContentView((int) R.layout.activity_main); Object a = new AppModule1().a(); a.a(a, "Cannot return null from a non-@Nullable @Provides method"); this.o = a; this.p = AppModule2_ProvideService2Factory.a(); AppService appService = this.o; if (appService != null) { appService.a().execute(); AppService2 appService2 = this.p; if (appService2 != null) { appService2.a().execute(); return; } else { e.a.a.a.a("appService2"); throw …; } } e.a.a.a.a("appService"); throw …; } } -
public final class MainActivity extends m { public AppService o;
public AppService2 p; public void onCreate(Bundle bundle) { super.onCreate(bundle); setContentView((int) R.layout.activity_main); Object a = new AppModule1().a(); a.a(a, "Cannot return null from a non-@Nullable @Provides method"); this.o = a; this.p = AppModule2_ProvideService2Factory.a(); AppService appService = this.o; if (appService != null) { appService.a().execute(); AppService2 appService2 = this.p; if (appService2 != null) { appService2.a().execute(); return; } else { e.a.a.a.a("appService2"); throw …; } } e.a.a.a.a("appService"); throw …; } } AppComponent͕ফ͑ͨ!! AppComponentͷ֤ϝιου͕ inlineԽ͞ΕɺऔΓআ͔Εͨɻ -
ࣗݾհ • ࠤ౻ ൏/͞ͱ͏ ͠ΎΜ • ϚονϯάΤʔδΣϯτɺCyberAgent, inc. ॴଐ •
@stsn_jp • github.com/satoshun