mirror of
https://github.com/sudoxnym/habitica-android.git
synced 2026-07-13 01:38:21 +00:00
Add shared kotlin multiplatform library
This commit is contained in:
parent
109c3f06fd
commit
56fab73305
8 changed files with 188 additions and 0 deletions
|
|
@ -134,6 +134,8 @@ dependencies {
|
|||
implementation 'android.arch.navigation:navigation-fragment-ktx:1.0.0'
|
||||
implementation 'android.arch.navigation:navigation-ui-ktx:1.0.0'
|
||||
implementation 'com.plattysoft.leonids:LeonidsLib:1.3.2'
|
||||
|
||||
implementation project(':shared')
|
||||
}
|
||||
|
||||
android {
|
||||
|
|
|
|||
|
|
@ -1 +1,2 @@
|
|||
include ':shared'
|
||||
include 'Habitica', ':Habitica', ':seeds-sdk'
|
||||
1
shared/.gitignore
vendored
Normal file
1
shared/.gitignore
vendored
Normal file
|
|
@ -0,0 +1 @@
|
|||
/build
|
||||
89
shared/build.gradle
Normal file
89
shared/build.gradle
Normal file
|
|
@ -0,0 +1,89 @@
|
|||
apply plugin: 'com.android.library'
|
||||
apply plugin: 'kotlin-multiplatform'
|
||||
apply plugin: 'kotlin-kapt'
|
||||
|
||||
android {
|
||||
compileSdkVersion 28
|
||||
|
||||
defaultConfig {
|
||||
|
||||
minSdkVersion 21
|
||||
targetSdkVersion 28
|
||||
versionCode 1
|
||||
versionName "1.0"
|
||||
}
|
||||
buildTypes {
|
||||
release {
|
||||
}
|
||||
}
|
||||
sourceSets{
|
||||
main.java.srcDirs += 'src/androidMain/kotlin'
|
||||
}
|
||||
compileOptions {
|
||||
targetCompatibility = '1.8'
|
||||
}
|
||||
}
|
||||
|
||||
kotlin {
|
||||
targets {
|
||||
final def iOSTarget = System.getenv('SDK_NAME')?.startsWith("iphoneos") \
|
||||
? presets.iosArm64 : presets.iosX64
|
||||
|
||||
fromPreset(iOSTarget, 'ios') {
|
||||
binaries {
|
||||
framework('shared')
|
||||
}
|
||||
}
|
||||
|
||||
android()
|
||||
}
|
||||
|
||||
sourceSets {
|
||||
commonMain.dependencies {
|
||||
api 'org.jetbrains.kotlin:kotlin-stdlib-common'
|
||||
}
|
||||
|
||||
commonMain.kotlin.srcDirs += 'src/commonMain/kotlin'
|
||||
|
||||
androidMain.dependencies {
|
||||
api 'org.jetbrains.kotlin:kotlin-stdlib'
|
||||
}
|
||||
|
||||
iosMain.dependencies {
|
||||
implementation "com.squareup.sqldelight:ios-driver:1.1.3"
|
||||
}
|
||||
|
||||
iosMain.kotlin.srcDirs += 'src/iosMain/kotlin'
|
||||
}
|
||||
}
|
||||
|
||||
// workaround for https://youtrack.jetbrains.com/issue/KT-27170
|
||||
configurations {
|
||||
compileClasspath
|
||||
}
|
||||
|
||||
task packForXCode(type: Sync) {
|
||||
final File frameworkDir = new File(buildDir, "xcode-frameworks")
|
||||
final String mode = project.findProperty("XCODE_CONFIGURATION")?.toUpperCase() ?: 'DEBUG'
|
||||
final def framework = kotlin.targets.ios.binaries.getFramework("shared", mode)
|
||||
|
||||
inputs.property "mode", mode
|
||||
dependsOn framework.linkTask
|
||||
|
||||
from { framework.outputFile.parentFile }
|
||||
into frameworkDir
|
||||
|
||||
doLast {
|
||||
new File(frameworkDir, 'gradlew').with {
|
||||
text = "#!/bin/bash\nexport 'JAVA_HOME=${System.getProperty("java.home")}'\ncd '${rootProject.rootDir}'\n./gradlew \$@\n"
|
||||
setExecutable(true)
|
||||
}
|
||||
}
|
||||
}
|
||||
tasks.build.dependsOn packForXCode
|
||||
|
||||
tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).all {
|
||||
kotlinOptions {
|
||||
jvmTarget = "1.8"
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
package com.habitrpg.shared.habitica
|
||||
|
||||
import android.util.Log
|
||||
import space.thelen.shared.cluetective.BuildConfig
|
||||
|
||||
actual class PlatformLogger actual constructor() {
|
||||
actual val enabled: Boolean
|
||||
get() = BuildConfig.DEBUG
|
||||
|
||||
actual fun logDebug(tag: String, message: String) {
|
||||
Log.d(tag, message)
|
||||
}
|
||||
|
||||
actual fun logInfo(tag: String, message: String) {
|
||||
Log.i(tag, message)
|
||||
}
|
||||
|
||||
actual fun logError(tag: String, message: String) {
|
||||
Log.e(tag, message)
|
||||
}
|
||||
|
||||
actual fun logError(tag: String, message: String, exception: Throwable) {
|
||||
Log.e(tag, message, exception)
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,42 @@
|
|||
package com.habitrpg.shared.habitica
|
||||
|
||||
expect class PlatformLogger() {
|
||||
val enabled: Boolean
|
||||
|
||||
fun logDebug(tag: String, message: String)
|
||||
fun logInfo(tag: String, message: String)
|
||||
fun logError(tag: String, message: String)
|
||||
fun logError(tag: String, message: String, exception: Throwable)
|
||||
}
|
||||
|
||||
enum class LogLevel {
|
||||
ERROR, INFO, DEBUG
|
||||
}
|
||||
|
||||
class Logger {
|
||||
|
||||
companion object {
|
||||
private val platformLogger = PlatformLogger()
|
||||
|
||||
val enabled
|
||||
get() = platformLogger.enabled
|
||||
|
||||
fun log(level: LogLevel, tag: String, message: String) {
|
||||
if (!enabled) return
|
||||
when (level) {
|
||||
LogLevel.ERROR -> platformLogger.logError(tag, message)
|
||||
LogLevel.INFO -> platformLogger.logInfo(tag, message)
|
||||
LogLevel.DEBUG -> platformLogger.logDebug(tag, message)
|
||||
}
|
||||
}
|
||||
|
||||
fun logException(tag: String, message: String, exception: Throwable? = null) {
|
||||
if (!enabled) return
|
||||
exception?.let {
|
||||
platformLogger.logError(tag, message, exception)
|
||||
} ?: run {
|
||||
platformLogger.logError(tag, message)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
package com.habitrpg.shared.habitica
|
||||
|
||||
actual class PlatformLogger actual constructor() {
|
||||
actual val enabled: Boolean
|
||||
get() = true
|
||||
|
||||
actual fun logDebug(tag: String, message: String) {
|
||||
println("[DEBUG] $tag: $message")
|
||||
}
|
||||
|
||||
actual fun logInfo(tag: String, message: String) {
|
||||
println("[INFO] $tag: $message")
|
||||
}
|
||||
|
||||
actual fun logError(tag: String, message: String) {
|
||||
println("[ERROR] $tag: $message")
|
||||
}
|
||||
|
||||
actual fun logError(tag: String, message: String, exception: Throwable) {
|
||||
println("[ERROR] $tag: $message\n${exception.getStackTrace().joinToString("\n")}")
|
||||
}
|
||||
}
|
||||
5
shared/src/main/AndroidManifest.xml
Normal file
5
shared/src/main/AndroidManifest.xml
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="space.thelen.shared.cluetective">
|
||||
|
||||
</manifest>
|
||||
Loading…
Reference in a new issue