@@ -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