https://kotlinlang.org logo
#multiplatform
Title
# multiplatform
c

Christian Sousa

03/31/2020, 11:34 AM
anyone has any experience working with JFrog Artifactory? I’m generating and publishing to a local repo but I can’t seem to be able to use the lib on another project. The problem I’m facing is that the aar is published but on my other project, I can’t use the code anywhere, and on my external libraries, I can only see: Gradle: com.christiansousa.lib:MyLib -> classes.jar but inside it there’s only:
MyLib-release.kotlin_module
and not any of the classes. Sorry if it’s not the right place to ask this but since I can only see the
*.kotlin_module
on my External Libraries I thought this would be the best place to ask.
k

Kris Wong

03/31/2020, 1:06 PM
if your APIs are public, they will be included in the target binary. which artifact are you looking at?
c

Christian Sousa

03/31/2020, 1:42 PM
What I did was I followed a sort of tutorial on some blog and did everything according to it. Problem is when in the blank project I do
implementation "com.christiansousa.lib:MyLib:1.0.0"
and then try to import something from the lib I simply can’t. Then I went ahead and looked into the External Libraries Tree that I have in my blank project but there’s not a single class to be seen, just the
kotlin_module
file. I don’t know if I’m explaining correctly what the issue is, but anyways thank you for your time @Kris Wong
k

Kris Wong

03/31/2020, 1:47 PM
sounds like you're importing the metadata module and not a target-specific module. have you browsed the maven repo for your project to see what artifacts are there?
c

Christian Sousa

03/31/2020, 1:52 PM
I’m using the JFrog locally. On the Artifacts I have the following structure: my-repo |-> com/christiansousa/lib/MyLib |-> 1.0.0 |-> MyLib-1.0.0.aar |-> MyLib-1.0.0.pom |-> maven-metadata.xml
I don’t know what I’m doing wrong
k

Kris Wong

03/31/2020, 1:55 PM
i see
how about your build.gradle[.kts]
c

Christian Sousa

03/31/2020, 1:56 PM
From my lib?
On my lib I have the following:
Copy code
project('MyLib') {
    artifactoryPublish.dependsOn('build')
    publishing {
        publications {
            aar(MavenPublication) {
                groupId = "com.christiansousa.lib"
                artifactId = project.getName()
                version = "1.0.0"
                artifact("$buildDir/outputs/aar/${project.getName()}-release.aar")
            }
        }
    }

    artifactoryPublish {
        publications(publishing.publications.aar)
    }
}
and
Copy code
artifactory {
    clientConfig.setIncludeEnvVars(true)
    <http://clientConfig.info|clientConfig.info>.addEnvironmentProperty('test.adding.dynVar',new Date().toString())

    contextUrl = '<http://127.0.0.1:8082/artifactory>'
    publish {
        repository {
            repoKey = 'libs-release-local'
            username = "${artifactory_user}"
            password = "${artifactory_password}"
            
            ivy {
                ivyLayout = '[organization]/[module]/ivy-[revision].xml'
                artifactLayout = '[organization]/[module]/[revision]/[module]-[revision](-[classifier]).[ext]'
                mavenCompatible = true
            }
        }
        defaults {
            publishArtifacts = true
            properties = ['qa.level': 'basic', 'dev.team' : 'core']
            publishPom = true
        }
    }
}
On my blank app I have this (on the outer):
Copy code
allprojects {
    repositories {
        google()
        jcenter()
        repositories {
            maven {
                url "<http://localhost:8082/artifactory/libs-release-local>"
                credentials {
                    username "admin"
                    password "password"
                }
            }
        }
    }
}
In the app I have:
Copy code
dependencies {
  ...
  implementation "com.christiansousa.lib:MyLib:1.0.0"
}
k

Kris Wong

03/31/2020, 2:10 PM
i was more interested in how your targets and source sets are configured
your artifact is getting published, so I know that configuration is working
c

Christian Sousa

