Skip to content

Commit def939e

Browse files
committed
Update dependencies and enable dependency verification in Gradle
Here's another attempt to enable Gradle dependency verification. I've tried to do this a couple of times before, but always ran into issues. With a helper script borrowed from a different project, hopefully this will finally work reliably. Every time we update Gradle or a dependency, the script I mentioned needs to be run to update the list of checksums. The script runs the build, the tests and the instrumented tests. This is necessary because apparently Gradle is not able to discover all dependencies without actually running the build tasks. It's a little bit annoying that this Gradle feature is so half-baked that we need a helper script to make things work, but I think it's worth it.
1 parent 49a2b5d commit def939e

File tree

5 files changed

+3529
-13
lines changed

5 files changed

+3529
-13
lines changed

app/build.gradle

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -133,10 +133,10 @@ aboutLibraries {
133133
}
134134

135135
dependencies {
136-
def cameraxVersion = '1.3.1'
136+
def cameraxVersion = '1.3.2'
137137
def glideVersion = '4.16.0'
138-
def guavaVersion = '33.0.0'
139-
def hiltVersion = '2.50'
138+
def guavaVersion = '33.1.0'
139+
def hiltVersion = '2.51'
140140
def junitVersion = '4.13.2'
141141
def libsuVersion = '5.2.2'
142142

@@ -154,7 +154,7 @@ dependencies {
154154
implementation "androidx.core:core:1.12.0"
155155
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
156156
implementation 'androidx.documentfile:documentfile:1.0.1'
157-
implementation "androidx.lifecycle:lifecycle-process:2.6.2"
157+
implementation "androidx.lifecycle:lifecycle-process:2.7.0"
158158
implementation "androidx.preference:preference:1.2.1"
159159
implementation 'androidx.recyclerview:recyclerview:1.3.2'
160160
implementation "androidx.viewpager2:viewpager2:1.0.0"
@@ -171,18 +171,18 @@ dependencies {
171171
implementation "com.github.topjohnwu.libsu:io:${libsuVersion}"
172172
implementation "com.google.guava:guava:${guavaVersion}-android"
173173
implementation 'com.google.android.material:material:1.11.0'
174-
implementation 'com.google.protobuf:protobuf-javalite:3.25.1'
175-
implementation 'com.google.zxing:core:3.5.2'
174+
implementation 'com.google.protobuf:protobuf-javalite:4.26.0'
175+
implementation 'com.google.zxing:core:3.5.3'
176176
implementation("com.mikepenz:aboutlibraries:11.1.0") {
177177
exclude group: 'com.mikepenz', module: 'aboutlibraries-core'
178178
}
179-
implementation "com.mikepenz:aboutlibraries-core-android:11.1.0"
179+
implementation 'com.mikepenz:aboutlibraries-core-android:11.1.1'
180180
implementation 'com.nulab-inc:zxcvbn:1.8.2'
181181
implementation 'de.hdodenhof:circleimageview:3.1.0'
182182
implementation 'net.lingala.zip4j:zip4j:2.11.5'
183183
implementation 'info.guardianproject.trustedintents:trustedintents:0.2'
184184
implementation 'org.bouncycastle:bcprov-jdk18on:1.77'
185-
implementation "org.simpleflatmapper:sfm-csv:8.2.3"
185+
implementation 'org.simpleflatmapper:sfm-csv:9.0.0'
186186

187187
androidTestAnnotationProcessor "com.google.dagger:hilt-android-compiler:$hiltVersion"
188188
androidTestImplementation "com.google.dagger:hilt-android-testing:$hiltVersion"
@@ -199,7 +199,7 @@ dependencies {
199199
testImplementation 'androidx.test:core:1.5.0'
200200
testImplementation "com.google.guava:guava:${guavaVersion}-jre"
201201
testImplementation "junit:junit:${junitVersion}"
202-
testImplementation 'org.json:json:20231013'
202+
testImplementation 'org.json:json:20240303'
203203
testImplementation 'org.robolectric:robolectric:4.11.1'
204204

205205
coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:2.0.4'

build.gradle

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ buildscript {
66
google()
77
}
88
dependencies {
9-
classpath 'com.android.tools.build:gradle:8.2.0'
10-
classpath 'com.google.dagger:hilt-android-gradle-plugin:2.50'
9+
classpath 'com.android.tools.build:gradle:8.3.1'
10+
classpath 'com.google.dagger:hilt-android-gradle-plugin:2.51'
1111
classpath 'com.google.protobuf:protobuf-gradle-plugin:0.9.4'
1212

1313
// NOTE: Do not place your application dependencies here; they belong
@@ -21,8 +21,8 @@ plugins {
2121

2222
allprojects {
2323
repositories {
24-
mavenCentral()
2524
google()
25+
mavenCentral()
2626
maven { url 'https://jitpack.io' }
2727
maven {
2828
url 'https://jcenter.bintray.com'

gradle/update_verification.py

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
#!/usr/bin/env python3
2+
3+
# Based on: https://github.com/chenxiaolong/BCR/blob/6f1f30cf89f7d564870fe61791a490649cfb0ea0/gradle/update_verification.py
4+
# License: GPL-3.0
5+
6+
import hashlib
7+
import io
8+
import os
9+
import subprocess
10+
import sys
11+
import tempfile
12+
import urllib.request
13+
import xml.etree.ElementTree as ET
14+
15+
16+
GOOGLE_MAVEN_REPO = 'https://dl.google.com/android/maven2'
17+
18+
19+
def add_source_exclusions(ns, root):
20+
configuration = root.find(f'{{{ns}}}configuration')
21+
trusted_artifacts = ET.SubElement(
22+
configuration, f'{{{ns}}}trusted-artifacts')
23+
24+
for regex in [
25+
r'.*-javadoc[.]jar',
26+
r'.*-sources[.]jar',
27+
r'.*-src[.]zip',
28+
]:
29+
ET.SubElement(trusted_artifacts, f'{{{ns}}}trust', attrib={
30+
'file': regex,
31+
'regex': 'true',
32+
})
33+
34+
35+
def add_missing_aapt2_platforms(ns, root):
36+
components = root.find(f'{{{ns}}}components')
37+
aapt2 = components.find(f'{{{ns}}}component[@name="aapt2"]')
38+
39+
for platform in ['linux', 'osx', 'windows']:
40+
group = aapt2.attrib['group']
41+
name = aapt2.attrib['name']
42+
version = aapt2.attrib['version']
43+
filename = f'{name}-{version}-{platform}.jar'
44+
45+
if aapt2.find(f'{{{ns}}}artifact[@name="{filename}"]') is not None:
46+
continue
47+
48+
path = f'{group.replace(".", "/")}/{name}/{version}/{filename}'
49+
url = f'{GOOGLE_MAVEN_REPO}/{path}'
50+
51+
with urllib.request.urlopen(url) as r:
52+
if r.status != 200:
53+
raise Exception(f'{url} returned HTTP {r.status}')
54+
55+
digest = hashlib.file_digest(r, 'sha512')
56+
57+
artifact = ET.SubElement(aapt2, f'{{{ns}}}artifact',
58+
attrib={'name': filename})
59+
60+
ET.SubElement(artifact, f'{{{ns}}}sha512', attrib={
61+
'value': digest.hexdigest(),
62+
'origin': 'Generated by Gradle',
63+
})
64+
65+
aapt2[:] = sorted(aapt2, key=lambda child: child.attrib['name'])
66+
67+
68+
def patch_xml(path):
69+
tree = ET.parse(path)
70+
root = tree.getroot()
71+
72+
ns = 'https://schema.gradle.org/dependency-verification'
73+
ET.register_namespace('', ns)
74+
75+
# Add exclusions to allow Android Studio to download sources.
76+
add_source_exclusions(ns, root)
77+
78+
# Gradle only adds the aapt2 entry for the host OS. We have to manually add
79+
# the checksums for the other major desktop OSs.
80+
add_missing_aapt2_platforms(ns, root)
81+
82+
# Match gradle's formatting exactly.
83+
ET.indent(tree, ' ')
84+
root.tail = '\n'
85+
86+
with io.BytesIO() as f:
87+
# etree's xml_declaration=True uses single quotes in the header.
88+
f.write(b'<?xml version="1.0" encoding="UTF-8"?>\n')
89+
tree.write(f)
90+
serialized = f.getvalue().replace(b' />', b'/>')
91+
92+
with open(path, 'wb') as f:
93+
f.write(serialized)
94+
95+
96+
def main():
97+
root_dir = os.path.join(sys.path[0], '..')
98+
xml_file = os.path.join(sys.path[0], 'verification-metadata.xml')
99+
100+
try:
101+
os.remove(xml_file)
102+
except FileNotFoundError:
103+
pass
104+
105+
# Gradle will sometimes fail to add verification entries for artifacts that
106+
# are already cached.
107+
with tempfile.TemporaryDirectory() as temp_dir:
108+
env = os.environ | {'GRADLE_USER_HOME': temp_dir}
109+
110+
subprocess.check_call(
111+
[
112+
'./gradlew' + ('.bat' if os.name == 'nt' else ''),
113+
'--write-verification-metadata', 'sha512',
114+
'--no-daemon',
115+
'build',
116+
'connectedCheck'
117+
],
118+
env=env,
119+
cwd=root_dir,
120+
)
121+
122+
patch_xml(xml_file)
123+
124+
125+
if __name__ == '__main__':
126+
main()

0 commit comments

Comments
 (0)