Skip to content

Broken Build #5

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
rhonyabdullah opened this issue Mar 5, 2024 · 3 comments
Closed

Broken Build #5

rhonyabdullah opened this issue Mar 5, 2024 · 3 comments

Comments

@rhonyabdullah
Copy link

This project is broken, i'm unable to build it. Some of the imports also error on the iosMain.kt file did you try to build this project on the Android Studio @KhubaibKhan4 ?

Android Studio Iguana | 2023.2.1
Build #AI-232.10227.8.2321.11479570, built on February 22, 2024
Runtime version: 17.0.9+0-17.0.9b1087.7-11185874 aarch64
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o.
macOS 14.3.1
GC: G1 Young Generation, G1 Old Generation
Memory: 4096M
Cores: 8
Metal Rendering is ON
Registry:
    debugger.new.tool.window.layout=true
    ide.instant.shutdown=false
    ide.experimental.ui=true
@KhubaibKhan4
Copy link
Owner

KhubaibKhan4 commented Mar 5, 2024

Hi @rhonyabdullah, It's working fine but might contains some imports issue on the iOS Side because To Use the iOS Imports section you must have a mac otherwise you'll get the imports issue. If you gave Mac then you'll not get any issue regarding these imports. But the build section works perfectly fine. Checkout what's the issue you are facing? If you need any help. Please comment it down.

@rhonyabdullah
Copy link
Author

Hi @rhonyabdullah, It's working fine but might contains some imports issue on the iOS Side because To Use the iOS Imports section you must have a mac otherwise you'll get the imports issue. If you gave Mac then you'll not get any issue regarding these imports. But the build section works perfectly fine. Checkout what's the issue you are facing? If you need any help. Please comment it down.

Helo @KhubaibKhan4
Thanks for your response, from my first comment above currently i'm using AS Iguana with macOS 14.3.1 with Mac M1 Pro which i'm really sure that there is no machine issues on my side. I'm seeing that you just recently make an update from this commit 56ed62088cbe71b4b09e6fc864eddfd4343d7570

Here is the result when i'm running the kdoctor on my mac terminal
Screenshot 2024-03-05 at 22 02 15

Checking out from the last version, if i'm syncing the project this error occurs:

:composeApp:iosArm64Main: Could not resolve io.github.aakira:napier:2.7.0.
Required by:
    project :composeApp

This is looks like caused by the napier version is not found, so i try to upgrade it to napier = "2.7.1", the above error is gone, but another error is occurs which related with some import error referrence:

Screenshot 2024-03-05 at 21 22 55

At this point, i'm trying to do some workaround:

@file:OptIn(ExperimentalForeignApi::class)

package org.company.app

import YouTubeDatabase.db.YoutubeDatabase
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.interop.UIKitView
import app.cash.sqldelight.db.SqlDriver
import app.cash.sqldelight.driver.native.NativeSqliteDriver
import kotlinx.cinterop.BetaInteropApi
import kotlinx.cinterop.CValue
import kotlinx.cinterop.ExperimentalForeignApi
import kotlinx.cinterop.ObjCObjectVar
import kotlinx.cinterop.allocPointerTo
import kotlinx.cinterop.memScoped
import kotlinx.cinterop.pointed
import kotlinx.cinterop.value
import platform.AVFoundation.AVPlayer
import platform.AVFoundation.AVPlayerLayer
import platform.AVFoundation.play
import platform.AVKit.AVPlayerViewController
import platform.CoreGraphics.CGRect
import platform.Foundation.NSError
import platform.Foundation.NSLocale
import platform.Foundation.NSURL
import platform.Foundation.NSURLConnection
import platform.Foundation.NSURLRequest
import platform.Foundation.NSURLResponse
import platform.Foundation.countryCode
import platform.Foundation.currentLocale
import platform.Foundation.sendSynchronousRequest
import platform.QuartzCore.CATransaction
import platform.QuartzCore.kCATransactionDisableActions
import platform.UIKit.UIActivityViewController
import platform.UIKit.UIAlertAction
import platform.UIKit.UIAlertActionStyle
import platform.UIKit.UIAlertController
import platform.UIKit.UIAlertControllerStyle
import platform.UIKit.UIApplication
import platform.UIKit.UIDevice
import platform.UIKit.UIView

internal actual fun openUrl(url: String?) {
    val nsUrl = url?.let { NSURL.URLWithString(it) } ?: return
    UIApplication.sharedApplication.openURL(nsUrl)
}

