I am trying to build an Android Library and I have the following:
- Github Repo for the library
- Library 1: Kotlin native/multiplatform code that can compile to Android and iOS
- Library 2: Kotlin/JVM code dependent on Library 1
- Example App: App using Library 2 and Library 1
- Personal Android Project
- Dependent on the Github Library above
On my personal project I only have:
implementation 'com.github.username:myrepo:0.5'
Issues
The private Android project is loading android library (Library 2) but the multiplatform kotlin models and functions (Library 1) are not accessible.
Note that the example app of the library is working fine. I suspect that the jitpack.io is not publishing the artifacts correctly. Any idea on how to troubleshoot this? Is there anything that should be done to the gradle files to solve the problem?
I would like to have the multiplatform library published alone. I tried to access it from a multiplatform Kotlin module but I am getting "Unable to resolve dependencies". This is what I was trying:
implementation 'com.github.username.myrepo:library1_moduleName:0.1'
Gradle for Library 1 multiplatform:
plugins {
kotlin("multiplatform")
}
kotlin {
//select iOS target platform depending on the Xcode environment variables
val iOSTarget: (String, KotlinNativeTarget.() -> Unit) -> KotlinNativeTarget =
if (System.getenv("SDK_NAME")?.startsWith("iphoneos") == true)
::iosArm64
else
::iosX64
iOSTarget("ios") {
binaries {
framework {
baseName = "library1"
freeCompilerArgs.add("-Xobjc-generics")
}
}
}
jvm("android")
sourceSets["commonMain"].dependencies {
implementation("org.jetbrains.kotlin:kotlin-stdlib-common")
}
sourceSets["androidMain"].dependencies {
implementation("org.jetbrains.kotlin:kotlin-stdlib")
}
}
val packForXcode by tasks.creating(Sync::class) {
val targetDir = File(buildDir, "xcode-frameworks")
/// selecting the right configuration for the iOS
/// framework depending on the environment
/// variables set by Xcode build
val mode = System.getenv("CONFIGURATION") ?: "DEBUG"
val framework = kotlin.targets
.getByName<KotlinNativeTarget>("ios")
.binaries.getFramework(mode)
inputs.property("mode", mode)
dependsOn(framework.linkTask)
from({ framework.outputDirectory })
into(targetDir)
/// generate a helpful ./gradlew wrapper with embedded Java path
doLast {
val gradlew = File(targetDir, "gradlew")
gradlew.writeText(
"#!/bin/bash\n"
+ "export 'JAVA_HOME=${System.getProperty("java.home")}'\n"
+ "cd '${rootProject.rootDir}'\n"
+ "./gradlew \$@\n"
)
gradlew.setExecutable(true)
}
}
tasks.getByName("build").dependsOn(packForXcode)
Gradle for library 2
apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
android {
repositories {
google()
jcenter()
maven { url 'https://jitpack.io' }
}
compileSdkVersion 29
buildToolsVersion "29.0.0"
defaultConfig {
minSdkVersion 19
targetSdkVersion 29
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles 'consumer-rules.pro'
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
api project(":library1")
}