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

nestserau

01/30/2019, 2:10 PM
So I’ve found a way to rename my iOS framework from
main
to a custom name of mine. But how should I adjust the
packForXCode
task? I don’t understand. Can someone guide me? That’s my iOS target:
Copy code
final def iosTarget = System.getenv('SDK_NAME')?.startsWith("iphoneos") ? presets.iosArm64 : presets.iosX64
        fromPreset(iosTarget, 'ios') {
            binaries {
                framework {
                    baseName = 'reports'
                }
            }
        }
s

svyatoslav.scherbina

01/30/2019, 2:22 PM
But how should I adjust the
packForXCode
task?
Why do you find this necessary?
n

nestserau

01/30/2019, 2:25 PM
Otherwise it doesn’t find my renamed library.
When I try executing
packForXCode
in its default form, I get:
Copy code
* What went wrong:
Could not determine the dependencies of task ':packForXCode'.
> Task with path 'linkMainDebugFrameworkIos' not found in root project 'reports'.
And that is true. The only tasks I get are
linkDebugFrameworkIos
and
linkReleaseFrameworkIos
.
y
though I’m not sure if the first argument for findFramework is baseName or not
n

nestserau

01/30/2019, 3:23 PM
Does empty string work for you?
y

yshrsmz

01/30/2019, 3:41 PM
yes
name of the argument is namePrefix, so should be fine in your case too
for more detailed explanation please refer to this thread https://kotlinlang.slack.com/archives/C3PQML5NU/p1548403622428800
n

nestserau

01/30/2019, 3:45 PM
Yes, the script can now find my framework. Thank you very much @yshrsmz
y

yshrsmz

01/30/2019, 3:47 PM
great! 👍
n

nestserau

01/30/2019, 3:55 PM
For those who find this thread later in time, here is the final version of my
packForXCode
task:
Copy code
task packForXCode(type: Sync) {
    final File frameworkDir = new File(buildDir, "xcode-frameworks")
    final String mode = project.findProperty("XCODE_CONFIGURATION")?.toUpperCase() ?: 'DEBUG'
    inputs.property "mode", mode

    def binary = kotlin.targets.ios.compilations.main.target.binaries.findFramework("", mode)
    dependsOn binary.linkTask

    from { binary.outputFile.parent }
    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)
        }
    }
}
It’s the same as the origiinal one, but then made work for 1.3.20 Kotlin Gradle plug-in.
d

drofwarcs

01/30/2019, 4:30 PM
@nestserau do you know if anyone has tried with with Kotlin Gradle DSL? Nothing seems to resolve to a class that I can retrieve the binaries from. Essentially, having trouble converting this
Copy code
def binary = kotlin.targets.ios.compilations.main.target.binaries.findFramework("", mode)
to kotlin
n

nestserau

01/30/2019, 4:32 PM
I have no idea Eric. I don’t use Kotlin DSL, it has just popped out, I will wait a couple of releases until I decide to switch to it.
y

yshrsmz

01/30/2019, 4:39 PM
targets could be map or something, as
ios
is dynamically defined name
d

drofwarcs

01/30/2019, 5:04 PM
yeah, thats the issue, the dynamic nature of things lol.
Copy code
val nativeTarget = kotlin.targets["ios"] as KotlinNativeTarget
val srcFile = nativeTarget.binaries.getFramework(buildType).outputFile
was the closest thing I can get to build, but not sure if that works and it looks very verbose
48 Views