From e568e7b4e9f7362da672e171b304eefd451cd657 Mon Sep 17 00:00:00 2001 From: HimanshuKumarDutt094 Date: Fri, 17 Oct 2025 09:42:06 +0530 Subject: [PATCH 1/2] fix: devtool instance registration for ios android --- .../app/src/main/java/com/helloworld/MainApplication.kt | 3 +++ packages/helloworld/apple/HelloWorld/AppDelegate.swift | 6 +++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/packages/helloworld/android/app/src/main/java/com/helloworld/MainApplication.kt b/packages/helloworld/android/app/src/main/java/com/helloworld/MainApplication.kt index a228483..1172b31 100644 --- a/packages/helloworld/android/app/src/main/java/com/helloworld/MainApplication.kt +++ b/packages/helloworld/android/app/src/main/java/com/helloworld/MainApplication.kt @@ -9,6 +9,7 @@ import com.facebook.imagepipeline.core.ImagePipelineConfig import com.facebook.imagepipeline.memory.PoolConfig import com.facebook.imagepipeline.memory.PoolFactory import com.lynx.devtoolwrapper.LynxDevtoolGlobalHelper +import com.lynx.service.devtool.LynxDevToolService import com.lynx.service.image.LynxImageService import com.lynx.service.log.LynxLogService import com.lynx.tasm.LynxEnv @@ -31,6 +32,8 @@ class MainApplication : Application() { LynxServiceCenter.inst().registerService(LynxImageService.getInstance()) LynxServiceCenter.inst().registerService(LynxLogService) LynxServiceCenter.inst().registerService(LynxHttpService) + LynxServiceCenter.inst().registerService(LynxDevToolService.INSTANCE) + } private fun initLynxEnv() { diff --git a/packages/helloworld/apple/HelloWorld/AppDelegate.swift b/packages/helloworld/apple/HelloWorld/AppDelegate.swift index a3c2490..044854f 100644 --- a/packages/helloworld/apple/HelloWorld/AppDelegate.swift +++ b/packages/helloworld/apple/HelloWorld/AppDelegate.swift @@ -10,7 +10,11 @@ class AppDelegate: UIResponder, UIApplicationDelegate { // Register new modules with: // config.register(YourModuleName.self) - + lynxEnv.lynxDebugEnabled = true + // Enable Lynx DevTool + lynxEnv.devtoolEnabled = true + // Enable Lynx LogBox + lynxEnv.logBoxEnabled = true lynxEnv.prepareConfig(config) return true From e2d452494174322bf902c29f269edfb7b564a3e7 Mon Sep 17 00:00:00 2001 From: HimanshuKumarDutt094 Date: Fri, 17 Oct 2025 10:38:52 +0530 Subject: [PATCH 2/2] feat: network ip detect and install for physical device development --- .../helloworld/android/app/build.gradle.kts | 3 +- .../main/java/com/helloworld/MainActivity.kt | 3 +- .../apple/HelloWorld/SceneDelegate.swift | 4 +- packages/helloworld/package.json | 80 +++++------ packages/helloworld/scripts/android.sh | 87 ++++++++++++ packages/helloworld/scripts/ios.sh | 124 ++++++++++++++++++ 6 files changed, 259 insertions(+), 42 deletions(-) create mode 100755 packages/helloworld/scripts/android.sh create mode 100755 packages/helloworld/scripts/ios.sh diff --git a/packages/helloworld/android/app/build.gradle.kts b/packages/helloworld/android/app/build.gradle.kts index 2061208..efbe713 100644 --- a/packages/helloworld/android/app/build.gradle.kts +++ b/packages/helloworld/android/app/build.gradle.kts @@ -28,11 +28,12 @@ android { keyPassword = "release-key-password" } } - + val devServerHost = project.findProperty("DEV_SERVER_HOST") as String? ?: "10.0.2.2" buildTypes { debug { isDebuggable = true applicationIdSuffix = ".debug" + buildConfigField("String", "DEV_SERVER_HOST", "\"$devServerHost\"") } release { isMinifyEnabled = true diff --git a/packages/helloworld/android/app/src/main/java/com/helloworld/MainActivity.kt b/packages/helloworld/android/app/src/main/java/com/helloworld/MainActivity.kt index 2a9cbec..8e0b561 100644 --- a/packages/helloworld/android/app/src/main/java/com/helloworld/MainActivity.kt +++ b/packages/helloworld/android/app/src/main/java/com/helloworld/MainActivity.kt @@ -15,7 +15,8 @@ class MainActivity : Activity() { var uri = "" uri = if (BuildConfig.DEBUG == true) { - "http://10.0.2.2:3000/main.lynx.bundle?fullscreen=true" + val devServerHost = BuildConfig.DEV_SERVER_HOST + "http://$devServerHost:3000/main.lynx.bundle?fullscreen=true" } else { "main.lynx.bundle" } diff --git a/packages/helloworld/apple/HelloWorld/SceneDelegate.swift b/packages/helloworld/apple/HelloWorld/SceneDelegate.swift index 209ccc2..1f4d661 100644 --- a/packages/helloworld/apple/HelloWorld/SceneDelegate.swift +++ b/packages/helloworld/apple/HelloWorld/SceneDelegate.swift @@ -27,8 +27,10 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate { rootViewController.view = lynxView #if DEBUG + // Get dev server host from environment variable or use localhost as fallback + let devServerHost = ProcessInfo.processInfo.environment["DEV_SERVER_HOST"] ?? "localhost" lynxView.loadTemplate( - fromURL: "http://localhost:3000/main.lynx.bundle?fullscreen=true", + fromURL: "http://\(devServerHost):3000/main.lynx.bundle?fullscreen=true", initData: nil ) #else diff --git a/packages/helloworld/package.json b/packages/helloworld/package.json index ad4411f..4b662ee 100644 --- a/packages/helloworld/package.json +++ b/packages/helloworld/package.json @@ -1,40 +1,42 @@ { - "name": "HelloWorld", - "version": "1.0.0", - "type": "module", - "scripts": { - "build": "rspeedy build", - "dev": "rspeedy dev", - "format": "prettier --write .", - "lint": "eslint .", - "preview": "rspeedy preview", - "test": "vitest run" - }, - "dependencies": { - "@lynx-js/react": "^0.112.5" - }, - "devDependencies": { - "@eslint/js": "^9.32.0", - "@lynx-js/preact-devtools": "^5.0.1-6664329", - "@lynx-js/qrcode-rsbuild-plugin": "^0.4.1", - "@lynx-js/react-rsbuild-plugin": "^0.10.13", - "@lynx-js/rspeedy": "^0.11.0", - "@lynx-js/types": "3.4.11", - "@rsbuild/plugin-type-check": "1.2.4", - "@testing-library/jest-dom": "^6.8.0", - "@types/react": "^18.3.23", - "eslint": "^9.32.0", - "eslint-plugin-react-hooks": "^5.2.0", - "eslint-plugin-react-refresh": "^0.4.20", - "globals": "^16.3.0", - "jsdom": "^26.1.0", - "prettier": "^3.6.2", - "typescript": "~5.9.2", - "typescript-eslint": "^8.38.0", - "vitest": "^3.2.4" - }, - "engines": { - "node": ">=18" - }, - "private": true -} + "name": "HelloWorld", + "version": "1.0.0", + "type": "module", + "scripts": { + "build": "rspeedy build", + "dev": "rspeedy dev", + "format": "prettier --write .", + "lint": "eslint .", + "preview": "rspeedy preview", + "test": "vitest run", + "install:android": "./scripts/android.sh", + "install:ios": "./scripts/ios.sh" + }, + "dependencies": { + "@lynx-js/react": "^0.112.5" + }, + "devDependencies": { + "@eslint/js": "^9.32.0", + "@lynx-js/preact-devtools": "^5.0.1-6664329", + "@lynx-js/qrcode-rsbuild-plugin": "^0.4.1", + "@lynx-js/react-rsbuild-plugin": "^0.10.13", + "@lynx-js/rspeedy": "^0.11.0", + "@lynx-js/types": "3.4.11", + "@rsbuild/plugin-type-check": "1.2.4", + "@testing-library/jest-dom": "^6.8.0", + "@types/react": "^18.3.23", + "eslint": "^9.32.0", + "eslint-plugin-react-hooks": "^5.2.0", + "eslint-plugin-react-refresh": "^0.4.20", + "globals": "^16.3.0", + "jsdom": "^26.1.0", + "prettier": "^3.6.2", + "typescript": "~5.9.2", + "typescript-eslint": "^8.38.0", + "vitest": "^3.2.4" + }, + "engines": { + "node": ">=18" + }, + "private": true +} \ No newline at end of file diff --git a/packages/helloworld/scripts/android.sh b/packages/helloworld/scripts/android.sh new file mode 100755 index 0000000..0cbd99f --- /dev/null +++ b/packages/helloworld/scripts/android.sh @@ -0,0 +1,87 @@ +#!/bin/bash + +# android.sh - Build Android app with automatic dev server IP detection + +set -e + +# Colors for output +RED='\033[0;31m' +GREEN='\033[0;32m' +YELLOW='\033[1;33m' +NC='\033[0m' # No Color + +echo -e "${GREEN}🔍 Detecting development server IP address...${NC}" + +# Function to detect IP on different platforms +detect_ip() { + if [[ "$OSTYPE" == "linux-gnu"* ]]; then + # Linux + ip -4 addr show $(ip route show default | awk '{print $5}' | head -n1) 2>/dev/null | grep -oP '(?<=inet\s)\d+(\.\d+){3}' | head -n1 + elif [[ "$OSTYPE" == "darwin"* ]]; then + # macOS + route get default | grep interface | awk '{print $2}' | xargs ifconfig | grep -E "inet [0-9]" | grep -v 127.0.0.1 | awk '{print $2}' | head -n1 + elif [[ "$OSTYPE" == "msys" ]] || [[ "$OSTYPE" == "win32" ]]; then + # Windows (Git Bash/MSYS2) + ipconfig | grep -A 5 "Wireless LAN adapter Wi-Fi\|Ethernet adapter" | grep "IPv4 Address" | head -n1 | sed 's/.*: //' + else + echo -e "${YELLOW}⚠️ Unknown OS type: $OSTYPE${NC}" + echo -e "${YELLOW}Please manually specify your IP address${NC}" + return 1 + fi +} + +# Try to detect the IP +DEV_SERVER_IP=$(detect_ip) + +if [ -z "$DEV_SERVER_IP" ]; then + echo -e "${YELLOW}⚠️ Could not automatically detect IP address${NC}" + echo -e "${YELLOW}Please enter your development machine's IP address:${NC}" + read -p "IP Address: " DEV_SERVER_IP + + if [ -z "$DEV_SERVER_IP" ]; then + echo -e "${RED}❌ No IP address provided. Using automatic detection in app.${NC}" + DEV_SERVER_IP="" + fi +fi + +if [ -n "$DEV_SERVER_IP" ]; then + echo -e "${GREEN}✅ Using development server IP: $DEV_SERVER_IP${NC}" +else + echo -e "${YELLOW}⚠️ Will use automatic detection in the app${NC}" +fi + +# Change to Android project directory +cd "android" + +echo -e "${GREEN}🔨 Building Android app...${NC}" + +# Build the debug APK with the detected IP +if [ -n "$DEV_SERVER_IP" ]; then + ./gradlew assembleDebug -PDEV_SERVER_HOST="$DEV_SERVER_IP" +else + ./gradlew assembleDebug +fi + +echo -e "${GREEN}✅ Build complete!${NC}" +echo -e "${GREEN}📱 APK location: android/app/build/outputs/apk/debug/app-debug.apk${NC}" + +# Optionally install the APK if device is connected +if command -v adb &> /dev/null; then + if adb devices | grep -q "device$"; then + echo -e "${YELLOW}📱 Android device detected. Install APK? (y/n):${NC}" + read -p "" install_choice + if [[ $install_choice == "y" || $install_choice == "Y" ]]; then + echo -e "${GREEN}📲 Installing APK...${NC}" + adb install -r app/build/outputs/apk/debug/app-debug.apk + echo -e "${GREEN}✅ APK installed successfully!${NC}" + fi + else + echo -e "${YELLOW}📱 No Android device connected via ADB${NC}" + fi +fi + +if [ -n "$DEV_SERVER_IP" ]; then + echo -e "${GREEN}🚀 Start your development server with:${NC}" + echo -e "${GREEN} cd project && npm run dev${NC}" + echo -e "${GREEN}🌐 Server should be accessible at: http://$DEV_SERVER_IP:3000${NC}" +fi \ No newline at end of file diff --git a/packages/helloworld/scripts/ios.sh b/packages/helloworld/scripts/ios.sh new file mode 100755 index 0000000..4126f9a --- /dev/null +++ b/packages/helloworld/scripts/ios.sh @@ -0,0 +1,124 @@ +#!/bin/bash + +# ios.sh - Build iOS app with automatic dev server IP detection + +set -e + +# Colors for output +RED='\033[0;31m' +GREEN='\033[0;32m' +YELLOW='\033[1;33m' +NC='\033[0m' # No Color + +echo -e "${GREEN}🔍 Detecting development server IP address...${NC}" + +# Function to detect IP on macOS (only platform needed for iOS development) +detect_ip() { + # macOS + route get default | grep interface | awk '{print $2}' | xargs ifconfig | grep -E "inet [0-9]" | grep -v 127.0.0.1 | awk '{print $2}' | head -n1 +} + +# Try to detect the IP +DEV_SERVER_IP=$(detect_ip) + +if [ -z "$DEV_SERVER_IP" ]; then + echo -e "${YELLOW}⚠️ Could not automatically detect IP address${NC}" + echo -e "${YELLOW}Please enter your development server IP address:${NC}" + read -p "IP Address: " DEV_SERVER_IP + + if [ -z "$DEV_SERVER_IP" ]; then + echo -e "${RED}❌ No IP address provided. Using localhost fallback.${NC}" + DEV_SERVER_IP="localhost" + fi +fi + +if [ -n "$DEV_SERVER_IP" ]; then + echo -e "${GREEN}✅ Using development server IP: $DEV_SERVER_IP${NC}" +else + echo -e "${YELLOW}⚠️ Will use localhost fallback${NC}" + DEV_SERVER_IP="localhost" +fi + +# Try to detect the IP +DEV_SERVER_IP=$(detect_ip) + +if [ -z "$DEV_SERVER_IP" ]; then + echo -e "${YELLOW}⚠️ Could not automatically detect IP address${NC}" + echo -e "${YELLOW}Please enter your development machine's IP address:${NC}" + read -p "IP Address: " DEV_SERVER_IP + + if [ -z "$DEV_SERVER_IP" ]; then + echo -e "${RED}❌ No IP address provided. Using localhost fallback.${NC}" + DEV_SERVER_IP="localhost" + fi +fi + +if [ -n "$DEV_SERVER_IP" ]; then + echo -e "${GREEN}✅ Using development server IP: $DEV_SERVER_IP${NC}" +else + echo -e "${YELLOW}⚠️ Will use localhost fallback${NC}" + DEV_SERVER_IP="localhost" +fi + +# Check if we're on macOS (required for iOS development) +if [[ "$OSTYPE" != "darwin"* ]]; then + echo -e "${RED}❌ iOS development requires macOS and Xcode${NC}" + echo -e "${YELLOW}📱 Please run this script on a macOS machine with Xcode installed${NC}" + echo -e "${YELLOW}💡 For now, the iOS app has been configured to use: $DEV_SERVER_IP${NC}" + echo -e "${YELLOW}🔧 You'll need to manually open the Xcode project to build: apple/HelloWorld.xcodeproj${NC}" + exit 1 +fi + +# Change to iOS project directory +cd "apple" + +echo -e "${GREEN}🔨 Building iOS app...${NC}" + +# Build the iOS app with the detected IP +if [ -n "$DEV_SERVER_IP" ]; then + # Set environment variable for the build + export DEV_SERVER_HOST="$DEV_SERVER_IP" + + # Build for iOS simulator (development) + xcodebuild -project HelloWorld.xcodeproj -scheme HelloWorld -destination 'platform=iOS Simulator,name=iPhone 15' clean build + + echo -e "${GREEN}✅ Build complete!${NC}" + echo -e "${GREEN}📱 App built for iOS simulator${NC}" +else + echo -e "${RED}❌ Build failed${NC}" + exit 1 +fi + +# Optionally open iOS simulator and install app if available +if command -v xcrun &> /dev/null; then + echo -e "${YELLOW}📱 Opening iOS Simulator...${NC}" + # Open the default iOS simulator + xcrun simctl boot "iPhone 15" &> /dev/null || true + + # Find the most recently built app in derived data + # The template system will have replaced "HelloWorld" with the actual project name + APP_PATH=$(find ~/Library/Developer/Xcode/DerivedData -name "*.app" -type d -path "*/Build/Products/*" 2>/dev/null | head -n1) + + if [ -n "$APP_PATH" ]; then + echo -e "${YELLOW}📲 Installing app on simulator...${NC}" + # Install the app on the simulator + xcrun simctl install "iPhone 15" "$APP_PATH" + echo -e "${GREEN}✅ App installed successfully on simulator!${NC}" + + echo -e "${YELLOW}🚀 Launching app...${NC}" + # Launch the app (bundle ID will be whatever the template system generated) + xcrun simctl launch "iPhone 15" "$(basename "$APP_PATH" .app)" + else + echo -e "${YELLOW}⚠️ App not found in derived data${NC}" + echo -e "${YELLOW}💡 You can manually launch the app from Xcode${NC}" + echo -e "${YELLOW}🔧 Look for your app in Xcode's Products folder${NC}" + fi +else + echo -e "${YELLOW}📱 xcrun not found. Simulator management skipped${NC}" +fi + +if [ -n "$DEV_SERVER_IP" ]; then + echo -e "${GREEN}🚀 Start your development server with:${NC}" + echo -e "${GREEN} cd project && npm run dev${NC}" + echo -e "${GREEN}🌐 Server should be accessible at: http://$DEV_SERVER_IP:3000${NC}" +fi \ No newline at end of file