Skip to content

Commit a32b4cb

Browse files
committed
Re-enable CSS compilation in Android app build script
1 parent 85a0173 commit a32b4cb

File tree

1 file changed

+37
-7
lines changed

1 file changed

+37
-7
lines changed

scripts/build-android-app.sh

Lines changed: 37 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ TMPDIR="${TMPDIR:-/tmp}"
1414
TMPDIR="${TMPDIR%/}"
1515
DOWNLOAD_DIR="${TMPDIR%/}/codenameone-tools"
1616
ENV_DIR="$DOWNLOAD_DIR/tools"
17+
EXTRA_MVN_ARGS=("$@")
1718

1819
ensure_workspace() {
1920
local attempt
@@ -76,18 +77,24 @@ GROUP_ID="com.codenameone.examples"
7677
ARTIFACT_ID="hello-codenameone"
7778
MAIN_NAME="HelloCodenameOne"
7879

80+
LOCAL_MAVEN_REPO="${LOCAL_MAVEN_REPO:-$HOME/.m2/repository}"
81+
log "Using local Maven repository at $LOCAL_MAVEN_REPO"
82+
MAVEN_CMD=("$MAVEN_HOME/bin/mvn" -Dmaven.repo.local="$LOCAL_MAVEN_REPO")
83+
7984
log "Generating Codename One application skeleton"
80-
"$MAVEN_HOME/bin/mvn" -q archetype:generate \
85+
"${MAVEN_CMD[@]}" -q --offline archetype:generate \
8186
-DarchetypeArtifactId=cn1app-archetype \
8287
-DarchetypeGroupId=com.codenameone \
8388
-DarchetypeVersion="$CN1_VERSION" \
89+
-DarchetypeCatalog=local \
8490
-DgroupId="$GROUP_ID" \
8591
-DartifactId="$ARTIFACT_ID" \
8692
-Dversion=1.0-SNAPSHOT \
8793
-DmainName="$MAIN_NAME" \
8894
-DinteractiveMode=false \
8995
-Dpackage="$GROUP_ID.$MAIN_NAME" \
90-
-DoutputDirectory="$WORK_DIR"
96+
-DoutputDirectory="$WORK_DIR" \
97+
"${EXTRA_MVN_ARGS[@]}"
9198

9299
APP_DIR="$WORK_DIR/$ARTIFACT_ID"
93100
if [ ! -d "$APP_DIR" ]; then
@@ -147,7 +154,7 @@ public class ${MAIN_NAME} {
147154
HELLOEOF
148155

149156
SETTINGS_FILE="$APP_DIR/common/codenameone_settings.properties"
150-
log "Disabling Codename One CSS compilation for headless build environment"
157+
log "Ensuring Codename One CSS compilation is enabled"
151158
if [ -f "$SETTINGS_FILE" ]; then
152159
if grep -q '^codename1.cssTheme=' "$SETTINGS_FILE"; then
153160
python3 - "$SETTINGS_FILE" <<'PY'
@@ -157,18 +164,41 @@ import sys
157164
158165
path = pathlib.Path(sys.argv[1])
159166
text = path.read_text()
160-
text = re.sub(r'^codename1\.cssTheme=.*$', 'codename1.cssTheme=false', text, flags=re.MULTILINE)
167+
replacement = 'codename1.cssTheme=true'
168+
if re.search(r'^codename1\.cssTheme=', text, flags=re.MULTILINE):
169+
text = re.sub(r'^codename1\.cssTheme=.*$', replacement, text, flags=re.MULTILINE)
170+
else:
171+
text = text + ('\n' if not text.endswith('\n') else '') + replacement + '\n'
161172
path.write_text(text if text.endswith('\n') else text + '\n')
162173
PY
163174
else
164-
printf '\ncodename1.cssTheme=false\n' >> "$SETTINGS_FILE"
175+
printf '\ncodename1.cssTheme=true\n' >> "$SETTINGS_FILE"
165176
fi
166177
else
167-
printf 'codename1.cssTheme=false\n' > "$SETTINGS_FILE"
178+
printf 'codename1.cssTheme=true\n' > "$SETTINGS_FILE"
168179
fi
169180

181+
CSS_DIR="$APP_DIR/common/src/main/css"
182+
mkdir -p "$CSS_DIR"
183+
THEME_CSS="$CSS_DIR/theme.css"
184+
if [ ! -f "$THEME_CSS" ]; then
185+
cat > "$THEME_CSS" <<'CSSEOF'
186+
/* Minimal CSS to ensure the theme compiles during automated builds */
187+
Form {
188+
background-color: #ffffff;
189+
}
190+
191+
Label {
192+
font-size: 2mm;
193+
}
194+
CSSEOF
195+
fi
196+
197+
log "Compiling Codename One CSS theme"
198+
xvfb-run -a "${MAVEN_CMD[@]}" -q --offline -f "$APP_DIR/pom.xml" codenameone:css "${EXTRA_MVN_ARGS[@]}"
199+
170200
log "Building Android gradle project using Codename One port"
171-
"$MAVEN_HOME/bin/mvn" -q -f "$APP_DIR/pom.xml" package -DskipTests -Dcodename1.platform=android -Dcodename1.buildTarget=android-source -Dopen=false "$@"
201+
xvfb-run -a "${MAVEN_CMD[@]}" -q --offline -f "$APP_DIR/pom.xml" package -DskipTests -Dcodename1.platform=android -Dcodename1.buildTarget=android-source -Dopen=false "${EXTRA_MVN_ARGS[@]}"
172202

173203
GRADLE_PROJECT_DIR=$(find "$APP_DIR/target" -maxdepth 1 -type d -name "*-android-source" | head -n 1 || true)
174204
if [ -z "$GRADLE_PROJECT_DIR" ]; then

0 commit comments

Comments
 (0)