-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added a new KMP module named "shared" to the project. This module includes: - Support for Android and iOS platforms. - A function `createCrashInKMPModule` in the Android source set that triggers a crash. - Basic unit tests for both Android and common source sets. This change also involved updating the app module to trigger the crash from the KMP module and upgrading Gradle to version 8. 10.2.
- Loading branch information
1 parent
0210a78
commit 5377ef0
Showing
15 changed files
with
200 additions
and
7 deletions.
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
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
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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
#Fri Oct 27 14:35:03 PDT 2023 | ||
distributionBase=GRADLE_USER_HOME | ||
distributionPath=wrapper/dists | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.2-bin.zip | ||
zipStoreBase=GRADLE_USER_HOME | ||
zipStorePath=wrapper/dists |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
plugins { | ||
id("org.jetbrains.kotlin.multiplatform") | ||
id("com.android.kotlin.multiplatform.library") | ||
} | ||
|
||
kotlin { | ||
|
||
// Target declarations - add or remove as needed below. These define | ||
// which platforms this KMP module supports. | ||
// See: https://kotlinlang.org/docs/multiplatform-discover-project.html#targets | ||
androidLibrary { | ||
namespace = "com.google.play.dynamic.filters.opted.shared" | ||
compileSdk = 34 | ||
minSdk = 24 | ||
|
||
withAndroidTestOnJvmBuilder { | ||
compilationName = "unitTest" | ||
defaultSourceSetName = "androidUnitTest" | ||
} | ||
|
||
withAndroidTestOnDeviceBuilder { | ||
compilationName = "instrumentedTest" | ||
defaultSourceSetName = "androidInstrumentedTest" | ||
sourceSetTreeName = "test" | ||
}.configure { | ||
instrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" | ||
} | ||
} | ||
|
||
// For iOS targets, this is also where you should | ||
// configure native binary output. For more information, see: | ||
// https://kotlinlang.org/docs/multiplatform-build-native-binaries.html#build-xcframeworks | ||
|
||
// A step-by-step guide on how to include this library in an XCode | ||
// project can be found here: | ||
// https://developer.android.com/kotlin/multiplatform/migrate | ||
val xcfName = "shared" | ||
|
||
iosX64 { | ||
binaries.framework { | ||
baseName = xcfName | ||
} | ||
} | ||
|
||
iosArm64 { | ||
binaries.framework { | ||
baseName = xcfName | ||
} | ||
} | ||
|
||
iosSimulatorArm64 { | ||
binaries.framework { | ||
baseName = xcfName | ||
} | ||
} | ||
|
||
// Source set declarations. | ||
// Declaring a target automatically creates a source set with the same name. By default, the | ||
// Kotlin Gradle Plugin creates additional source sets that depend on each other, since it is | ||
// common to share sources between related targets. | ||
// See: https://kotlinlang.org/docs/multiplatform-hierarchy.html | ||
sourceSets { | ||
commonMain { | ||
dependencies { | ||
implementation("org.jetbrains.kotlin:kotlin-stdlib:2.0.20") | ||
// Add KMP dependencies here | ||
} | ||
} | ||
|
||
commonTest { | ||
dependencies { | ||
implementation("org.jetbrains.kotlin:kotlin-test:2.0.0") | ||
} | ||
} | ||
|
||
androidMain { | ||
dependencies { | ||
// Add Android-specific dependencies here. Note that this source set depends on | ||
// commonMain by default and will correctly pull the Android artifacts of any KMP | ||
// dependencies declared in commonMain. | ||
} | ||
} | ||
|
||
getByName("androidInstrumentedTest") { | ||
dependencies { | ||
implementation("androidx.test:runner:1.6.2") | ||
implementation("androidx.test:core:1.6.1") | ||
implementation("androidx.test.ext:junit:1.2.1") | ||
} | ||
} | ||
|
||
iosMain { | ||
dependencies { | ||
// Add iOS-specific dependencies here. This a source set created by Kotlin Gradle | ||
// Plugin (KGP) that each specific iOS target (e.g., iosX64) depends on as | ||
// part of KMP’s default source set hierarchy. Note that this source set depends | ||
// on common by default and will correctly pull the iOS artifacts of any | ||
// KMP dependencies declared in commonMain. | ||
} | ||
} | ||
} | ||
|
||
} |
27 changes: 27 additions & 0 deletions
27
...mentedTest/kotlin/com/google/play/dynamic/filters/opted/shared/ExampleInstrumentedTest.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,27 @@ | ||
package com.google.play.dynamic.filters.opted.shared | ||
|
||
import androidx.test.platform.app.InstrumentationRegistry | ||
import androidx.test.ext.junit.runners.AndroidJUnit4 | ||
|
||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
|
||
import org.junit.Assert.* | ||
|
||
/** | ||
* Instrumented test, which will execute on an Android device. | ||
* | ||
* See [testing documentation](http://d.android.com/tools/testing). | ||
*/ | ||
@RunWith(AndroidJUnit4::class) | ||
class ExampleInstrumentedTest { | ||
@Test | ||
fun useAppContext() { | ||
// Context of the app under test. | ||
val appContext = InstrumentationRegistry.getInstrumentation().targetContext | ||
assertEquals( | ||
"com.google.play.dynamic.filters.opted.shared.test", | ||
appContext.packageName | ||
) | ||
} | ||
} |
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,4 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"> | ||
|
||
</manifest> |
9 changes: 9 additions & 0 deletions
9
...d/src/androidMain/kotlin/com/google/play/dynamic/filters/opted/shared/Platform.android.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,9 @@ | ||
package com.google.play.dynamic.filters.opted.shared | ||
|
||
actual fun platform() = "Android" | ||
|
||
fun createCrashInKMPModule() | ||
{ | ||
val name="test" | ||
val c=name.get(10) | ||
} |
16 changes: 16 additions & 0 deletions
16
...rc/androidUnitTest/kotlin/com/google/play/dynamic/filters/opted/shared/ExampleUnitTest.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,16 @@ | ||
package com.google.play.dynamic.filters.opted.shared | ||
|
||
import kotlin.test.Test | ||
import kotlin.test.assertEquals | ||
|
||
/** | ||
* Example local unit test, which will execute on the development machine (host). | ||
* | ||
* See [testing documentation](http://d.android.com/tools/testing). | ||
*/ | ||
class ExampleUnitTest { | ||
@Test | ||
fun addition_isCorrect() { | ||
assertEquals(4, 2 + 2) | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
shared/src/commonMain/kotlin/com/google/play/dynamic/filters/opted/shared/Platform.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,3 @@ | ||
package com.google.play.dynamic.filters.opted.shared | ||
|
||
expect fun platform(): String |
3 changes: 3 additions & 0 deletions
3
shared/src/iosMain/kotlin/com/google/play/dynamic/filters/opted/shared/Platform.ios.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,3 @@ | ||
package com.google.play.dynamic.filters.opted.shared | ||
|
||
actual fun platform() = "iOS" |