Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
File renamed without changes.
16 changes: 9 additions & 7 deletions Android/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
28 changes: 15 additions & 13 deletions Android/app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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")}\""
)
}

Expand Down Expand Up @@ -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}")
}
4 changes: 2 additions & 2 deletions iOS/DittoPOS.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@
);
inputPaths = (
"$(SRCROOT)/buildEnv.sh",
"$(SRCROOT)/.env",
"$(SRCROOT)/../.env",
);
name = "Generate Env.swift";
outputFileListPaths = (
Expand All @@ -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 */

Expand Down
19 changes: 10 additions & 9 deletions iOS/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.