Skip to content
This repository has been archived by the owner on Jul 2, 2024. It is now read-only.

Commit

Permalink
Update libgeomag
Browse files Browse the repository at this point in the history
  • Loading branch information
SanmerDev committed Feb 9, 2024
1 parent c702a0e commit 280f312
Show file tree
Hide file tree
Showing 15 changed files with 124 additions and 8 deletions.
8 changes: 1 addition & 7 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,6 @@ android {
}
}

sourceSets {
getByName("main") {
jniLibs.srcDir("src/main/libs")
}
}

splits {
abi {
reset()
Expand Down Expand Up @@ -130,7 +124,7 @@ androidComponents {
}

dependencies {
implementation(fileTree("src/main/libs") { include("*.jar") })
implementation(projects.native)

implementation(libs.accompanist.permissions)
implementation(libs.androidx.activity.compose)
Expand Down
Binary file removed app/src/main/libs/arm64-v8a/libgeomag-jni.so
Binary file not shown.
Binary file removed app/src/main/libs/libgeomag-jni-android.jar
Binary file not shown.
Binary file removed app/src/main/libs/x86_64/libgeomag-jni.so
Binary file not shown.
5 changes: 5 additions & 0 deletions build-logic/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ gradlePlugin {
implementationClass = "ApplicationConventionPlugin"
}

register("proLibrary") {
id = "pro.library"
implementationClass = "LibraryConventionPlugin"
}

register("proCompose") {
id = "pro.compose"
implementationClass = "ComposeConventionPlugin"
Expand Down
43 changes: 43 additions & 0 deletions build-logic/src/main/kotlin/LibraryConventionPlugin.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import com.android.build.api.dsl.LibraryExtension
import org.gradle.api.JavaVersion
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.plugins.JavaPluginExtension
import org.gradle.jvm.toolchain.JavaLanguageVersion
import org.gradle.kotlin.dsl.configure
import org.jetbrains.kotlin.gradle.dsl.KotlinAndroidProjectExtension

class LibraryConventionPlugin : Plugin<Project> {
override fun apply(target: Project) {
with(target) {
with(pluginManager) {
apply("com.android.library")
apply("org.jetbrains.kotlin.android")
}

extensions.configure<LibraryExtension> {
compileSdk = 34
buildToolsVersion = "34.0.0"

defaultConfig {
minSdk = 29
}

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

extensions.configure<JavaPluginExtension> {
toolchain {
languageVersion.set(JavaLanguageVersion.of(17))
}
}

extensions.configure<KotlinAndroidProjectExtension> {
jvmToolchain(17)
}
}
}
}
1 change: 1 addition & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ protobuf = { id = "com.google.protobuf", version.ref = "protobufPlugin" }

# Plugins defined by this project
pro-application = { id = "pro.application", version = "unspecified" }
pro-library = { id = "pro.library", version = "unspecified" }
pro-compose = { id = "pro.compose", version = "unspecified" }
pro-hilt = { id = "pro.hilt", version = "unspecified" }
pro-room = { id = "pro.room", version = "unspecified" }
17 changes: 17 additions & 0 deletions native/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
plugins {
alias(libs.plugins.pro.library)
}

android {
namespace = "dev.sanmer.geomag"

sourceSets {
getByName("main") {
jniLibs.srcDir("src/main/libs")
}
}
}

dependencies {
implementation(libs.kotlinx.datetime)
}
22 changes: 22 additions & 0 deletions native/src/main/kotlin/dev/sanmer/geomag/Geomag.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package dev.sanmer.geomag

import kotlinx.datetime.LocalDateTime

object Geomag {
init {
ImplLibrary.load()
}

external fun toDecimalYears(year: Int, month: Int, day: Int, hour: Int, minute: Int, second: Int): Double
external fun wmm(longitude: Double, latitude: Double, altitude: Double, decimalYears: Double): MagneticField
external fun igrf(longitude: Double, latitude: Double, altitude: Double, decimalYears: Double): MagneticField

fun toDecimalYears(date: LocalDateTime) =
toDecimalYears(date.year, date.monthNumber, date.dayOfMonth, date.hour, date.minute, date.second)

fun wmm(longitude: Double, latitude: Double, altitude: Double, date: LocalDateTime) =
wmm(longitude, latitude, altitude, toDecimalYears(date))

fun igrf(longitude: Double, latitude: Double, altitude: Double, date: LocalDateTime) =
igrf(longitude, latitude, altitude, toDecimalYears(date))
}
10 changes: 10 additions & 0 deletions native/src/main/kotlin/dev/sanmer/geomag/ImplLibrary.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package dev.sanmer.geomag


internal object ImplLibrary: Library {
override val name: String = "geomag-jni"

override fun load() {
System.loadLibrary(name)
}
}
6 changes: 6 additions & 0 deletions native/src/main/kotlin/dev/sanmer/geomag/Library.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package dev.sanmer.geomag

internal interface Library {
val name: String
fun load()
}
18 changes: 18 additions & 0 deletions native/src/main/kotlin/dev/sanmer/geomag/MagneticField.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package dev.sanmer.geomag

data class MagneticField(
val x: Double,
val xDot: Double,
val y: Double,
val yDot: Double,
val z: Double,
val zDot: Double,
val h: Double,
val hDot: Double,
val f: Double,
val fDot: Double,
val d: Double,
val dDot: Double,
val i: Double,
val iDot: Double
)
Binary file added native/src/main/libs/arm64-v8a/libgeomag-jni.so
Binary file not shown.
Binary file added native/src/main/libs/x86_64/libgeomag-jni.so
Binary file not shown.
2 changes: 1 addition & 1 deletion settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ dependencyResolutionManagement {
repositories {
google()
mavenCentral()
maven("https://jitpack.io")
}
}

Expand All @@ -21,3 +20,4 @@ pluginManagement {

rootProject.name = "Geomag"
include(":app")
include(":native")

0 comments on commit 280f312

Please sign in to comment.