Skip to content

Commit 4cccafb

Browse files
committed
Remove iOS example app files and update dependencies
- Deleted LaunchScreen.storyboard and Main.storyboard from iOS example app. - Removed GeneratedPluginRegistrant.h and GeneratedPluginRegistrant.m files. - Deleted Info.plist and Runner-Bridging-Header.h from iOS example app. - Removed RunnerProfile.entitlements and main.dart from iOS example app. - Cleaned up pubspec.lock and pubspec.yaml by removing example app dependencies. - Added PowerShell script to run Flutter with environment variables from .env file. - Updated pubspec.yaml to include countly_flutter dependency.
1 parent 104beaf commit 4cccafb

96 files changed

Lines changed: 1599 additions & 2462 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/build.yml

Lines changed: 236 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,236 @@
1+
name: Build & Release
2+
3+
on:
4+
push:
5+
branches: [ main, master ]
6+
tags: [ 'v*' ]
7+
pull_request:
8+
branches: [ main, master ]
9+
workflow_dispatch:
10+
11+
env:
12+
FLUTTER_VERSION: '3.27.0'
13+
14+
jobs:
15+
# Validate secrets exist
16+
check-secrets:
17+
runs-on: ubuntu-latest
18+
steps:
19+
- name: Check required secrets
20+
run: |
21+
if [ -z "${{ secrets.COUNTLY_SERVER_URL }}" ]; then
22+
echo "⚠️ Warning: COUNTLY_SERVER_URL secret not set. Analytics will be disabled."
23+
else
24+
echo "✅ COUNTLY_SERVER_URL secret is configured"
25+
fi
26+
27+
if [ -z "${{ secrets.COUNTLY_APP_KEY }}" ]; then
28+
echo "⚠️ Warning: COUNTLY_APP_KEY secret not set. Analytics will be disabled."
29+
else
30+
echo "✅ COUNTLY_APP_KEY secret is configured (masked)"
31+
fi
32+
continue-on-error: true
33+
34+
# Android Build
35+
build-android:
36+
runs-on: ubuntu-latest
37+
needs: check-secrets
38+
steps:
39+
- uses: actions/checkout@v4
40+
41+
- name: Setup Flutter
42+
uses: subosito/flutter-action@v2
43+
with:
44+
flutter-version: ${{ env.FLUTTER_VERSION }}
45+
channel: 'stable'
46+
47+
- name: Install dependencies
48+
run: flutter pub get
49+
50+
- name: Build APK (with encrypted analytics)
51+
env:
52+
COUNTLY_SERVER_URL: ${{ secrets.COUNTLY_SERVER_URL }}
53+
COUNTLY_APP_KEY: ${{ secrets.COUNTLY_APP_KEY }}
54+
run: |
55+
# Mask secrets in logs (GitHub does this automatically, but we double-check)
56+
echo "::add-mask::$COUNTLY_APP_KEY"
57+
echo "Building with analytics configured..."
58+
flutter build apk --release \
59+
--dart-define=COUNTLY_SERVER_URL="$COUNTLY_SERVER_URL" \
60+
--dart-define=COUNTLY_APP_KEY="$COUNTLY_APP_KEY" 2>&1 | grep -v "$COUNTLY_APP_KEY" || true
61+
62+
- name: Build AppBundle (with encrypted analytics)
63+
env:
64+
COUNTLY_SERVER_URL: ${{ secrets.COUNTLY_SERVER_URL }}
65+
COUNTLY_APP_KEY: ${{ secrets.COUNTLY_APP_KEY }}
66+
run: |
67+
echo "::add-mask::$COUNTLY_APP_KEY"
68+
flutter build appbundle --release \
69+
--dart-define=COUNTLY_SERVER_URL="$COUNTLY_SERVER_URL" \
70+
--dart-define=COUNTLY_APP_KEY="$COUNTLY_APP_KEY" 2>&1 | grep -v "$COUNTLY_APP_KEY" || true
71+
72+
- name: Upload APK
73+
uses: actions/upload-artifact@v4
74+
with:
75+
name: android-apk
76+
path: build/app/outputs/flutter-apk/app-release.apk
77+
78+
# iOS Build (macOS required)
79+
build-ios:
80+
runs-on: macos-latest
81+
needs: check-secrets
82+
steps:
83+
- uses: actions/checkout@v4
84+
85+
- name: Setup Flutter
86+
uses: subosito/flutter-action@v2
87+
with:
88+
flutter-version: ${{ env.FLUTTER_VERSION }}
89+
channel: 'stable'
90+
91+
- name: Install dependencies
92+
run: flutter pub get
93+
94+
- name: Build iOS (no codesign for testing)
95+
env:
96+
COUNTLY_SERVER_URL: ${{ secrets.COUNTLY_SERVER_URL }}
97+
COUNTLY_APP_KEY: ${{ secrets.COUNTLY_APP_KEY }}
98+
run: |
99+
echo "::add-mask::$COUNTLY_APP_KEY"
100+
flutter build ios --release --no-codesign \
101+
--dart-define=COUNTLY_SERVER_URL="$COUNTLY_SERVER_URL" \
102+
--dart-define=COUNTLY_APP_KEY="$COUNTLY_APP_KEY" 2>&1 | grep -v "$COUNTLY_APP_KEY" || true
103+
104+
# Windows Build
105+
build-windows:
106+
runs-on: windows-latest
107+
needs: check-secrets
108+
steps:
109+
- uses: actions/checkout@v4
110+
111+
- name: Setup Flutter
112+
uses: subosito/flutter-action@v2
113+
with:
114+
flutter-version: ${{ env.FLUTTER_VERSION }}
115+
channel: 'stable'
116+
117+
- name: Install dependencies
118+
run: flutter pub get
119+
120+
- name: Build Windows
121+
env:
122+
COUNTLY_SERVER_URL: ${{ secrets.COUNTLY_SERVER_URL }}
123+
COUNTLY_APP_KEY: ${{ secrets.COUNTLY_APP_KEY }}
124+
run: |
125+
$key = $env:COUNTLY_APP_KEY
126+
Write-Host "::add-mask::$key"
127+
flutter build windows --release `
128+
--dart-define=COUNTLY_SERVER_URL="$env:COUNTLY_SERVER_URL" `
129+
--dart-define=COUNTLY_APP_KEY="$key" 2>&1 | Select-String -Pattern $key -NotMatch
130+
131+
- name: Upload Windows Build
132+
uses: actions/upload-artifact@v4
133+
with:
134+
name: windows-build
135+
path: build/windows/x64/runner/Release/
136+
137+
# Linux Build
138+
build-linux:
139+
runs-on: ubuntu-latest
140+
needs: check-secrets
141+
steps:
142+
- uses: actions/checkout@v4
143+
144+
- name: Install Linux dependencies
145+
run: |
146+
sudo apt-get update
147+
sudo apt-get install -y clang cmake ninja-build pkg-config libgtk-3-dev liblzma-dev libstdc++-12-dev
148+
149+
- name: Setup Flutter
150+
uses: subosito/flutter-action@v2
151+
with:
152+
flutter-version: ${{ env.FLUTTER_VERSION }}
153+
channel: 'stable'
154+
155+
- name: Install dependencies
156+
run: flutter pub get
157+
158+
- name: Build Linux
159+
env:
160+
COUNTLY_SERVER_URL: ${{ secrets.COUNTLY_SERVER_URL }}
161+
COUNTLY_APP_KEY: ${{ secrets.COUNTLY_APP_KEY }}
162+
run: |
163+
echo "::add-mask::$COUNTLY_APP_KEY"
164+
flutter build linux --release \
165+
--dart-define=COUNTLY_SERVER_URL="$COUNTLY_SERVER_URL" \
166+
--dart-define=COUNTLY_APP_KEY="$COUNTLY_APP_KEY" 2>&1 | grep -v "$COUNTLY_APP_KEY" || true
167+
168+
- name: Upload Linux Build
169+
uses: actions/upload-artifact@v4
170+
with:
171+
name: linux-build
172+
path: build/linux/x64/release/bundle/
173+
174+
# macOS Build
175+
build-macos:
176+
runs-on: macos-latest
177+
needs: check-secrets
178+
steps:
179+
- uses: actions/checkout@v4
180+
181+
- name: Setup Flutter
182+
uses: subosito/flutter-action@v2
183+
with:
184+
flutter-version: ${{ env.FLUTTER_VERSION }}
185+
channel: 'stable'
186+
187+
- name: Install dependencies
188+
run: flutter pub get
189+
190+
- name: Build macOS
191+
env:
192+
COUNTLY_SERVER_URL: ${{ secrets.COUNTLY_SERVER_URL }}
193+
COUNTLY_APP_KEY: ${{ secrets.COUNTLY_APP_KEY }}
194+
run: |
195+
echo "::add-mask::$COUNTLY_APP_KEY"
196+
flutter build macos --release \
197+
--dart-define=COUNTLY_SERVER_URL="$COUNTLY_SERVER_URL" \
198+
--dart-define=COUNTLY_APP_KEY="$COUNTLY_APP_KEY" 2>&1 | grep -v "$COUNTLY_APP_KEY" || true
199+
200+
- name: Upload macOS Build
201+
uses: actions/upload-artifact@v4
202+
with:
203+
name: macos-build
204+
path: build/macos/Build/Products/Release/
205+
206+
# Web Build
207+
build-web:
208+
runs-on: ubuntu-latest
209+
needs: check-secrets
210+
steps:
211+
- uses: actions/checkout@v4
212+
213+
- name: Setup Flutter
214+
uses: subosito/flutter-action@v2
215+
with:
216+
flutter-version: ${{ env.FLUTTER_VERSION }}
217+
channel: 'stable'
218+
219+
- name: Install dependencies
220+
run: flutter pub get
221+
222+
- name: Build Web
223+
env:
224+
COUNTLY_SERVER_URL: ${{ secrets.COUNTLY_SERVER_URL }}
225+
COUNTLY_APP_KEY: ${{ secrets.COUNTLY_APP_KEY }}
226+
run: |
227+
echo "::add-mask::$COUNTLY_APP_KEY"
228+
flutter build web --release \
229+
--dart-define=COUNTLY_SERVER_URL="$COUNTLY_SERVER_URL" \
230+
--dart-define=COUNTLY_APP_KEY="$COUNTLY_APP_KEY" 2>&1 | grep -v "$COUNTLY_APP_KEY" || true
231+
232+
- name: Upload Web Build
233+
uses: actions/upload-artifact@v4
234+
with:
235+
name: web-build
236+
path: build/web/

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ migrate_working_dir/
1414
musly-1.0.4-setup.exe
1515
.claude/
1616
/discord_sdk_temp
17+
# lib/services/analytics_service.dart
18+
.env
1719

1820
# IntelliJ related
1921
*.iml

build_release.ps1

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# Build release version with environment variables from .env file
2+
# Usage: .\build_release.ps1 [apk|appbundle|ios|windows|linux|macos|web]
3+
4+
param(
5+
[string]$Target = "apk"
6+
)
7+
8+
# Read .env file
9+
$envFile = ".env"
10+
if (Test-Path $envFile) {
11+
Get-Content $envFile | ForEach-Object {
12+
if ($_ -match '^(.+?)=(.+)$') {
13+
$name = $matches[1].Trim()
14+
$value = $matches[2].Trim()
15+
if ($value.StartsWith('"') -and $value.EndsWith('"')) {
16+
$value = $value.Substring(1, $value.Length - 2)
17+
}
18+
[Environment]::SetEnvironmentVariable($name, $value, "Process")
19+
Write-Host "Loaded: $name = ***" -ForegroundColor DarkGray
20+
}
21+
}
22+
Write-Host "Environment variables loaded from .env" -ForegroundColor Green
23+
} else {
24+
Write-Error ".env file not found!"
25+
exit 1
26+
}
27+
28+
# Build dart-define arguments
29+
$defines = @()
30+
if ($env:COUNTLY_SERVER_URL) {
31+
$defines += "--dart-define=COUNTLY_SERVER_URL=`"$env:COUNTLY_SERVER_URL`""
32+
}
33+
if ($env:COUNTLY_APP_KEY) {
34+
$defines += "--dart-define=COUNTLY_APP_KEY=`"$env:COUNTLY_APP_KEY`""
35+
}
36+
37+
# Build based on target
38+
$cmd = ""
39+
switch ($Target.ToLower()) {
40+
"apk" { $cmd = "flutter build apk --release" }
41+
"appbundle" { $cmd = "flutter build appbundle --release" }
42+
"ios" { $cmd = "flutter build ios --release" }
43+
"windows" { $cmd = "flutter build windows --release" }
44+
"linux" { $cmd = "flutter build linux --release" }
45+
"macos" { $cmd = "flutter build macos --release" }
46+
"web" { $cmd = "flutter build web --release" }
47+
default {
48+
Write-Error "Unknown target: $Target"
49+
Write-Host "Valid targets: apk, appbundle, ios, windows, linux, macos, web"
50+
exit 1
51+
}
52+
}
53+
54+
Write-Host "Building: $cmd with dart-defines" -ForegroundColor Cyan
55+
& flutter build $Target --release @defines
56+
57+
if ($LASTEXITCODE -eq 0) {
58+
Write-Host "Build completed successfully!" -ForegroundColor Green
59+
} else {
60+
Write-Error "Build failed!"
61+
}

