diff --git a/iOS/.env.template b/.env.template similarity index 100% rename from iOS/.env.template rename to .env.template diff --git a/Android/README.md b/Android/README.md index 3f33970..cfcfb21 100644 --- a/Android/README.md +++ b/Android/README.md @@ -14,14 +14,16 @@ If you'd like to just view the app, it is available in the [Play store](https:// ### Building and Running the App in Android Studio 1. In your [Ditto portal](https://portal.ditto.live), create an app to generate a Database ID, development token, and URL. -2. Clone this repo to a location on your machine, and open in Android Studio. -3. Create a `local.properties` file or if you already have one, open it. -4. In the `local.properties` file add the following entries (keep the quotes): +2. Clone this repo to a location on your machine, and open the `Android` project in Android Studio. +3. From the **repository root**, run `cp .env.template .env`. This `.env` is shared by the iOS and +Android apps. +4. Edit `.env` to add the values from the portal (no quotes): ``` -dittoDatabaseId="replace-with-your-database-id" -dittoDevelopmentToken="replace-with-your-development-token" -dittoUrl="replace-with-your-url" +DITTO_DATABASE_ID=replace-with-your-database-id +DITTO_DEVELOPMENT_TOKEN=replace-with-your-development-token +DITTO_URL=replace-with-your-url ``` -5. Hit the green play button to run the app +5. Hit the green play button to run the app. (Android Studio manages `local.properties` for the +Android SDK location; credentials no longer go there.) Compatible with Android Automotive OS (AAOS) \ No newline at end of file diff --git a/Android/app/build.gradle.kts b/Android/app/build.gradle.kts index baadec4..9f76a3e 100644 --- a/Android/app/build.gradle.kts +++ b/Android/app/build.gradle.kts @@ -28,23 +28,24 @@ android { useSupportLibrary = true } - // Load Ditto API keys + // Load Ditto credentials from the shared repo-root .env. Values there + // are unquoted, so wrap each in quotes for the generated BuildConfig. buildConfigField( "String", "DITTO_DATABASE_ID", - getLocalProperty("dittoDatabaseId") + "\"${dittoEnv("DITTO_DATABASE_ID")}\"" ) buildConfigField( "String", "DITTO_DEVELOPMENT_TOKEN", - getLocalProperty("dittoDevelopmentToken") + "\"${dittoEnv("DITTO_DEVELOPMENT_TOKEN")}\"" ) buildConfigField( "String", "DITTO_URL", - getLocalProperty("dittoUrl") + "\"${dittoEnv("DITTO_URL")}\"" ) } @@ -139,16 +140,17 @@ kapt { correctErrorTypes = true } -fun getLocalProperty(key: String, file: String = "local.properties"): String { +// Reads a value from the shared repo-root .env — the single source of truth +// for Ditto credentials across the iOS and Android apps. Values are unquoted. +fun dittoEnv(key: String): String { + val envFile = File(rootProject.projectDir.parentFile, ".env") + if (!envFile.isFile) { + error("Shared .env not found at ${envFile.absolutePath}. Copy .env.template to .env at the repo root.") + } val properties = Properties() - val localProperties = File(file) - if (localProperties.isFile) { - InputStreamReader(FileInputStream(localProperties), Charsets.UTF_8).use { reader -> - properties.load(reader) - } - } else { - error("File not found") + InputStreamReader(FileInputStream(envFile), Charsets.UTF_8).use { reader -> + properties.load(reader) } - return properties.getProperty(key) + ?: error("Missing \"$key\" in ${envFile.absolutePath}") } diff --git a/iOS/DittoPOS.xcodeproj/project.pbxproj b/iOS/DittoPOS.xcodeproj/project.pbxproj index 6427261..e4470ee 100644 --- a/iOS/DittoPOS.xcodeproj/project.pbxproj +++ b/iOS/DittoPOS.xcodeproj/project.pbxproj @@ -409,7 +409,7 @@ ); inputPaths = ( "$(SRCROOT)/buildEnv.sh", - "$(SRCROOT)/.env", + "$(SRCROOT)/../.env", ); name = "Generate Env.swift"; outputFileListPaths = ( @@ -419,7 +419,7 @@ ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; - shellScript = "\"${SRCROOT}/buildEnv.sh\" \"${SRCROOT}/.env\" \"${SRCROOT}/${PROJECT}\"\n"; + shellScript = "\"${SRCROOT}/buildEnv.sh\" \"${SRCROOT}/../.env\" \"${SRCROOT}/${PROJECT}\"\n"; }; /* End PBXShellScriptBuildPhase section */ diff --git a/iOS/README.md b/iOS/README.md index 08ce92c..b71fd13 100644 --- a/iOS/README.md +++ b/iOS/README.md @@ -16,15 +16,16 @@ If you'd like to just view the app, it is available in the [app store](https://a 1. Clone this repo to a location on your machine, and open in Xcode. 2. Navigate to the project `Signing & Capabilities` tab and modify the `Team and Bundle Identifier` settings to your Apple developer account credentials to provision building to your device. -3. In your [Ditto portal](https://portal.ditto.live), create an app to generate an App ID and -playground token. -4. In Terminal, run `cp .env.template .env` at the Xcode project root directory. -5. Edit `.env` to add environment variables from the portal as in the following example: +3. In your [Ditto portal](https://portal.ditto.live), create an app to generate a Database ID, +development token, and URL. +4. In Terminal, from the **repository root** run `cp .env.template .env`. This `.env` is shared by the +iOS and Android apps. +5. Edit `.env` to add the values from the portal (no quotes): ``` bash -DITTO_APP_ID=replace_with_your_app_id -DITTO_PLAYGROUND_TOKEN=replace_with_your_playground_token -DITTO_WEBSOCKET_URL=replace_with_your_websocket_url +DITTO_DATABASE_ID=replace_with_your_database_id +DITTO_DEVELOPMENT_TOKEN=replace_with_your_development_token +DITTO_URL=replace_with_your_url ``` -6. Clean (**Command + Shift + K**), then build (**Command + B**). This will generate `Env.swift`. -The project is now configured for the portal app. +6. Clean (**Command + Shift + K**), then build (**Command + B**). This generates `Env.swift` from the +root `.env`. The project is now configured for the portal app.