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 Android Modules #2

Merged
merged 21 commits into from
Jul 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ jobs:
java-version: '21'

- name: Build kinject
run: ./gradlew :kinject:build
run: ./gradlew :build
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,20 @@ You can find all the posts [here](https://scottpierce.dev/categories/making-a-ko

A multiplatform Dependency Injection library.

## Artifacts

| Artifact | Description |
|----------------------------|------------------------------------------------------------------------------------------------------------------------------------------------|
| kinject-core | Provides core DI functionality. |
| kinject-android | Provides helper methods for working with `ObjectGraph`s embedded in `Context`s, and helper classes for embedding `ObjectGraph`s in `Contexts`. |
| kinject-android-appcompat | Provides `KinjectAppCompatActivity`. |
| kinject-android-compose | Provides `KinjectComponentActivity`. |
| kinject-compose | Provides the ability to provide an ObjectGraph in a Compose hierarchy. |
| kinject-compose-viewmodel | Provides the ability to get a ViewModel in a compose hierarchy. |
| kinject-coroutines | Provides a `KinjectCoroutineContextElement`, to easily allow passing an `ObjectGraph` via a `CoroutineContext`.
| kinject-viewmodel | Provides the ability to declare a view model dependency, and a factory to create it. |


## Usage

```kotlin
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,14 @@ plugins {

android {
namespace = "dev.scottpierce.kinject.benchmark"
compileSdk = 34

compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}

kotlinOptions {
jvmTarget = "1.8"
}

defaultConfig {
minSdk = 24
targetSdk = 34

testInstrumentationRunner = "androidx.benchmark.junit4.AndroidBenchmarkRunner"

// TODO remove this after writing the benchmark is done
testInstrumentationRunnerArguments["androidx.benchmark.suppressErrors"] = "EMULATOR,LOW-BATTERY"
}

testBuildType = "release"
buildTypes {
debug {
// Since isDebuggable can"t be modified by gradle for library modules,
// Since isDebuggable can't be modified by gradle for library modules,
// it must be done in a manifest - see src/androidTest/AndroidManifest.xml
isMinifyEnabled = true
proguardFiles(
Expand All @@ -45,7 +28,7 @@ android {
}

dependencies {
androidTestImplementation(project(":benchmark-shared"))
androidTestImplementation(project(":benchmark:benchmark-shared"))

androidTestImplementation(libs.androidx.runner)
androidTestImplementation(libs.androidx.junit)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ kotlin {

sourceSets {
commonMain.dependencies {
implementation(project(":benchmark-shared"))
implementation(project(":benchmark:benchmark-shared"))
implementation(libs.kotlinx.benchmark)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,15 @@ plugins {
}

kotlin {
jvm {
compilations.all {
kotlinOptions {
jvmTarget = "1.8"
}
}
}
jvm()
macosArm64()
js {
nodejs()
}

sourceSets {
commonMain.dependencies {
api(project(":kinject"))
api(project(":kinject-core"))
api(libs.koin.core)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -312,5 +312,5 @@ class AllDependencies(
val wwww: WWWW,
val xxxx: XXXX,
val yyyy: YYYY,
val zzzz: ZZZZ
val zzzz: ZZZZ,
)
Original file line number Diff line number Diff line change
Expand Up @@ -385,11 +385,10 @@ class LargeExample(
get(), get(), get(), get(), get(), get(), get(), get(), get(),
)
}
}
},
)
}
return koinApp.koin
}
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ package kinject.benchmark
import kinject.ObjectGraph
import kinject.objectGraph
import org.koin.core.Koin
import org.koin.core.context.startKoin
import org.koin.core.module.dsl.singleOf
import org.koin.dsl.koinApplication
import org.koin.dsl.module

Expand Down Expand Up @@ -40,7 +38,7 @@ class SmallExample(
single { D(get(), get(), get()) }
single { E(get()) }
single { SmallExample(get(), get(), get(), get(), get()) }
}
},
)
}
return koinApp.koin
Expand Down
132 changes: 131 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,15 +1,145 @@
import com.android.build.api.dsl.ApplicationExtension
import com.android.build.gradle.LibraryExtension
import com.android.build.gradle.TestExtension
import com.vanniktech.maven.publish.SonatypeHost
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
import org.jetbrains.kotlin.gradle.dsl.KotlinTopLevelExtension
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
alias(libs.plugins.kotlin.multiplatform) apply false
alias(libs.plugins.kotlin.android) apply false
alias(libs.plugins.kotlin.compose) apply false
alias(libs.plugins.gradleMavenPublish) apply false
alias(libs.plugins.android.application) apply false
alias(libs.plugins.kotlin.android) apply false
alias(libs.plugins.android.library) apply false
alias(libs.plugins.androidx.benchmark) apply false
}

apply(rootProject.file("gradle/ktlint.gradle.kts"))

object AndroidConfig {
const val compileSdkVersion = 34
const val targetSdkVersion = 34
const val minSdkVersion = 23
const val composeCompilerVersion = "1.5.14"
}

val javaVersion = JavaVersion.VERSION_1_8
val javaVersionInt = javaVersion.ordinal + 1
val jvmTarget = JvmTarget.JVM_1_8

val ref = System.getenv()["GITHUB_REF"]
val releaseVersion: String? = if (
System.getenv()["GITHUB_REF_TYPE"] == "tag" &&
ref?.startsWith("refs/tags/v") == true
) {
ref.removePrefix("refs/tags/v")
.also { println("Releasing Version: $it") }
} else {
null
}

subprojects {
group = "dev.scottpierce"
version = "0.1.0"

plugins.withId("com.android.application") {
configure<ApplicationExtension> {
compileOptions {
sourceCompatibility = javaVersion
targetCompatibility = javaVersion
}

compileSdk = AndroidConfig.compileSdkVersion

defaultConfig {
minSdk = AndroidConfig.minSdkVersion
targetSdk = AndroidConfig.targetSdkVersion
}
}
}

plugins.withId("com.android.library") {
configure<LibraryExtension> {
compileOptions {
sourceCompatibility = javaVersion
targetCompatibility = javaVersion
}

compileSdk = AndroidConfig.compileSdkVersion

defaultConfig {
minSdk = AndroidConfig.minSdkVersion
}
}
}

plugins.withId("com.android.test") {
configure<TestExtension> {
compileOptions {
sourceCompatibility = javaVersion
targetCompatibility = javaVersion
}

compileSdk = AndroidConfig.compileSdkVersion

defaultConfig {
minSdk = AndroidConfig.minSdkVersion
targetSdk = AndroidConfig.targetSdkVersion
}
}
}

tasks.withType<KotlinCompile> {
compilerOptions.jvmTarget.set(jvmTarget)
}

plugins.withId("org.jetbrains.kotlin.jvm") {
configure<KotlinTopLevelExtension> {
jvmToolchain(javaVersionInt)
}
}

if (releaseVersion != null) {
plugins.withId("com.vanniktech.maven.publish") {
configure<com.vanniktech.maven.publish.MavenPublishBaseExtension> {
publishToMavenCentral(SonatypeHost.CENTRAL_PORTAL, automaticRelease = true)

signAllPublications()

coordinates(
groupId = "dev.scottpierce",
artifactId = project.name,
version = releaseVersion,
)

pom {
name.set("Kinject")
description.set("A simple Kotlin Multiplatform dependency injection library.")
inceptionYear.set("2024")
url.set("https://github.com/ScottPierce/kinject")
licenses {
license {
name.set("The Apache License, Version 2.0")
url.set("http://www.apache.org/licenses/LICENSE-2.0.txt")
distribution.set("http://www.apache.org/licenses/LICENSE-2.0.txt")
}
}
developers {
developer {
id.set("ScottPierce")
name.set("Scott Pierce")
url.set("https://github.com/ScottPierce")
}
}
scm {
url.set("https://github.com/ScottPierce/kinject")
connection.set("scm:git:git://github.com/ScottPierce/kinject.git")
developerConnection.set("scm:git:ssh://[email protected]/ScottPierce/kinject.git")
}
}
}
}
}
}
2 changes: 2 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
org.gradle.jvmargs=-Xmx3g -Dfile.encoding=UTF-8 -Dkotlin.daemon.jvm.options\="-Xmx2g"

kotlin.code.style=official
kotlin.mpp.androidGradlePluginCompatibility.nowarn=true
kotlin.apple.xcodeCompatibility.nowarn=true

android.useAndroidX=true
2 changes: 1 addition & 1 deletion gradle/ktlint.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ dependencies {
}
}

val outputDir = "${project.buildDir}/reports/ktlint/"
val outputDir = "${project.layout.buildDirectory}/reports/ktlint/"
val inputFiles = project.fileTree(mapOf("dir" to "src", "include" to "**/*.kt"))

val commonArgs = listOf("**/src/**/*.kt", "!**/src/**/generated/**", "!**/build/**")
Expand Down
46 changes: 38 additions & 8 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,28 +1,58 @@
[versions]
agp = "8.5.0"
compose = "1.6.8"
junit = "4.13.2"
kotlin = "2.0.0"
kotlinx-coroutines = "1.8.1"
kotlinxBenchmark = "0.4.10"

agp = "8.2.0"
junit = "4.13.2"
junitVersion = "1.1.5"
androidx-benchmark = "1.2.4"
runner = "1.5.2"
runner = "1.6.1"
benchmarkJunit4 = "1.2.4"
androidx-lifecycle = "2.8.3"
compose-bom = "2024.06.00"
compose-compiler = "1.5.14"
coreKtx = "1.13.1"
espressoCore = "3.6.1"
lifecycleRuntimeKtx = "2.8.3"
activityCompose = "1.9.0"
appcompat = "1.7.0"
jetbrains-androidx-lifecycle = "2.8.0"

[libraries]
androidx-appcompat = { group = "androidx.appcompat", name = "appcompat", version.ref = "appcompat" }
androidx-benchmark-junit4 = { group = "androidx.benchmark", name = "benchmark-junit4", version.ref = "benchmarkJunit4" }
androidx-junit = { group = "androidx.test.ext", name = "junit", version.ref = "junitVersion" }
androidx-junit = { group = "androidx.test.ext", name = "junit", version = "1.2.1" }
androidx-runner = { group = "androidx.test", name = "runner", version.ref = "runner" }
compose-bom = { group = "androidx.compose", name = "compose-bom", version = "2024.06.00" }
compose-runtime = { group = "androidx.compose.runtime", name = "runtime", version.ref = "compose" }
junit = { group = "junit", name = "junit", version.ref = "junit" }
koin-core = { module = "io.insert-koin:koin-core", version = "3.2.0" }
koin-core = { module = "io.insert-koin:koin-core", version = "3.5.6" }
kotlinx-benchmark = { module = "org.jetbrains.kotlinx:kotlinx-benchmark-runtime", version.ref = "kotlinxBenchmark" }
kotlinx-coroutines-core = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-core", version.ref = "kotlinx-coroutines" }
androidx-lifecycle-viewmodel = { module = "androidx.lifecycle:lifecycle-viewmodel", version.ref = "androidx-lifecycle" }
androidx-lifecycle-viewmodel-compose = { module = "androidx.lifecycle:lifecycle-viewmodel-compose", version.ref = "androidx-lifecycle" }
jetbrains-androidx-lifecycle-viewmodel = { module = "org.jetbrains.androidx.lifecycle:lifecycle-viewmodel", version.ref = "jetbrains-androidx-lifecycle" }
jetbrains-androidx-lifecycle-viewmodel-compose = { module = "org.jetbrains.androidx.lifecycle:lifecycle-viewmodel-compose", version.ref = "jetbrains-androidx-lifecycle" }

androidx-core-ktx = { group = "androidx.core", name = "core-ktx", version.ref = "coreKtx" }
androidx-espresso-core = { group = "androidx.test.espresso", name = "espresso-core", version.ref = "espressoCore" }
androidx-lifecycle-runtime-ktx = { group = "androidx.lifecycle", name = "lifecycle-runtime-ktx", version.ref = "lifecycleRuntimeKtx" }
androidx-activity-compose = { group = "androidx.activity", name = "activity-compose", version.ref = "activityCompose" }
androidx-ui = { group = "androidx.compose.ui", name = "ui" }
androidx-ui-graphics = { group = "androidx.compose.ui", name = "ui-graphics" }
androidx-ui-tooling = { group = "androidx.compose.ui", name = "ui-tooling" }
androidx-ui-tooling-preview = { group = "androidx.compose.ui", name = "ui-tooling-preview" }
androidx-ui-test-manifest = { group = "androidx.compose.ui", name = "ui-test-manifest" }
androidx-ui-test-junit4 = { group = "androidx.compose.ui", name = "ui-test-junit4" }
androidx-material3 = { group = "androidx.compose.material3", name = "material3" }

[plugins]
android-application = { id = "com.android.application", version.ref = "agp" }
android-library = { id = "com.android.library", version.ref = "agp" }
androidx-benchmark = { id = "androidx.benchmark", version.ref = "androidx-benchmark" }
kotlin-allOpen = { id = "org.jetbrains.kotlin.plugin.allopen", version.ref = "kotlin" }
kotlin-android = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" }
kotlin-compose = { id = "org.jetbrains.kotlin.plugin.compose", version.ref = "kotlin" }
kotlin-multiplatform = { id = "org.jetbrains.kotlin.multiplatform", version.ref = "kotlin" }
kotlinx-benchmark = { id = "org.jetbrains.kotlinx.benchmark", version.ref = "kotlinxBenchmark" }
gradleMavenPublish = { id = "com.vanniktech.maven.publish", version = "0.28.0" }
gradleMavenPublish = { id = "com.vanniktech.maven.publish", version = "0.29.0" }
14 changes: 14 additions & 0 deletions kinject-android-appcompat/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
plugins {
alias(libs.plugins.android.library)
alias(libs.plugins.kotlin.android)
alias(libs.plugins.gradleMavenPublish)
}

android {
namespace = "kinject.android.appcompat"
}

dependencies {
api(project(":kinject-android"))
implementation(libs.androidx.appcompat)
}
Loading