Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add "Min API" setting #69

Merged
merged 1 commit into from
Sep 3, 2024

Conversation

EpicDima
Copy link
Contributor

@EpicDima EpicDima commented Sep 3, 2024

Changing min API can be useful when working with R8, when it changes the code for older APIs.

Example:

import java. lang. Thread
import android.os.Looper

fun test3() {
    Looper.getMainLooper().isCurrentThread()
}

DEX with min API 21 (R8 enabled):

class KotlinExplorerKt$$ExternalSyntheticApiModelOutline0
    void KotlinExplorerKt$$ExternalSyntheticApiModelOutline0.m(android.os.Looper)
        -- 2 instructions
        0000: invoke-virtual {v0}, Landroid/os/Looper;.isCurrentThread:()Z // method@0003
        0003: return-void

class KotlinExplorerKt
    void KotlinExplorerKt.test3()
        -- 4 instructions
        0000: invoke-static {}, Landroid/os/Looper;.getMainLooper:()Landroid/os/Looper; // method@0002
        0003: move-result-object v0
        0004: invoke-static {v0}, LKotlinExplorerKt$$ExternalSyntheticApiModelOutline0;.m:(Landroid/os/Looper;)V // method@0000
        0007: return-void

DEX with min API 26 (R8 enabled):

class KotlinExplorerKt
    void KotlinExplorerKt.test3()
        -- 4 instructions
        0000: invoke-static {}, Landroid/os/Looper;.getMainLooper:()Landroid/os/Looper; // method@0001
        0003: move-result-object v0
        0004: invoke-virtual {v0}, Landroid/os/Looper;.isCurrentThread:()Z // method@0002
        0007: return-void

Changing min API can be useful when working with R8, when it changes the code for older APIs.

Example:
```kotlin
import java. lang. Thread
import android.os.Looper

fun test3() {
    Looper.getMainLooper().isCurrentThread()
}
```

DEX with min API 21 (R8 enabled):
```dex
class KotlinExplorerKt$$ExternalSyntheticApiModelOutline0
    void KotlinExplorerKt$$ExternalSyntheticApiModelOutline0.m(android.os.Looper)
        -- 2 instructions
        0000: invoke-virtual {v0}, Landroid/os/Looper;.isCurrentThread:()Z // method@0003
        0003: return-void

class KotlinExplorerKt
    void KotlinExplorerKt.test3()
        -- 4 instructions
        0000: invoke-static {}, Landroid/os/Looper;.getMainLooper:()Landroid/os/Looper; // method@0002
        0003: move-result-object v0
        0004: invoke-static {v0}, LKotlinExplorerKt$$ExternalSyntheticApiModelOutline0;.m:(Landroid/os/Looper;)V // method@0000
        0007: return-void
```

DEX with min API 26 (R8 enabled):
```dex
class KotlinExplorerKt
    void KotlinExplorerKt.test3()
        -- 4 instructions
        0000: invoke-static {}, Landroid/os/Looper;.getMainLooper:()Landroid/os/Looper; // method@0001
        0003: move-result-object v0
        0004: invoke-virtual {v0}, Landroid/os/Looper;.isCurrentThread:()Z // method@0002
        0007: return-void
```
@romainguy romainguy merged commit b6734a8 into romainguy:main Sep 3, 2024
1 check passed
@romainguy
Copy link
Owner

Thanks! This is something I've been meaning to add, glad you beat me to it :)

@EpicDima EpicDima deleted the epicdima/min_api_setting branch September 14, 2024 23:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants