hotwired / turbo-android

Android framework for making Turbo native apps
MIT License
423 stars 51 forks source link

Getting demo to work with localhost rails app #221

Closed DanielJackson-Oslo closed 2 years ago

DanielJackson-Oslo commented 2 years ago

Thank you for an excellent contribution to the eco system!

I'm trying to test out turbo-android and turbo-ios in a greenfield Rails 7 app.

For turbo-ios, set up to use localhost was well documented, and easy to do:


struct Demo {
    static let local = URL(string: "http://localhost:3000")!

    static var current: URL {
        local
    }
}

But for turbo-android I haven't managed to get localhost to work, after a few hours of trying, neither with localhost:3000 or a custom local domain dev.local:3000 (however it works fine with an online production rails 7 app I also control):

I've tried to change BASE_URL in Constants.kt

// In Constants.kt
const val BASE_URL = "http://dev.local:3000"

and

// In Constants.kt
const val BASE_URL = "http://localhost:3000"

I get the following error message in the emulator, and while I've tried to look for logs to see what's going on, I'm not very well versed in Android Studio and haven't found anything useful there:

image

Any idea why this might be the case?

svantepolk commented 2 years ago

localhost refers to the emulator itself; you'll probably want to use 10.0.2.2 instead.

https://developer.android.com/studio/run/emulator-networking#networkaddresses

DanielJackson-Oslo commented 2 years ago

Thank you! That worked :)