-
-
Notifications
You must be signed in to change notification settings - Fork 719
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add onKoinStartup function to help start with AndroidX startup
- Loading branch information
1 parent
673e956
commit e0adb2e
Showing
14 changed files
with
240 additions
and
43 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
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,14 +1,11 @@ | ||
import org.junit.Test | ||
import org.koin.android.test.verify.androidVerify | ||
import org.koin.android.test.verify.verify | ||
import org.koin.sample.sandbox.di.allModules | ||
import org.koin.sample.sandbox.di.appModule | ||
import org.koin.sample.sandbox.di.mvpModule | ||
|
||
class CheckModulesTest { | ||
|
||
@Test | ||
fun `Verify Configuration`() { | ||
allModules.value.androidVerify() | ||
allModules.androidVerify() | ||
} | ||
} |
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,48 @@ | ||
import org.jetbrains.kotlin.gradle.dsl.JvmTarget | ||
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile | ||
|
||
plugins { | ||
alias(libs.plugins.androidLibrary) | ||
alias(libs.plugins.kotlinAndroid) | ||
} | ||
|
||
val androidCompileSDK : String by project | ||
val androidMinSDK : String by project | ||
|
||
android { | ||
namespace = "org.koin.androidx.startup" | ||
compileSdk = androidCompileSDK.toInt() | ||
defaultConfig { | ||
minSdk = androidMinSDK.toInt() | ||
} | ||
buildFeatures { | ||
buildConfig = false | ||
} | ||
compileOptions { | ||
sourceCompatibility = JavaVersion.VERSION_1_8 | ||
targetCompatibility = JavaVersion.VERSION_1_8 | ||
} | ||
} | ||
|
||
tasks.withType<KotlinCompile>().all { | ||
compilerOptions { | ||
jvmTarget.set(JvmTarget.JVM_1_8) | ||
} | ||
} | ||
|
||
dependencies { | ||
api(project(":android:koin-android")) | ||
api(libs.androidx.workmanager) | ||
|
||
// Test | ||
testImplementation(libs.test.junit) | ||
testImplementation(libs.test.mockito) | ||
} | ||
|
||
// android sources | ||
val sourcesJar: TaskProvider<Jar> by tasks.registering(Jar::class) { | ||
archiveClassifier.set("sources") | ||
from(android.sourceSets.map { it.java.srcDirs }) | ||
} | ||
|
||
apply(from = file("../../gradle/publish-android.gradle.kts")) |
15 changes: 15 additions & 0 deletions
15
projects/android/koin-androidx-startup/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,15 @@ | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="org.koin.androidx.startup" xmlns:tools="http://schemas.android.com/tools"> | ||
<application> | ||
<provider | ||
android:name="androidx.startup.InitializationProvider" | ||
android:authorities="${applicationId}.androidx-startup" | ||
android:exported="false" | ||
tools:node="merge"> | ||
<!-- This entry makes ExampleLoggerInitializer discoverable. --> | ||
<meta-data android:name="org.koin.androix.startup.KoinInitializer" | ||
android:value="androidx.startup" /> | ||
</provider> | ||
</application> | ||
|
||
</manifest> |
41 changes: 41 additions & 0 deletions
41
...s/android/koin-androidx-startup/src/main/java/org/koin/androix/startup/KoinInitializer.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,41 @@ | ||
/* | ||
* Copyright 2017-present the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.koin.androix.startup | ||
|
||
import android.content.Context | ||
import androidx.startup.Initializer | ||
import org.koin.core.Koin | ||
import org.koin.core.annotation.KoinExperimentalAPI | ||
import org.koin.core.context.startKoin | ||
|
||
/** | ||
* KoinInitializer handle Initializer for Koin startup process | ||
* | ||
* @author Arnaud Giuliani | ||
*/ | ||
class KoinInitializer : Initializer<Koin> { | ||
|
||
@OptIn(KoinExperimentalAPI::class) | ||
override fun create(context: Context): Koin { | ||
return KoinStartup.koinAppDeclaration?.let { | ||
startKoin(it).koin | ||
} ?: error("KoinInitializer can't start Koin configuration. Please use KoinStartup.onKoinStartup() function to register your Koin application.") | ||
} | ||
|
||
override fun dependencies(): List<Class<out Initializer<*>>> { | ||
return emptyList() | ||
} | ||
} |
Oops, something went wrong.