03/31/2020, 2:12 PM
I’m kinda new to this kotlin and Android world, where are the targets and source sets so I can show you?
k

Kris Wong

03/31/2020, 2:13 PM
c

Christian Sousa

03/31/2020, 2:15 PM
Oh I see. Thing is, for my blank app I’m just using a blank page template from Android Studio, without Kotlin
I’m just using the Mpp for the lib
k

Kris Wong

03/31/2020, 2:38 PM
the lib has the problem, so that is what I am interested in
c

Christian Sousa

03/31/2020, 2:43 PM
Is this what you wanted to see?
Copy code
kotlin {
    val kotlin_version = "1.3.70"
    val coroutines_version = "1.3.4"
    val serialization_version = "0.20.0"
    val ktor_version = "1.3.2"

    //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 = "MyLib"
            }
        }
    }

    android("android")

    sourceSets["commonMain"].dependencies {
        implementation("org.jetbrains.kotlin:kotlin-stdlib-common:$kotlin_version")
        implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core-common:$coroutines_version")
        implementation("org.jetbrains.kotlinx:kotlinx-serialization-runtime-common:$serialization_version")
        implementation("io.ktor:ktor-client:$ktor_version")
        implementation("io.ktor:ktor-client-core:$ktor_version")
        implementation("io.ktor:ktor-client-json:$ktor_version")
        implementation("io.ktor:ktor-client-serialization:$ktor_version")
        implementation("com.benasher44:uuid:0.1.0")
        implementation("com.soywiz.korlibs.krypto:krypto:1.11.0")
        implementation("dev.icerock.moko:resources:0.9.0")
        implementation("com.google.android:flexbox:2.0.1")

    }

    sourceSets["androidMain"].dependencies {
        implementation("androidx.preference:preference-ktx:1.1.0")
        implementation("org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version")
        implementation("org.jetbrains.kotlinx:kotlinx-coroutines-android:$coroutines_version")
        implementation("org.jetbrains.kotlinx:kotlinx-serialization-runtime:$serialization_version")
        implementation("io.ktor:ktor-client-android:$ktor_version")
        implementation("io.ktor:ktor-client-core-jvm:$ktor_version")
        implementation("io.ktor:ktor-client-json-jvm:$ktor_version")
        implementation("io.ktor:ktor-client-serialization-jvm:$ktor_version")
    }

    sourceSets["iosMain"].dependencies {
        implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core-native:$coroutines_version")
        implementation("org.jetbrains.kotlinx:kotlinx-serialization-runtime-native:$serialization_version")
        implementation("io.ktor:ktor-client-ios:$ktor_version")
        implementation("io.ktor:ktor-client-core-native:$ktor_version")
        implementation("io.ktor:ktor-client-serialization-native:$ktor_version")
    }
}
Copy code
android {
    compileSdkVersion(29)
    buildToolsVersion("29.0.3")
    defaultConfig {
        minSdkVersion(16)
        targetSdkVersion(29)
    }
    buildTypes {
        getByName("release") {
            isMinifyEnabled = true
            proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "<http://proguard-rules.pro|proguard-rules.pro>")
        }
    }
}
Is there something more that you liked to take a look at?
k

Kris Wong

03/31/2020, 2:48 PM
well first thing I see that is that you have
isMinifyEnabled
set to true
c

Christian Sousa

03/31/2020, 3:03 PM
That alone should solve it?
k

Kris Wong

03/31/2020, 3:08 PM
it might. it's removing all unused code.
❤️ 1
c

Christian Sousa

03/31/2020, 3:14 PM
If I could, I would kiss you right away. No homo. Thanks a lot dude 🙂
🍻 1
@Kris Wong is there a way that I can forward my local repo so someone can access it remotely? I promise I won’t bother you for another lifetime
k

Kris Wong

03/31/2020, 3:41 PM
i don't know that much about running a local/remote repo
we use artifactory internally
c

Christian Sousa

03/31/2020, 3:42 PM
Oh ok then, thank you for your time 🙂
2 Views