Kotlin multi-platform framework file is too large

烂漫一生 提交于 2020-07-10 07:33:27

问题


We created a multi-platform framework file by building my project with the following packForXCode. It creates a framework file of the size 5.3 MB, which is too large. When I add it as part of my iOS extension module, it fails during initiation. The file works fine when inited in the main app.

My pack for Xcode:

task packForXcode(type: Sync) {
    final File frameworkDir = new File(buildDir, "xcode-frameworks")
    final String mode = project.findProperty("XCODE_CONFIGURATION")?.toUpperCase() ?: 'DEBUG'
    final def framework = kotlin.targets.iosArm64.binaries.getFramework(mode)

    inputs.property "mode", mode
    dependsOn framework.linkTask

    from { framework.outputFile.parentFile }
    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)
        }
    }
}

Adding the source set details:

sourceSets {
        commonMain {
            dependencies {
                implementation kotlin("stdlib-common")
            }
        }
        iosMain.dependencies {

        }
}

Also there are not other dependencies Can I make stdlib-common compileOnly ? How can I reduce the framework size. Am I blocked ?

Edit: At the same time the ios.jar is just 20kb

Adding error logs:

#0  0x0000000198726538 in _platform_memmove ()
#1  0x0000000104bcd514 in kfun:kotlin.collections.copyInto@kotlin.LongArray.(kotlin.LongArray;kotlin.Int;kotlin.Int;kotlin.Int)kotlin.LongArray ()
#2  0x0000000104bcd348 in kfun:kotlin.collections.copyOfUninitializedElements$stdlib@kotlin.LongArray.(kotlin.Int;kotlin.Int)kotlin.LongArray ()
#3  0x0000000104bcd114 in kfun:kotlin.collections.copyOfUninitializedElements$stdlib@kotlin.LongArray.(kotlin.Int)kotlin.LongArray ()
#4  0x0000000104bcd004 in kfun:kotlin.collections.copyOf@kotlin.LongArray.(kotlin.Int)kotlin.LongArray ()
#5  0x0000000104bf3928 in kfun:kotlin.native.BitSet.ensureCapacity#internal ()
#6  0x0000000104bf3f3c in kfun:kotlin.native.BitSet.set(kotlin.ranges.IntRange;kotlin.Boolean) ()
#7  0x0000000104bf3c70 in kfun:kotlin.native.BitSet.set(kotlin.Int;kotlin.Int;kotlin.Boolean) ()
#8  0x0000000104c42f30 in kfun:kotlin.text.regex.CharClass.add(kotlin.Int;kotlin.Int)kotlin.text.regex.CharClass ()
#9  0x0000000104c633b0 in kfun:kotlin.text.regex.Pattern.processRangeExpression#internal ()
#10 0x0000000104c62904 in kfun:kotlin.text.regex.Pattern.processRangeExpression#internal ()
#11 0x0000000104c61fe4 in kfun:kotlin.text.regex.Pattern.processRange#internal ()
#12 0x0000000104c601dc in kfun:kotlin.text.regex.Pattern.processTerminal#internal ()
#13 0x0000000104c5c698 in kfun:kotlin.text.regex.Pattern.processSubExpression#internal ()
#14 0x0000000104c58c58 in kfun:kotlin.text.regex.Pattern.processExpression#internal ()
#15 0x0000000104c5fe18 in kfun:kotlin.text.regex.Pattern.processTerminal#internal ()
#16 0x0000000104c5c698 in kfun:kotlin.text.regex.Pattern.processSubExpression#internal ()
#17 0x0000000104c5c080 in kfun:kotlin.text.regex.Pattern.processSubExpression#internal ()
#18 0x0000000104c58c58 in kfun:kotlin.text.regex.Pattern.processExpression#internal ()
#19 0x0000000104c5fe18 in kfun:kotlin.text.regex.Pattern.processTerminal#internal ()
#20 0x0000000104c5c698 in kfun:kotlin.text.regex.Pattern.processSubExpression#internal ()
#21 0x0000000104c58c58 in kfun:kotlin.text.regex.Pattern.processExpression#internal ()
#22 0x0000000104c5fe18 in kfun:kotlin.text.regex.Pattern.processTerminal#internal ()
#23 0x0000000104c5c698 in kfun:kotlin.text.regex.Pattern.processSubExpression#internal ()
#24 0x0000000104c58c58 in kfun:kotlin.text.regex.Pattern.processExpression#internal ()
#25 0x0000000104c5fe18 in kfun:kotlin.text.regex.Pattern.processTerminal#internal ()
#26 0x0000000104c5c698 in kfun:kotlin.text.regex.Pattern.processSubExpression#internal ()
#27 0x0000000104c5c080 in kfun:kotlin.text.regex.Pattern.processSubExpression#internal ()
#28 0x0000000104c58c58 in kfun:kotlin.text.regex.Pattern.processExpression#internal ()
#29 0x0000000104c5fe18 in kfun:kotlin.text.regex.Pattern.processTerminal#internal ()
#30 0x0000000104c5c698 in kfun:kotlin.text.regex.Pattern.processSubExpression#internal ()
#31 0x0000000104c58c58 in kfun:kotlin.text.regex.Pattern.processExpression#internal ()
#32 0x0000000104c5fe18 in kfun:kotlin.text.regex.Pattern.processTerminal#internal ()
#33 0x0000000104c5c698 in kfun:kotlin.text.regex.Pattern.processSubExpression#internal ()
#34 0x0000000104c58c58 in kfun:kotlin.text.regex.Pattern.processExpression#internal ()
#35 0x0000000104c57418 in kfun:kotlin.text.regex.Pattern.<init>(kotlin.String;kotlin.Int)kotlin.text.regex.Pattern ()
#36 0x0000000104c57794 in kfun:kotlin.text.regex.Pattern.<init>(kotlin.String;kotlin.Int;kotlin.Int;kotlin.native.internal.DefaultConstructorMarker?)kotlin.text.regex.Pattern ()
#37 0x0000000104c10984 in kfun:kotlin.text.Regex.<init>(kotlin.String)kotlin.text.Regex ()
#38 0x0000000104cbae0c in ___lldb_unnamed_symbol189$$MyMessageFilterExtension ()
#39 0x0000000104ce9200 in (anonymous namespace)::initRuntime() ()
#40 0x0000000104ce901c in Kotlin_initRuntimeIfNeeded ()
#41 0x0000000104cc8a84 in +[KotlinBase allocWithZone:] ()
#42 0x0000000104ba5ee4 in My_categorizerSmsClassifierBuilder.__allocating_init() ()
#43 0x0000000104ba5db4 in SMSCategorizerBuilder.build(completion:) ()
#44 0x0000000104ba5160 in MessageFilterExtension.filterByContent(for:completion:) at /Users/vs/Development/my-iphone/My_iOS/MyMessageFilterExtension/MessageFilterExtension.swift:75
#45 0x0000000104ba4a54 in MessageFilterExtension.handle(_:context:completion:) at /Users/vs/Development/my-iphone/My_iOS/MyMessageFilterExtension/MessageFilterExtension.swift:56
#46 0x0000000104ba528c in @objc MessageFilterExtension.handle(_:context:completion:) ()
#47 0x00000001b8fefef0 in -[ILMessageFilterExtensionContext handleQueryRequest:reply:] ()
#48 0x0000000198f283d4 in __NSXPCCONNECTION_IS_CALLING_OUT_TO_EXPORTED_OBJECT_S2__ ()
#49 0x0000000198d31e40 in -[NSXPCConnection _decodeAndInvokeMessageWithEvent:flags:] ()
#50 0x0000000198f284f8 in message_handler ()
#51 0x000000019861aae0 in _xpc_connection_call_event_handler ()
#52 0x000000019861ae68 in _xpc_connection_mach_event ()
#53 0x00000001986c4408 in _dispatch_client_callout4 ()
#54 0x00000001986db2f0 in _dispatch_mach_msg_invoke ()
#55 0x00000001986ca72c in _dispatch_lane_serial_drain ()
#56 0x00000001986dbf2c in _dispatch_mach_invoke ()
#57 0x00000001986ca72c in _dispatch_lane_serial_drain ()
#58 0x00000001986cb2c4 in _dispatch_lane_invoke ()
#59 0x00000001986d4928 in _dispatch_workloop_worker_thread ()
#60 0x000000019872b714 in _pthread_wqthread () 

来源:https://stackoverflow.com/questions/61920418/kotlin-multi-platform-framework-file-is-too-large

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!