Skip to content

Commit

Permalink
Publish core & koin to GitHub packages
Browse files Browse the repository at this point in the history
  • Loading branch information
vitoksmile committed Sep 1, 2023
1 parent 8acb240 commit 15fc908
Show file tree
Hide file tree
Showing 25 changed files with 388 additions and 59 deletions.
2 changes: 1 addition & 1 deletion LICENSE.txt
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@
same "printed page" as the copyright notice for easier
identification within third-party archives.

Copyright 2020-2021 JetBrains s.r.o. and and respective authors and developers.
Copyright 2023 Viktor Mykhailiv

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
61 changes: 60 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,63 @@ Note that for Android, the target phone **needs** to have ~~[Google Fit](https:/

## Data Types
- STEPS
- WEIGHT
- WEIGHT


# Using

You need an access token to install GitHub packages, see [Managing your personal access tokens](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/managing-your-personal-access-tokens).

local.properties
```
[email protected]
GITHUB_TOKEN=xxx
```

settings.gradle.kts:
```kotlin
dependencyResolutionManagement {
repositories {
maven {
url = uri("https://maven.pkg.github.com/vitoksmile/HealthKMP")
name = "GitHubPackages"
credentials {
val properties = java.util.Properties()
properties.load(file("local.properties").inputStream())
username = properties["GITHUB_USERNAME"].toString()
password = properties["GITHUB_TOKEN"].toString()
}
}
}
}
```

build.gradle:
```kotlin
sourceSets {
val commonMain by getting {
dependencies {
implementation("com.vitoksmile.health-kmp:core:0.0.1")
}
}
}
```

If you are using Koin, add to build.gradle:
```kotlin
implementation("com.vitoksmile.health-kmp:koin:0.0.1")
```


## 👷 Project Structure
* <kbd>core</kbd> - module with main source for the HealthKMP library
* <kbd>koin</kbd> - module with extensions for Koin

* <kbd>sample</kbd> - shared code for sample Compose project
* <kbd>androidApp</kbd> - sample Android projects that use HealthKMP
* <kbd>iosApp</kbd> - sample iOS projects that use HealthKMP


## 📜 License

This project is licensed under the Apache License, Version 2.0 - see the [LICENSE.md](https://github.com/Foso/Ktorfit/blob/master/LICENSE) file for details
7 changes: 5 additions & 2 deletions androidApp/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
@file:Suppress("UNUSED_VARIABLE")

plugins {
kotlin("multiplatform")
id("com.android.application")
Expand All @@ -9,8 +11,9 @@ kotlin {
sourceSets {
val androidMain by getting {
dependencies {
implementation(project(":core"))
implementation(project(":koin"))
implementation("com.vitoksmile.health-kmp:core:0.0.1")
implementation("com.vitoksmile.health-kmp:koin:0.0.1")
implementation(project(":sample"))
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
package com.vitoksmile.kmp.health

import MainView
import android.os.Bundle
import androidx.activity.compose.setContent
import androidx.appcompat.app.AppCompatActivity
import com.vitoksmile.kmp.health.sample.SampleApp

class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

setContent {
MainView()
SampleApp()
}
}
}
2 changes: 1 addition & 1 deletion androidApp/src/androidMain/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<resources>
<string name="app_name">HealthKMP</string>
<string name="app_name">Health</string>
</resources>
39 changes: 39 additions & 0 deletions core/HealthKMP.podspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
Pod::Spec.new do |spec|
spec.name = 'HealthKMP'
spec.version = '0.0.1'
spec.homepage = 'https://github.com/vitoksmile/HealthKMP'
spec.source = { :http=> ''}
spec.authors = ''
spec.license = ''
spec.summary = 'Wrapper for HealthKit on iOS and Google Fit and Health Connect on Android.'
spec.vendored_frameworks = 'build/cocoapods/framework/HealthKMP.framework'
spec.libraries = 'c++'
spec.ios.deployment_target = '14.1'


spec.pod_target_xcconfig = {
'KOTLIN_PROJECT_PATH' => ':core',
'PRODUCT_MODULE_NAME' => 'HealthKMP',
}

spec.script_phases = [
{
:name => 'Build HealthKMP',
:execution_position => :before_compile,
:shell_path => '/bin/sh',
:script => <<-SCRIPT
if [ "YES" = "$OVERRIDE_KOTLIN_BUILD_IDE_SUPPORTED" ]; then
echo "Skipping Gradle build task invocation due to OVERRIDE_KOTLIN_BUILD_IDE_SUPPORTED environment variable set to \"YES\""
exit 0
fi
set -ev
REPO_ROOT="$PODS_TARGET_SRCROOT"
"$REPO_ROOT/../gradlew" -p "$REPO_ROOT" $KOTLIN_PROJECT_PATH:syncFramework \
-Pkotlin.native.cocoapods.platform=$PLATFORM_NAME \
-Pkotlin.native.cocoapods.archs="$ARCHS" \
-Pkotlin.native.cocoapods.configuration="$CONFIGURATION"
SCRIPT
}
]

end
46 changes: 32 additions & 14 deletions core/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,14 +1,37 @@
@file:Suppress("UNUSED_VARIABLE")

import java.util.Properties

plugins {
kotlin("multiplatform")
kotlin("native.cocoapods")
id("com.android.library")
id("org.jetbrains.compose")
id("maven-publish")
}

group = "com.vitoksmile.health-kmp"
version = "0.0.1"

publishing {
repositories {
maven {
url = uri("https://maven.pkg.github.com/vitoksmile/HealthKMP")
name = "GitHubPackages"
credentials {
val properties = Properties()
properties.load(project.rootProject.file("local.properties").inputStream())
username = properties["GITHUB_USERNAME"].toString()
password = properties["GITHUB_TOKEN"].toString()
}
}
}
}

kotlin {
androidTarget()
androidTarget {
publishLibraryVariants("release", "debug")
publishLibraryVariantsGroupedByFlavor = true
}

iosX64()
iosArm64()
Expand All @@ -30,23 +53,13 @@ kotlin {
sourceSets {
val commonMain by getting {
dependencies {
implementation(compose.runtime)
implementation(compose.foundation)
implementation(compose.material)
@OptIn(org.jetbrains.compose.ExperimentalComposeLibrary::class)
implementation(compose.components.resources)

// Fix ios build
implementation("org.jetbrains.kotlinx:atomicfu:0.21.0")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.7.3")
}
}

val androidMain by getting {
dependencies {
api("androidx.activity:activity-compose:1.7.2")
api("androidx.appcompat:appcompat:1.6.1")
api("androidx.core:core-ktx:1.10.1")

implementation("androidx.activity:activity:1.7.2")
implementation("androidx.startup:startup-runtime:1.1.1")

implementation("androidx.health.connect:connect-client:1.1.0-alpha03")
Expand All @@ -61,6 +74,11 @@ kotlin {
iosX64Main.dependsOn(this)
iosArm64Main.dependsOn(this)
iosSimulatorArm64Main.dependsOn(this)

dependencies {
// Fix ios build
implementation("org.jetbrains.kotlinx:atomicfu:0.21.0")
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package com.vitoksmile.kmp.health
import android.content.Context
import android.content.Intent
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.activity.ComponentActivity
import androidx.health.connect.client.PermissionController
import kotlin.coroutines.resume
import kotlinx.coroutines.CancellableContinuation
Expand All @@ -14,7 +14,7 @@ import kotlinx.coroutines.suspendCancellableCoroutine
*
* https://issuetracker.google.com/issues/233239418
*/
internal class HealthConnectPermissionActivity : AppCompatActivity() {
internal class HealthConnectPermissionActivity : ComponentActivity() {

companion object {
private const val KEY_READ_PERMISSIONS = "KEY_READ_PERMISSIONS"
Expand Down
5 changes: 0 additions & 5 deletions core/src/androidMain/kotlin/main.android.kt

This file was deleted.

7 changes: 0 additions & 7 deletions core/src/iosMain/kotlin/main.ios.kt

This file was deleted.

2 changes: 1 addition & 1 deletion iosApp/Configuration/Config.xcconfig
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
TEAM_ID=
BUNDLE_ID=com.vitoksmile.kmp.health
APP_NAME=HealthKMP
APP_NAME=Health
1 change: 1 addition & 0 deletions iosApp/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ target 'iosApp' do
platform :ios, '14.1'
pod 'HealthKMP', :path => '../core'
pod 'HealthKMPKoin', :path => '../koin'
pod 'HealthKMPSample', :path => '../sample'
end
6 changes: 3 additions & 3 deletions iosApp/iosApp.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
20ACF4E2201EBCFD0F637C2A /* Pods_iosApp.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_iosApp.framework; sourceTree = BUILT_PRODUCTS_DIR; };
2152FB032600AC8F00CF470E /* iOSApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = iOSApp.swift; sourceTree = "<group>"; };
68E4587840B67DF8CD73E3AE /* Pods-iosApp.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-iosApp.debug.xcconfig"; path = "Target Support Files/Pods-iosApp/Pods-iosApp.debug.xcconfig"; sourceTree = "<group>"; };
7555FF7B242A565900829871 /* HealthKMP.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = HealthKMP.app; sourceTree = BUILT_PRODUCTS_DIR; };
7555FF7B242A565900829871 /* Health.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Health.app; sourceTree = BUILT_PRODUCTS_DIR; };
7555FF82242A565900829871 /* ContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentView.swift; sourceTree = "<group>"; };
7555FF8C242A565B00829871 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
9429AFAC2A68240500E5B251 /* iosApp.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = iosApp.entitlements; sourceTree = "<group>"; };
Expand Down Expand Up @@ -70,7 +70,7 @@
7555FF7C242A565900829871 /* Products */ = {
isa = PBXGroup;
children = (
7555FF7B242A565900829871 /* HealthKMP.app */,
7555FF7B242A565900829871 /* Health.app */,
);
name = Products;
sourceTree = "<group>";
Expand Down Expand Up @@ -123,7 +123,7 @@
);
name = iosApp;
productName = iosApp;
productReference = 7555FF7B242A565900829871 /* HealthKMP.app */;
productReference = 7555FF7B242A565900829871 /* Health.app */;
productType = "com.apple.product-type.application";
};
/* End PBXNativeTarget section */
Expand Down
9 changes: 5 additions & 4 deletions iosApp/iosApp/ContentView.swift
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
import UIKit
import SwiftUI
import core
import koin
import HealthKMP
import HealthKMPKoin
import HealthKMPSample

struct ComposeView: UIViewControllerRepresentable {

init() {
Health_kmp_koinKt.start()
HealthKMPKoin().start()
}

func makeUIViewController(context: Context) -> UIViewController {
Main_iosKt.MainViewController()
HealthKMPSample().MainViewController()
}

func updateUIViewController(_ uiViewController: UIViewController, context: Context) {}
Expand Down
39 changes: 39 additions & 0 deletions koin/HealthKMPKoin.podspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
Pod::Spec.new do |spec|
spec.name = 'HealthKMPKoin'
spec.version = '0.0.1'
spec.homepage = 'https://github.com/vitoksmile/HealthKMP'
spec.source = { :http=> ''}
spec.authors = ''
spec.license = ''
spec.summary = 'Shared Koin module for wrapper for HealthKit on iOS and Google Fit and Health Connect on Android.'
spec.vendored_frameworks = 'build/cocoapods/framework/HealthKMPKoin.framework'
spec.libraries = 'c++'
spec.ios.deployment_target = '14.1'


spec.pod_target_xcconfig = {
'KOTLIN_PROJECT_PATH' => ':koin',
'PRODUCT_MODULE_NAME' => 'HealthKMPKoin',
}

spec.script_phases = [
{
:name => 'Build HealthKMPKoin',
:execution_position => :before_compile,
:shell_path => '/bin/sh',
:script => <<-SCRIPT
if [ "YES" = "$OVERRIDE_KOTLIN_BUILD_IDE_SUPPORTED" ]; then
echo "Skipping Gradle build task invocation due to OVERRIDE_KOTLIN_BUILD_IDE_SUPPORTED environment variable set to \"YES\""
exit 0
fi
set -ev
REPO_ROOT="$PODS_TARGET_SRCROOT"
"$REPO_ROOT/../gradlew" -p "$REPO_ROOT" $KOTLIN_PROJECT_PATH:syncFramework \
-Pkotlin.native.cocoapods.platform=$PLATFORM_NAME \
-Pkotlin.native.cocoapods.archs="$ARCHS" \
-Pkotlin.native.cocoapods.configuration="$CONFIGURATION"
SCRIPT
}
]

end
Loading

0 comments on commit 15fc908

Please sign in to comment.