casimir / frigoligo

Your articles with you
MIT License
37 stars 3 forks source link

Prevent error after fdroid signingConfig stripping #190

Closed casimir closed 1 month ago

casimir commented 1 month ago

It removes the whole signingConfigs block.

diff --git a/android/app/build.gradle b/android/app/build.gradle
index 95627ea..eb79665 100644
--- a/android/app/build.gradle
+++ b/android/app/build.gradle
@@ -59,14 +59,6 @@ android {
         versionName flutterVersionName
     }

-    signingConfigs {
-        release {
-            keyAlias keystoreProperties['keyAlias']
-            keyPassword keystoreProperties['keyPassword']
-            storeFile keystoreProperties['storeFile'] ? file(keystoreProperties['storeFile']) : null
-            storePassword keystoreProperties['storePassword']
-        }
-    }

     buildTypes {
         release {
Involved code (extracted fomr `fdroid` scripts). ```python import os import re gradle_comment = re.compile(r'[ ]*//') gradle_signing_configs = re.compile(r'^[\t ]*signingConfigs[ \t]*{[ \t]*$') gradle_line_matches = [ re.compile(r'^[\t ]*signingConfig\s*[= ]\s*[^ ]*$'), re.compile(r'.*android\.signingConfigs\.[^{]*$'), re.compile(r'.*release\.signingConfig *= *'), ] def remove_signing_keys(build_dir): for root, dirs, files in os.walk(build_dir): gradlefile = None if 'build.gradle' in files: gradlefile = "build.gradle" elif 'build.gradle.kts' in files: gradlefile = "build.gradle.kts" if gradlefile: path = os.path.join(root, gradlefile) with open(path, "r") as o: lines = o.readlines() changed = False opened = 0 i = 0 with open(path, "w") as o: while i < len(lines): line = lines[i] i += 1 while line.endswith('\\\n'): line = line.rstrip('\\\n') + lines[i] i += 1 if gradle_comment.match(line): o.write(line) continue if opened > 0: opened += line.count('{') opened -= line.count('}') continue if gradle_signing_configs.match(line): changed = True opened += 1 continue if any(s.match(line) for s in gradle_line_matches): changed = True continue if opened == 0: o.write(line) if changed: print("Cleaned %s of keysigning configs at %s" % (gradlefile, path)) for propfile in [ 'project.properties', 'build.properties', 'default.properties', 'ant.properties', ]: if propfile in files: path = os.path.join(root, propfile) with open(path, "r", encoding='iso-8859-1') as o: lines = o.readlines() changed = False with open(path, "w", encoding='iso-8859-1') as o: for line in lines: if any(line.startswith(s) for s in ('key.store', 'key.alias')): changed = True continue o.write(line) if changed: print("Cleaned %s of keysigning configs at %s" % (propfile, path)) if __name__ == '__main__': remove_signing_keys('./android') ```