Skip to content

Commit 2abaf8e

Browse files
committed
fix: Android CI not working
1 parent e02922a commit 2abaf8e

File tree

2 files changed

+58
-5
lines changed

2 files changed

+58
-5
lines changed

android/build.sh

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,45 @@ EOF
9696
echo "----------------------------------------"
9797
fi
9898

99+
if [ "$CIRCLECI" = "true" ]; then
100+
echo "=== Preparing Writable Flutter Gradle Tools for Nix Build ==="
101+
102+
# Check if Flutter is present before using it
103+
if ! command -v flutter &> /dev/null; then
104+
echo "ERROR: Flutter command not found, cannot determine SDK path."
105+
exit 1
106+
fi
107+
108+
# Reliably get the Flutter SDK path from the flutter tool itself
109+
FLUTTER_SDK_PATH=$(flutter --version | grep 'Flutter version' | sed 's/.* at //')
110+
if [ -z "$FLUTTER_SDK_PATH" ]; then
111+
echo "ERROR: Could not determine Flutter SDK path."
112+
exit 1
113+
fi
114+
echo "Found Flutter SDK at: $FLUTTER_SDK_PATH"
115+
116+
# Define a writable path within the workspace
117+
WRITABLE_FLUTTER_TOOLS_GRADLE_PATH="$WORK_DIR/writable_flutter_tools_gradle"
118+
mkdir -p "$WRITABLE_FLUTTER_TOOLS_GRADLE_PATH"
119+
120+
# Copy the Flutter Gradle tools to the writable location
121+
echo "Copying Flutter Gradle tools to $WRITABLE_FLUTTER_TOOLS_GRADLE_PATH..."
122+
cp -rL "$FLUTTER_SDK_PATH/packages/flutter_tools/gradle/." "$WRITABLE_FLUTTER_TOOLS_GRADLE_PATH/"
123+
124+
# Add a Gradle property pointing to this new directory.
125+
# We use flutterToolsGradleDir to match the property in settings.gradle
126+
export GRADLE_OPTS="$GRADLE_OPTS -PflutterToolsGradleDir=$WRITABLE_FLUTTER_TOOLS_GRADLE_PATH"
127+
128+
# Re-apply to FLUTTER_GRADLE_OPTS for CircleCI environment
129+
if [ "$CIRCLECI" = "true" ]; then
130+
export FLUTTER_GRADLE_OPTS="$GRADLE_OPTS"
131+
fi
132+
133+
echo "Writable Flutter Gradle tools prepared."
134+
echo "Updated GRADLE_OPTS: $GRADLE_OPTS"
135+
echo "============================================================"
136+
fi
137+
99138
# Create a local gradle wrapper properties to ensure consistent Gradle version
100139
mkdir -p "$WORK_DIR/gradle/wrapper"
101140
if [ ! -f "$WORK_DIR/gradle/wrapper/gradle-wrapper.properties" ]; then

android/settings.gradle

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,27 @@
11
pluginManagement {
22
def flutterSdkPath = {
33
def properties = new Properties()
4-
file("local.properties").withInputStream { properties.load(it) }
5-
def flutterSdkPath = properties.getProperty("flutter.sdk")
6-
assert flutterSdkPath != null, "flutter.sdk not set in local.properties"
7-
return flutterSdkPath
4+
// Make reading local.properties safer for CI environments
5+
def localPropertiesFile = new File(rootDir, "local.properties")
6+
if (localPropertiesFile.exists()) {
7+
localPropertiesFile.withInputStream { properties.load(it) }
8+
}
9+
def sdkPath = properties.getProperty("flutter.sdk")
10+
assert sdkPath != null, "flutter.sdk not set in local.properties. Please create this file."
11+
return sdkPath
812
}()
913

10-
includeBuild("$flutterSdkPath/packages/flutter_tools/gradle")
14+
def flutterToolsGradlePath
15+
// In CI/Nix, we pass a property pointing to a writable copy.
16+
if (settings.hasProperty('flutterToolsGradleDir')) {
17+
flutterToolsGradlePath = settings['flutterToolsGradleDir']
18+
} else {
19+
// For local development, use the default path inside the SDK.
20+
flutterToolsGradlePath = new File(flutterSdkPath, 'packages/flutter_tools/gradle')
21+
}
22+
23+
// Use the determined path
24+
includeBuild(flutterToolsGradlePath)
1125

1226
repositories {
1327
google()

0 commit comments

Comments
 (0)