Dana Haukoos
10/19/2020, 5:17 PMkpgalligan
10/20/2020, 2:39 PMDana Haukoos
10/23/2020, 8:05 PMTask androidAppvalidateSigningDebug UP-TO-DATE
Task androidAppmergeDebugJavaResource FAILEDFAILURE: Build failed with an exception. * What went wrong: Execution failed for task 'androidAppmergeDebugJavaResource'.
A failure occurred while executing com.android.build.gradle.internal.tasks.Workers$ActionFacade> More than one file was found with OS independent path 'META-INF/DEPENDENCIES'. I found and tried this https://www.programmersought.com/article/17391741333/, but that doesn't even pass the syntax checker. Did some regression checking: If I comment everything with this newer module out, it builds again. If I comment out the original shared module and just build with this new one, the error returns.
russhwolf
10/26/2020, 5:32 PMandroid {
// ...
packagingOptions {
exclude("META_INF/*")
}
}
Dana Haukoos
10/26/2020, 5:36 PMrusshwolf
10/26/2020, 5:43 PMNSURLSession
in the platform.Foundation
packageDana Haukoos
10/26/2020, 5:52 PMrusshwolf
10/26/2020, 5:52 PMDana Haukoos
10/26/2020, 5:56 PMrusshwolf
10/26/2020, 5:57 PMNSURLSession
instead of URLSession
Dana Haukoos
10/26/2020, 5:59 PMactual fun getUser(email: String, hostToUse: String): String {
//<https://stackoverflow.com/questions/3566516/simple-http-post-example-in-objective-c/3566539>
// <https://blog.jetbrains.com/kotlin/2018/04/kotlinnative-v0-7-released-smoother-interop-frozen-objects-optimisations-and-more/>
val url = "https://$hostToUse/user/get"
println("The url is " + url.toString())
val postString = "data={\"email\":\"$email\"}" as NSString
println("The postString is " + postString)
val nsUrl = NSURL.URLWithString(url) as NSURL
val postData = (postString).dataUsingEncoding(NSUTF8StringEncoding)!!
val request = NSMutableURLRequest.requestWithURL(nsUrl)
request.setTimeoutInterval(120.0)
request.HTTPMethod = "POST"
request.HTTPBody = postData
// <https://github.com/ktorio/ktor/blob/master/ktor-client/ktor-client-ios/darwin/src/io/ktor/client/engine/ios/IosClientEngine.kt>
// <http://hayageek.com/ios-nsurlsession-example/#get-post> //#3.2
var result : String = "None"
//val task = session.dataTaskWithRequest(request)
val task = NSURLSession.sharedSession.dataTaskWithRequest(request) {
nsData: NSData?, nsURLResponse: NSURLResponse?, nsError: NSError? ->
if (nsError != null) {
val message = "The response is: " + nsURLResponse?.description() + ", error is: " + nsError.description()
println(message)
}
result = nsData.toString()
println("The data is: " + result)
}
task.resume()
return "The result is: " + result
This compiles when I run a unit test, but it doesn't work as intended. Here's the output:
> Task :ccwsmodule:cleanIosX64Test UP-TO-DATE
> Task :ccwsmodule:compileKotlinIosX64
w: /Users/dana.haukoos/ClearCaptionsGit/KMMApplication/ccwsmodule/src/iosMain/kotlin/com/example/ccwsmodule/CCWSv2.kt: (14, 56): This cast can never succeed
> Task :ccwsmodule:iosX64ProcessResources NO-SOURCE
> Task :ccwsmodule:iosX64MainKlibrary
> Task :ccwsmodule:compileTestKotlinIosX64
> Task :ccwsmodule:linkDebugTestIosX64
> Task :ccwsmodule:iosX64Test
2020-10-26 23:22:51.814 simctl[18263:5286149] Unable to locate a bundle at URL file:///Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Library/Developer/CoreSimulator/Profiles/DeviceTypes/iPhone%2012%20Pro%20Max.simdevicetype/
2020-10-26 23:22:51.814 simctl[18263:5286149] Unable to locate a bundle at URL file:///Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS.simruntime/
The url is <https://our.domain.com/user/get>
The postString is data={"email":"<mailto:dana.haukoos@clearcaptions.com|dana.haukoos@clearcaptions.com>"}
The response is The result is: None
BUILD SUCCESSFUL in 31s
5 actionable tasks: 4 executed, 1 up-to-date
11:22:52 PM: Tasks execution finished 'cleanIosX64Test iosX64Test --tests "com.example.ccwsmodule.ExampleUnitTest.test_getUser"'
w: /Users/dana.haukoos/ClearCaptionsGit/KMMApplication/ccwsmodule/src/iosMain/kotlin/com/example/ccwsmodule/CCWSv2.kt: (14, 56): This cast can never succeed
but haven't figured out how to resolve it, and I'm not clear on it's impact. Obviously, none of the println statements in task callback are run - I'm not clear on how the async aspect is supposed to work.russhwolf
10/27/2020, 1:31 PMDana Haukoos
10/27/2020, 1:33 PMprintln("The data is: " + result)
russhwolf
10/27/2020, 1:38 PMDana Haukoos
10/27/2020, 1:43 PMrusshwolf
10/27/2020, 1:46 PMtask.resume()
to handle thatDana Haukoos
10/27/2020, 1:46 PMrusshwolf
10/27/2020, 1:49 PMDana Haukoos
10/27/2020, 1:50 PMrusshwolf
10/27/2020, 1:50 PMnsData.toString()
won’t work the way you’re using it. You’ll need to convert the bytes explicitly, something like result = nsData?.bytes?.reinterpret<ByteVar>()?.toKString() ?: ""
Dana Haukoos
10/27/2020, 1:53 PMrusshwolf
10/27/2020, 1:54 PMDana Haukoos
10/27/2020, 1:54 PMrusshwolf
10/27/2020, 1:55 PMimport kotlinx.cinterop.*
if they’re not auto-importingDana Haukoos
10/27/2020, 1:55 PMrusshwolf
10/27/2020, 2:24 PMDana Haukoos
10/27/2020, 2:33 PMrusshwolf
10/27/2020, 2:35 PMDana Haukoos
10/27/2020, 2:37 PMrusshwolf
10/27/2020, 4:35 PMDana Haukoos
10/27/2020, 4:36 PMrusshwolf
10/27/2020, 4:39 PMDana Haukoos
10/27/2020, 4:42 PMandroid {
// ...
packagingOptions {
exclude("META_INF/*")
}
}
(edited)
but when I added that, it didn't resolve my problem:
A failure occurred while executing com.android.build.gradle.internal.tasks.Workers$ActionFacade> More than one file was found with OS independent path 'META-INF/DEPENDENCIES'.
russhwolf
10/27/2020, 5:19 PMDana Haukoos
10/27/2020, 5:24 PMrusshwolf
10/27/2020, 5:25 PMDana Haukoos
10/27/2020, 5:32 PMTask androidAppmergeDebugJavaResource FAILEDso that implicates the ":shared" module, I would infer. But that's what I tried, so maybe I'm not following yet.
russhwolf
10/27/2020, 5:33 PMDana Haukoos
10/27/2020, 5:35 PMprintln("getUser is ${ccws.getUser(email, host)}")
russhwolf
10/27/2020, 7:30 PMval result = AtomicReference("None")
val completionHandler = { nsData: NSData?, nsURLResponse: NSURLResponse?, nsError: NSError? ->
if (nsError != null) {
val message =
"The response is: " + nsURLResponse?.description() + ", error is: " + nsError.description()
println(message)
}
result.value = nsData?.bytes?.reinterpret<ByteVar>()?.toKString() ?: ""
println("The data is: " + result.value)
}.freeze()
val task =
NSURLSession.sharedSession.dataTaskWithRequest(request, completionHandler)
task.resume()
return "The result is: " + result.value
Dana Haukoos
10/27/2020, 7:36 PMrusshwolf
10/27/2020, 7:37 PMkotlin.native.concurrent
package.Dana Haukoos
10/27/2020, 7:38 PMrusshwolf
10/27/2020, 7:39 PMDana Haukoos
10/27/2020, 7:44 PMrusshwolf
10/27/2020, 7:44 PMDana Haukoos
10/27/2020, 7:50 PMrusshwolf
10/27/2020, 7:52 PMDana Haukoos
10/27/2020, 7:57 PMrusshwolf
10/27/2020, 7:58 PMDana Haukoos
10/27/2020, 7:59 PMrusshwolf
10/27/2020, 8:03 PMDana Haukoos
10/27/2020, 8:07 PMrusshwolf
10/27/2020, 8:09 PMDana Haukoos
10/27/2020, 8:09 PMrusshwolf
10/27/2020, 8:09 PMDana Haukoos
10/27/2020, 8:14 PMrusshwolf
10/27/2020, 8:15 PMDana Haukoos
10/27/2020, 8:23 PMactual fun getUser(email: String, hostToUse: String): String {
val client = OkHttpClient()
val url = "https://$hostToUse/user/get"
println("The url is " + url.toString())
val postString = "data={\"email\":\"$email\"}"
println("The postString is " + postString)
// val body: RequestBody = create(json, JSON)
val body: RequestBody = RequestBody.create(
//MediaType.parse("application/json"), postString
MediaType.parse("application/x-www-form-urlencoded; charset=UTF-8"), postString
)
val request: Request = Request.Builder()
.url(url)
.post(body)
.build()
val call: Call = client.newCall(request)
return try {
val response: Response = call.execute()
response.body().toString()
} catch (e: Exception) {
"Exception is " + e.message
}
}
}
actual fun getUser(email: String, hostToUse: String): String {
//val client = OkHttpClient()
val CLIENT_TIMEOUT_MILLIS: Long = 60000
val client = OkHttpClient.Builder()
.connectTimeout(CLIENT_TIMEOUT_MILLIS, TimeUnit.MILLISECONDS)
.writeTimeout(CLIENT_TIMEOUT_MILLIS, TimeUnit.MILLISECONDS)
.readTimeout(CLIENT_TIMEOUT_MILLIS, TimeUnit.MILLISECONDS)
.build()
val url = "https://$hostToUse/user/get"
println("The url is " + url.toString())
val postString = "data={\"email\":\"$email\"}"
println("The postString is " + postString)
// val body: RequestBody = create(json, JSON)
val body: RequestBody = RequestBody.create(
//MediaType.parse("application/json"), postString
MediaType.parse("application/x-www-form-urlencoded; charset=UTF-8"), postString
)
val request: Request = Request.Builder()
.url(url)
.post(body)
.build()
println("The request body is " + request.body())
val call: Call = client.newCall(request)
return try {
val httpResponse: Response = call.execute()
println("POST Response Status: " + httpResponse.code())
println("POST Response Success: " + httpResponse.isSuccessful)
println("POST Response contentLegnth: " + httpResponse.body()!!.contentLength())
val reader = BufferedReader(
InputStreamReader(
httpResponse.body()!!.byteStream()
)
)
var inputLine: String?
val response = StringBuffer()
while (reader.readLine().also { inputLine = it } != null) {
response.append(inputLine)
}
reader.close()
response.toString()
} catch (e: Exception) {
"Exception is " + e.message
}
}
Still need to get it working when called via the app.russhwolf
10/28/2020, 3:19 PMbuild/bin
in your shared moduleDana Haukoos
10/28/2020, 3:26 PMrusshwolf
10/28/2020, 3:26 PM./gradlew build
to build everything and probably there will be a framework in there tooDana Haukoos
10/28/2020, 3:29 PMTask androidApplintRan lint on variant debug: 6 issues found Ran lint on variant release: 4 issues found Wrote HTML report to file:///Users/dana.haukoos/ClearCaptionsGit/KMMApplication/androidApp/build/reports/lint-results.html Wrote XML report to file:///Users/dana.haukoos/ClearCaptionsGit/KMMApplication/androidApp/build/reports/lint-results.xml Expiring Daemon because JVM heap space is exhausted Daemon will be stopped at the end of the build after running out of JVM memory Expiring Daemon because JVM heap space is exhausted Expiring Daemon because JVM heap space is exhausted Expiring Daemon because JVM heap space is exhausted Expiring Daemon because JVM heap space is exhausted Expiring Daemon because JVM heap space is exhausted Expiring Daemon because JVM heap space is exhausted
Task ccwsmodulelinkDebugTestIosX64 FAILEDe: /Users/dana.haukoos/ClearCaptionsGit/KMMApplication/ccwsmodule/src/iosTest/kotlin/com/example/ccwsmodule/iosTest.kt: Test function must return Unit: com.example.ccwsmodule.iOSUnitTest.test_getUser FAILURE: Build failed with an exception. * What went wrong: Execution failed for task 'ccwsmodulelinkDebugTestIosX64'.
Compilation finished with errors* Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights. * Get more help at https://help.gradle.org BUILD FAILED in 1m 54s 206 actionable tasks: 2 executed, 204 up-to-date Expiring Daemon because JVM heap space is exhausted
russhwolf
10/28/2020, 3:39 PMe: /Users/dana.haukoos/ClearCaptionsGit/KMMApplication/ccwsmodule/src/iosTest/kotlin/com/example/ccwsmodule/iosTest.kt: Test function must return Unit: com.example.ccwsmodule.iOSUnitTest.test_getUser
Fix this functionDana Haukoos
10/28/2020, 3:42 PM