-
Notifications
You must be signed in to change notification settings - Fork 41
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
Implement support for Android target #250
Draft
kx412764776
wants to merge
31
commits into
Kotlin:master
Choose a base branch
from
kx412764776:android-support
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
31 commits
Select commit
Hold shift + click to select a range
dbd741a
Detect when an Android target is registered for benchmarking
kx412764776 0ce431e
Research android target support
kx412764776 a363453
Add androidTarget to runtime module
kx412764776 df8052b
Add gradle tasks to unpack aar file & retrieve annotation
kx412764776 517b694
Retrieve annotation data
kx412764776 4fe7b57
Retrieve annotation data
kx412764776 7a1b77a
refactor retrieve annotation data
kx412764776 dc9d1e4
Use 'ClassAnnotationsDescriptor' to store annotation data
kx412764776 9e198c7
update 'AnnotationProcessor' to process jar file
kx412764776 303577e
Generate androidTest file executable by Junit4
kx412764776 87dfd92
Add detect android device function
kx412764776 fcfd01c
Improve code generation for android target
kx412764776 d9c5e59
Add 'benchmarkRule' to call test
kx412764776 2594ede
modify 'AnnotationProcessor' processing annotation data
kx412764776 a56b4af
Add 'BenchmarkState' to call test
kx412764776 18cd7e9
Execute separate gradle task via shell command
kx412764776 8f772b2
Use retrieved iteration data to generate file for android target
kx412764776 742a0c2
Print test info from android logcat
kx412764776 7982b85
Filter print data in android target
kx412764776 dc5c404
Change the paths to the kotlin-qualification-task
88951b3
Add the template android project for generating benchmark sources into
a515f55
Generate benchmark sources into the template android project
f5aa4ba
Fix generate folders in android template project
kx412764776 ee5b8fb
Fix: Correctly store field annotations in FieldAnnotationsDescriptor
kx412764776 d9c9ab0
Map @Param annotation to androidx.benchmark
kx412764776 6209b53
Support users to set sdkDir for Android
kx412764776 f65b105
Fix 'Type mismatch' error
kx412764776 df57148
Add test for generate android project
kx412764776 53831cc
Bump Android Gradle Plugin version to 8.5.1 in all subprojects
3a42442
Set namespace for the android target
934e250
Modify the mapping of `warmup` data to androidx.benchmark
kx412764776 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
examples/kotlin-multiplatform/src/androidMain/kotlin/AndroidTestBenchmark.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package test | ||
|
||
import kotlinx.benchmark.* | ||
import kotlin.math.* | ||
|
||
@State(Scope.Benchmark) | ||
@Warmup(iterations = 3, time = 1, timeUnit = BenchmarkTimeUnit.SECONDS) | ||
@Measurement(iterations = 3, time = 1, timeUnit = BenchmarkTimeUnit.SECONDS) | ||
class AndroidTestBenchmark { | ||
private var data = 0.0 | ||
|
||
@Setup | ||
fun setUp() { | ||
data = 3.0 | ||
} | ||
|
||
@TearDown | ||
fun teardown() { | ||
// println("Teardown!") | ||
} | ||
|
||
@Benchmark | ||
fun sqrtBenchmark(): Double { | ||
return sqrt(data) | ||
} | ||
|
||
@Benchmark | ||
fun cosBenchmark(): Double { | ||
return cos(data) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
integration/src/main/kotlin/kotlinx/benchmark/integration/GradleTestVersion.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
integration/src/test/kotlin/kotlinx/benchmark/integration/AndroidProjectGeneratorTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package kotlinx.benchmark.integration | ||
|
||
import org.junit.Test | ||
import kotlin.test.assertTrue | ||
|
||
class AndroidProjectGeneratorTest: GradleTest() { | ||
private fun testAndroidProjectGeneration(setupBlock: Runner.() -> Unit, checkBlock: Runner.() -> Unit) { | ||
project("source-generation", print = true, gradleVersion = GradleTestVersion.v8_7).apply { | ||
setupBlock() | ||
runAndSucceed("androidReleaseBenchmarkGenerate") | ||
checkBlock() | ||
} | ||
} | ||
|
||
@Test | ||
fun generateAndroidFromResources() { | ||
testAndroidProjectGeneration( | ||
setupBlock = { | ||
runAndSucceed("setupReleaseAndroidProject") | ||
}, | ||
checkBlock = { | ||
generatedAndroidDir("android", "release", "") { generatedAndroidDir -> | ||
assertTrue(generatedAndroidDir.exists(), "Generated Android project does not exist") | ||
} | ||
} | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
plugin/main/resources/GeneratedAndroidProject/app/build.gradle.kts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
plugins { | ||
alias(libs.plugins.android.application) | ||
alias(libs.plugins.jetbrains.kotlin.android) | ||
} | ||
|
||
android { | ||
namespace = "kotlinx.benchmark.generatedandroidproject" | ||
compileSdk = 34 | ||
|
||
defaultConfig { | ||
applicationId = "kotlinx.benchmark.generatedandroidproject" | ||
minSdk = 26 | ||
targetSdk = 34 | ||
versionCode = 1 | ||
versionName = "1.0" | ||
|
||
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" | ||
} | ||
|
||
buildTypes { | ||
release { | ||
isMinifyEnabled = false | ||
proguardFiles( | ||
getDefaultProguardFile("proguard-android-optimize.txt"), | ||
"proguard-rules.pro" | ||
) | ||
} | ||
} | ||
compileOptions { | ||
sourceCompatibility = JavaVersion.VERSION_1_8 | ||
targetCompatibility = JavaVersion.VERSION_1_8 | ||
} | ||
kotlinOptions { | ||
jvmTarget = "1.8" | ||
} | ||
} | ||
|
||
dependencies { | ||
implementation(libs.androidx.core.ktx) | ||
implementation(libs.androidx.appcompat) | ||
implementation(libs.material) | ||
} |
21 changes: 21 additions & 0 deletions
21
plugin/main/resources/GeneratedAndroidProject/app/proguard-rules.pro
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Add project specific ProGuard rules here. | ||
# You can control the set of applied configuration files using the | ||
# proguardFiles setting in build.gradle. | ||
# | ||
# For more details, see | ||
# http://developer.android.com/guide/developing/tools/proguard.html | ||
|
||
# If your project uses WebView with JS, uncomment the following | ||
# and specify the fully qualified class name to the JavaScript interface | ||
# class: | ||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview { | ||
# public *; | ||
#} | ||
|
||
# Uncomment this to preserve the line number information for | ||
# debugging stack traces. | ||
#-keepattributes SourceFile,LineNumberTable | ||
|
||
# If you keep the line number information, uncomment this to | ||
# hide the original source file name. | ||
#-renamesourcefileattribute SourceFile |
16 changes: 16 additions & 0 deletions
16
plugin/main/resources/GeneratedAndroidProject/app/src/main/AndroidManifest.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:tools="http://schemas.android.com/tools"> | ||
|
||
<application | ||
android:allowBackup="true" | ||
android:dataExtractionRules="@xml/data_extraction_rules" | ||
android:fullBackupContent="@xml/backup_rules" | ||
android:icon="@mipmap/ic_launcher" | ||
android:label="@string/app_name" | ||
android:roundIcon="@mipmap/ic_launcher_round" | ||
android:supportsRtl="true" | ||
android:theme="@style/Theme.GeneratedAndroidProject" | ||
tools:targetApi="31" /> | ||
|
||
</manifest> |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
JFYI: when
implementation project(":kotlinx-benchmark-runtime")
is replaced with a dependency on actual artifact (for instance, published to a local maven repo),:compileReleaseKotlinAndroid
fails due to unresolvedkotlinx.benchnark
symbols:It does not make much sense to redefine a dependency for this sample project, but the same issue is also reproduced on
kotlinx-io
when I tried to apply kx-benchmark w/ android support.