@Composable
internal actual fun VideoPlayer(modifier: Modifier, url: String?, thumbnail: String?) {

    val player = remember { AVPlayer(uRL = NSURL.URLWithString(url.orEmpty())!!) }
    val playerLayer = remember { AVPlayerLayer() }
    val avPlayerViewController = remember { AVPlayerViewController() }
    avPlayerViewController.player = player
    avPlayerViewController.showsPlaybackControls = true

    playerLayer.player = player
    // Use a UIKitView to integrate with your existing UIKit views
    UIKitView(
        factory = {
            // Create a UIView to hold the AVPlayerLayer
            val playerContainer = UIView()
            playerContainer.addSubview(avPlayerViewController.view)
            // Return the playerContainer as the root UIView
            playerContainer
        },
        onResize = { view: UIView, rect: CValue<CGRect> ->
            CATransaction.begin()
            CATransaction.setValue(true, kCATransactionDisableActions)
            view.layer.setFrame(rect)
            playerLayer.setFrame(rect)
            avPlayerViewController.view.layer.frame = rect
            CATransaction.commit()
        },
        update = { view ->
            player.play()
            avPlayerViewController.player!!.play()
        },
        modifier = modifier
    )
}
@Composable
internal actual fun provideShortCuts(){
    return
}

@Composable
internal actual fun Notify(message: String) {
    val alertController = UIAlertController.alertControllerWithTitle(
        title = UIDevice.currentDevice.systemName,
        message = message,
        preferredStyle = UIAlertControllerStyle.MAX_VALUE
    )
    alertController.addAction(
        UIAlertAction.actionWithTitle(
            "OK",
            style = UIAlertActionStyle.MAX_VALUE,
            handler = null
        )
    )
    val viewController = UIApplication.sharedApplication.keyWindow?.rootViewController
    viewController?.presentViewController(alertController, animated = true, completion = null)
}

@Composable
internal actual fun ShareManager(title: String, videoUrl: String) {
    val viewController = UIApplication.sharedApplication.keyWindow?.rootViewController
    val activityItems = listOf("$title: $videoUrl")
    val activityViewController = UIActivityViewController(activityItems, null)
    viewController?.presentViewController(activityViewController, true, null)
}
@Composable
internal actual fun ShortsVideoPlayer(url: String?) {
    val player = remember { AVPlayer(uRL = NSURL.URLWithString(url.orEmpty())!!) }
    val playerLayer = remember { AVPlayerLayer() }
    val avPlayerViewController = remember { AVPlayerViewController() }
    avPlayerViewController.player = player
    avPlayerViewController.showsPlaybackControls = true

    playerLayer.player = player
    // Use a UIKitView to integrate with your existing UIKit views
    UIKitView(
        factory = {
            // Create a UIView to hold the AVPlayerLayer
            val playerContainer = UIView()
            playerContainer.addSubview(avPlayerViewController.view)
            // Return the playerContainer as the root UIView
            playerContainer
        },
        onResize = { view: UIView, rect: CValue<CGRect> ->
            CATransaction.begin()
            CATransaction.setValue(true, kCATransactionDisableActions)
            view.layer.setFrame(rect)
            playerLayer.setFrame(rect)
            avPlayerViewController.view.layer.frame = rect
            CATransaction.commit()
        },
        update = { view ->
            player.play()
            avPlayerViewController.player!!.play()
        },
        modifier = Modifier
    )
}
internal actual fun UserRegion(): String {
    return NSLocale.currentLocale.countryCode ?: "us"
}
@OptIn(BetaInteropApi::class)
@Composable
internal actual fun isConnected(retry: () -> Unit): Boolean{
    val url = NSURL.URLWithString("https://www.google.com")
    val request = NSURLRequest.requestWithURL(url ?: return false)

    val response = memScoped {
        allocPointerTo<ObjCObjectVar<NSURLResponse?>>()
    }
    val error = memScoped {
        allocPointerTo<ObjCObjectVar<NSError?>>()
    }

    val data = NSURLConnection.sendSynchronousRequest(request, response.value, error.value)

    if (data != null) {
        return true
    } else {
        val nsError = error.pointed?.value

        if (nsError != null /*&& nsError.domain == NSErrorDomain*/) {
            return nsError.code != -1009L
        }
    }

    return false
}

actual class DriverFactory actual constructor(){
    actual fun createDriver(): SqlDriver {
        return NativeSqliteDriver(YoutubeDatabase.Schema,"YouTubeDatabase.db")
    }
}

Now there is all of the errors resolved then when i'm trying to rebuild the project its leading to another errors:
Screenshot 2024-03-05 at 22 07 34

After doing a lot of workaround the project still errors when i try to build

PS: i'm also register a new gradle task for temporary workaround which related with composeApp:testClasses error task("testClasses")

@KhubaibKhan4
Copy link
Owner

@rhonyabdullah Thanks for providing the details.

First of all, the Napier contains some issues but you can still run the apps. :composeApp:iosArm64Main: Could not resolve io.github.aakira:napier:2.7.0. Required by: project :composeApp

Further more, you need to imports the iOS Stuff by yourself. And you are getting some issues related to web app about the cashapp drivers, Basically you need to install npm and build this then it will work fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants