Skip to content

Commit a45545c

Browse files
committed
fix(ci): use proper Flutter --analyze-size according to docs
- Remove --release flag (--analyze-size implies release mode) - Add flutter clean before build to ensure fresh analysis - Simplify JSON search to primary location: build/apk-code-size-analysis_01.json - Remove unnecessary directory creation - Follow Flutter official documentation pattern - Should resolve snapshot.arm64-v8a.json PathNotFoundException
1 parent 704042f commit a45545c

File tree

2 files changed

+43
-67
lines changed

2 files changed

+43
-67
lines changed

.github/workflows/build-develop-apk.yml

Lines changed: 13 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -102,12 +102,11 @@ jobs:
102102
run: |
103103
echo "Building APK for develop branch with size analysis..."
104104
105-
# Create required directories for size analysis
106-
mkdir -p build/flutter_size_01
107-
mkdir -p $HOME/.flutter-devtools
105+
# Clean build directory
106+
flutter clean
108107
109108
# Build APK with size analysis
110-
flutter build apk --release --analyze-size --target-platform android-arm64
109+
flutter build apk --analyze-size --target-platform android-arm64
111110
112111
# Check if APK was built
113112
APK_PATH="build/app/outputs/flutter-apk/app-release.apk"
@@ -124,29 +123,21 @@ jobs:
124123
APK_SIZE=$(du -h "build/app/outputs/flutter-apk/$NEW_APK_NAME" | cut -f1)
125124
echo "apk_size=$APK_SIZE" >> $GITHUB_OUTPUT
126125
127-
# Check for size analysis JSON in multiple locations
126+
# Check for size analysis JSON
128127
echo "🔍 Searching for size analysis JSON..."
129128
SIZE_JSON=""
130129
131-
# Search in common locations with wildcard support
132-
for location in \
133-
"$HOME/.flutter-devtools/apk-code-size-analysis"*".json" \
134-
"build/apk-"*"-release-code-size-analysis"*".json" \
135-
".flutter-devtools/apk-code-size-analysis"*".json" \
136-
"build/flutter_size"*"/apk-code-size-analysis"*".json"
137-
do
138-
if [ -f "$location" ]; then
139-
SIZE_JSON="$location"
140-
echo "✅ Found size analysis JSON: $SIZE_JSON"
141-
break
142-
fi
143-
done
144-
145-
# If still not found, try to find any JSON with size analysis
146-
if [ -z "$SIZE_JSON" ]; then
147-
SIZE_JSON=$(find "$HOME/.flutter-devtools" -name "*size*analysis*.json" -type f 2>/dev/null | head -n 1)
130+
# Primary location according to Flutter docs
131+
if [ -f "build/apk-code-size-analysis_01.json" ]; then
132+
SIZE_JSON="build/apk-code-size-analysis_01.json"
133+
echo "✅ Found size analysis JSON: $SIZE_JSON"
134+
else
135+
# Fallback: search in build directory
136+
SIZE_JSON=$(find build -name "*code-size-analysis*.json" -type f 2>/dev/null | head -n 1)
148137
if [ -n "$SIZE_JSON" ]; then
149138
echo "✅ Found size analysis JSON via search: $SIZE_JSON"
139+
else
140+
echo "⚠️ Size analysis JSON not found in build directory"
150141
fi
151142
fi
152143

.github/workflows/pr-apk-build.yml

Lines changed: 30 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -144,12 +144,12 @@ jobs:
144144
run: |
145145
echo "Building APK for PR #${{ steps.pr_info.outputs.pr_number }} with size analysis..."
146146
147-
# Create required directories for size analysis
148-
mkdir -p build/flutter_size_01
149-
mkdir -p $HOME/.flutter-devtools
147+
# Clean build directory to ensure fresh analysis
148+
flutter clean
150149
151-
# Build APK with size analysis
152-
flutter build apk --release --analyze-size --target-platform android-arm64
150+
# Build APK with size analysis (without --release flag as per Flutter docs)
151+
# The --analyze-size flag automatically builds in release mode
152+
flutter build apk --analyze-size --target-platform android-arm64
153153
154154
# Rename APK with PR info
155155
APK_PATH="build/app/outputs/flutter-apk/app-release.apk"
@@ -164,29 +164,23 @@ jobs:
164164
APK_SIZE=$(du -h "build/app/outputs/flutter-apk/$NEW_APK_NAME" | cut -f1)
165165
echo "apk_size=$APK_SIZE" >> $GITHUB_OUTPUT
166166
167-
# Check for size analysis JSON in multiple locations
167+
# Check for size analysis JSON (Flutter saves it in build directory)
168168
echo "🔍 Searching for size analysis JSON..."
169169
SIZE_JSON=""
170170
171-
# Search in common locations with wildcard support
172-
for location in \
173-
"$HOME/.flutter-devtools/apk-code-size-analysis"*".json" \
174-
"build/apk-"*"-release-code-size-analysis"*".json" \
175-
".flutter-devtools/apk-code-size-analysis"*".json" \
176-
"build/flutter_size"*"/apk-code-size-analysis"*".json"
177-
do
178-
if [ -f "$location" ]; then
179-
SIZE_JSON="$location"
180-
echo "✅ Found size analysis JSON: $SIZE_JSON"
181-
break
182-
fi
183-
done
184-
185-
# If still not found, try to find any JSON with size analysis
186-
if [ -z "$SIZE_JSON" ]; then
187-
SIZE_JSON=$(find "$HOME/.flutter-devtools" -name "*size*analysis*.json" -type f 2>/dev/null | head -n 1)
171+
# Primary location according to Flutter docs
172+
if [ -f "build/apk-code-size-analysis_01.json" ]; then
173+
SIZE_JSON="build/apk-code-size-analysis_01.json"
174+
echo "✅ Found size analysis JSON: $SIZE_JSON"
175+
else
176+
# Fallback: search in build directory
177+
SIZE_JSON=$(find build -name "*code-size-analysis*.json" -type f 2>/dev/null | head -n 1)
188178
if [ -n "$SIZE_JSON" ]; then
189179
echo "✅ Found size analysis JSON via search: $SIZE_JSON"
180+
else
181+
echo "⚠️ Size analysis JSON not found in build directory"
182+
echo "📂 Build directory contents:"
183+
ls -la build/ || true
190184
fi
191185
fi
192186
@@ -264,36 +258,27 @@ jobs:
264258
# Run build_runner
265259
flutter pub run build_runner build --delete-conflicting-outputs || true
266260
267-
# Create required directories for size analysis
268-
mkdir -p build/flutter_size_01
269-
mkdir -p $HOME/.flutter-devtools
261+
# Clean build directory
262+
flutter clean
270263
271264
# Build base APK with size analysis
272-
flutter build apk --release --analyze-size --target-platform android-arm64
265+
flutter build apk --analyze-size --target-platform android-arm64
273266
274-
# Check for size analysis JSON in multiple locations
267+
# Check for size analysis JSON
275268
echo "🔍 Searching for base size analysis JSON..."
276269
BASE_SIZE_JSON=""
277270
278-
# Search in common locations with wildcard support
279-
for location in \
280-
"$HOME/.flutter-devtools/apk-code-size-analysis"*".json" \
281-
"build/apk-"*"-release-code-size-analysis"*".json" \
282-
".flutter-devtools/apk-code-size-analysis"*".json" \
283-
"build/flutter_size"*"/apk-code-size-analysis"*".json"
284-
do
285-
if [ -f "$location" ]; then
286-
BASE_SIZE_JSON="$location"
287-
echo "✅ Found base size analysis JSON: $BASE_SIZE_JSON"
288-
break
289-
fi
290-
done
291-
292-
# If still not found, try to find any JSON with size analysis
293-
if [ -z "$BASE_SIZE_JSON" ]; then
294-
BASE_SIZE_JSON=$(find "$HOME/.flutter-devtools" -name "*size*analysis*.json" -type f 2>/dev/null | head -n 1)
271+
# Primary location according to Flutter docs
272+
if [ -f "build/apk-code-size-analysis_01.json" ]; then
273+
BASE_SIZE_JSON="build/apk-code-size-analysis_01.json"
274+
echo "✅ Found base size analysis JSON: $BASE_SIZE_JSON"
275+
else
276+
# Fallback: search in build directory
277+
BASE_SIZE_JSON=$(find build -name "*code-size-analysis*.json" -type f 2>/dev/null | head -n 1)
295278
if [ -n "$BASE_SIZE_JSON" ]; then
296279
echo "✅ Found base size analysis JSON via search: $BASE_SIZE_JSON"
280+
else
281+
echo "⚠️ Base size analysis JSON not found"
297282
fi
298283
fi
299284

0 commit comments

Comments
 (0)