lib/config/analytics_config.dart

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import 'dart:io';
2+
3+
/// Analytics configuration - loaded from environment variables during build
4+
///
5+
/// This file uses compile-time environment variables to inject the Countly
6+
/// app key securely. The actual values are never stored in the repository.
7+
///
8+
/// Setup instructions:
9+
/// 1. Create a `.env` file locally (add to .gitignore!)
10+
/// 2. Set environment variables in CI/CD (GitHub Actions secrets)
11+
/// 3. Use --dart-define during build
12+
///
13+
/// Example build command:
14+
/// flutter build apk --dart-define=COUNTLY_APP_KEY=your_key --dart-define=COUNTLY_SERVER_URL=your_url
15+
class AnalyticsConfig {
16+
/// Countly server URL
17+
///
18+
/// Set via: --dart-define=COUNTLY_SERVER_URL=https://your-countly.com
19+
/// Fallback for development (should be empty in production)
20+
static const String serverUrl = String.fromEnvironment(
21+
'COUNTLY_SERVER_URL',
22+
defaultValue: '',
23+
);
24+
25+
/// Countly app key
26+
///
27+
/// Set via: --dart-define=COUNTLY_APP_KEY=your_app_key_here
28+
/// Fallback for development (should be empty in production)
29+
static const String appKey = String.fromEnvironment(
30+
'COUNTLY_APP_KEY',
31+
defaultValue: '',
32+
);
33+
34+
/// Check if analytics is properly configured
35+
static bool get isConfigured => serverUrl.isNotEmpty && appKey.isNotEmpty;
36+
37+
/// Get a masked version of the app key for logging
38+
static String get maskedAppKey {
39+
if (appKey.length < 8) return '***';
40+
return '${appKey.substring(0, 4)}...${appKey.substring(appKey.length - 4)}';
41+
}
42+
}
43+
44+
/// Development configuration (for local testing only)
45+
///
46+
/// NEVER commit this with real values!
47+
/// Add to .gitignore:
48+
/// - lib/config/analytics_config_dev.dart
49+
/// - .env
50+
class AnalyticsConfigDev {
51+
/// Use this only for local development
52+
/// Load from .env file or local environment variables
53+
static String? get serverUrl => Platform.environment['COUNTLY_SERVER_URL'];
54+
static String? get appKey => Platform.environment['COUNTLY_APP_KEY'];
55+
}

0 commit comments

Comments
 (0)