Skip to content

Commit 809a417

Browse files
ted-xiecopybara-github
authored andcommitted
Use AOSP's apksigner, not the SDK's
The SDK version supports a different set of flags, and is also not a java binary. mobile-install invokes the apksigner with `java -jar apksigner_deploy.jar`. Part of #12 PiperOrigin-RevId: 600829305 Change-Id: Ic2d0b7468c17eee1d2f89ac2a430c660fcfa1d61
1 parent 7c6da99 commit 809a417

File tree

8 files changed

+88
-24
lines changed

8 files changed

+88
-24
lines changed

MODULE.bazel

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ use_repo(
3939
)
4040

4141
# python-related dependency setup
42-
bazel_dep(name = "rules_python", version = "0.26.0", repo_name = "rules_python")
42+
bazel_dep(name = "rules_python", version = "0.28.0", repo_name = "rules_python")
4343

4444
python = use_extension("@rules_python//python/extensions:python.bzl", "python")
4545
python.toolchain(
@@ -96,3 +96,7 @@ bazel_binaries = use_extension(
9696
)
9797
bazel_binaries.download(version = "last_green")
9898
use_repo(bazel_binaries, "bazel_binaries")
99+
100+
# extension for apksignerextensions
101+
apksig_extension = use_extension("//bzlmod_extensions:apksig.bzl", "apksig_extension")
102+
use_repo(apksig_extension, "apksig")

bzlmod_extensions/BUILD

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
exports_files(
2+
[
3+
"apksig.BUILD",
4+
],
5+
)

bzlmod_extensions/apksig.BUILD

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Defines targets for the apksigner build tool.
2+
load("@rules_java//java:defs.bzl", "java_binary", "java_library", "java_test")
3+
4+
java_binary(
5+
name = "apksigner",
6+
srcs = glob(
7+
["**/*.java"],
8+
exclude = [
9+
"**/test/**",
10+
"**/*Test.java",
11+
],
12+
),
13+
main_class = "com.android.apksigner.ApkSignerTool",
14+
visibility = ["//visibility:public"],
15+
deps = [
16+
"@rules_android_maven//:org_bouncycastle_bcprov_jdk18on",
17+
"@rules_android_maven//:org_conscrypt_conscrypt_openjdk_uber",
18+
],
19+
)

bzlmod_extensions/apksig.bzl

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Copyright 2023 The Bazel Authors. All rights reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
"""Module extension to enable building apksigner."""
16+
17+
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
18+
19+
APKSIG_COMMIT = "24e3075e68ebe17c0b529bb24bfda819db5e2f3b"
20+
21+
def apksig(_ctx = None):
22+
# NOTE(b/317109605): Cannot depend on a stable sha256 hash for googlesource repositories.
23+
http_archive(
24+
name = "apksig",
25+
url = "https://android.googlesource.com/platform/tools/apksig/+archive/%s.tar.gz" % APKSIG_COMMIT,
26+
build_file = Label("//bzlmod_extensions:apksig.BUILD"),
27+
)
28+
29+
apksig_extension = module_extension(
30+
implementation = apksig,
31+
)

defs.bzl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,10 @@ def rules_android_workspace():
4242
"androidx.privacysandbox.tools:tools-apipackager:1.0.0-alpha06",
4343
"androidx.test:core:1.6.0-alpha01",
4444
"androidx.test.ext:junit:1.2.0-alpha01",
45+
"com.android.tools.build:apksig:8.3.0-alpha18",
4546
"com.android.tools.build:bundletool:1.15.5",
4647
"com.android.tools.build:gradle:8.2.0-alpha15",
48+
"org.bouncycastle:bcprov-jdk18on:1.77",
4749
"org.hamcrest:hamcrest-core:2.2",
4850
"org.robolectric:robolectric:4.10.3",
4951
"com.google.guava:guava:32.1.2-jre",

mobile_install/tools.bzl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ TOOL_ATTRS = dict(
7979
executable = True,
8080
),
8181
_apk_signer = attr.label(
82-
default = Label("@androidsdk//:apksigner"),
82+
default = Label("@apksig//:apksigner_deploy.jar"),
8383
allow_files = True,
8484
cfg = "exec",
8585
executable = True,

prereqs.bzl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
1818
load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe")
19+
load("//bzlmod_extensions:apksig.bzl", _apksig_archive = "apksig")
1920

2021
def rules_android_prereqs(dev_mode = False):
2122
"""Downloads prerequisite repositories for rules_android."""
@@ -133,6 +134,8 @@ def rules_android_prereqs(dev_mode = False):
133134
sha256 = "84aec9e21cc56fbc7f1335035a71c850d1b9b5cc6ff497306f84cced9a769841",
134135
)
135136

137+
_apksig_archive()
138+
136139
if dev_mode:
137140
maybe(
138141
http_archive,

rules_android_maven_install.json

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
22
"dependency_tree": {
33
"__AUTOGENERATED_FILE_DO_NOT_MODIFY_THIS_FILE_MANUALLY": "THERE_IS_NO_DATA_ONLY_ZUUL",
4-
"__INPUT_ARTIFACTS_HASH": -1817170305,
5-
"__RESOLVED_ARTIFACTS_HASH": -541553829,
4+
"__INPUT_ARTIFACTS_HASH": 634937897,
5+
"__RESOLVED_ARTIFACTS_HASH": -634008848,
66
"conflict_resolution": {
77
"com.google.protobuf:protobuf-java-util:3.9.2": "com.google.protobuf:protobuf-java-util:3.19.3"
88
},
@@ -635,31 +635,31 @@
635635
"url": "https://maven.google.com/com/android/tools/build/aaptcompiler/8.2.0-alpha15/aaptcompiler-8.2.0-alpha15.jar"
636636
},
637637
{
638-
"coord": "com.android.tools.build:apksig:8.2.0-alpha15",
638+
"coord": "com.android.tools.build:apksig:8.3.0-alpha18",
639639
"dependencies": [],
640640
"directDependencies": [],
641-
"file": "v1/https/maven.google.com/com/android/tools/build/apksig/8.2.0-alpha15/apksig-8.2.0-alpha15.jar",
641+
"file": "v1/https/maven.google.com/com/android/tools/build/apksig/8.3.0-alpha18/apksig-8.3.0-alpha18.jar",
642642
"mirror_urls": [
643-
"https://maven.google.com/com/android/tools/build/apksig/8.2.0-alpha15/apksig-8.2.0-alpha15.jar",
644-
"https://repo1.maven.org/maven2/com/android/tools/build/apksig/8.2.0-alpha15/apksig-8.2.0-alpha15.jar"
643+
"https://maven.google.com/com/android/tools/build/apksig/8.3.0-alpha18/apksig-8.3.0-alpha18.jar",
644+
"https://repo1.maven.org/maven2/com/android/tools/build/apksig/8.3.0-alpha18/apksig-8.3.0-alpha18.jar"
645645
],
646646
"sha256": "468ee1852fa12461c6629608fe47be70e50f60be7c4744bb7f62ca48e85c0a6c",
647-
"url": "https://maven.google.com/com/android/tools/build/apksig/8.2.0-alpha15/apksig-8.2.0-alpha15.jar"
647+
"url": "https://maven.google.com/com/android/tools/build/apksig/8.3.0-alpha18/apksig-8.3.0-alpha18.jar"
648648
},
649649
{
650650
"coord": "com.android.tools.build:apkzlib:8.2.0-alpha15",
651651
"dependencies": [
652652
"org.bouncycastle:bcprov-jdk15on:jar:1.67",
653653
"com.google.guava:guava:32.1.2-jre",
654654
"com.google.code.findbugs:jsr305:3.0.2",
655-
"com.android.tools.build:apksig:8.2.0-alpha15",
655+
"com.android.tools.build:apksig:8.3.0-alpha18",
656656
"org.bouncycastle:bcpkix-jdk15on:1.67",
657657
"org.bouncycastle:bcprov-jdk15on:1.67"
658658
],
659659
"directDependencies": [
660660
"com.google.guava:guava:32.1.2-jre",
661661
"com.google.code.findbugs:jsr305:3.0.2",
662-
"com.android.tools.build:apksig:8.2.0-alpha15",
662+
"com.android.tools.build:apksig:8.3.0-alpha18",
663663
"org.bouncycastle:bcpkix-jdk15on:1.67",
664664
"org.bouncycastle:bcprov-jdk15on:1.67"
665665
],
@@ -741,6 +741,7 @@
741741
"org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.9.0-Beta",
742742
"org.glassfish.jaxb:txw2:2.3.2",
743743
"com.android.tools.build:builder-model:8.2.0-alpha15",
744+
"com.android.tools.build:apksig:8.3.0-alpha18",
744745
"com.android.tools.build:apkzlib:8.2.0-alpha15",
745746
"jakarta.xml.bind:jakarta.xml.bind-api:2.3.2",
746747
"org.ow2.asm:asm-commons:9.5",
@@ -758,7 +759,6 @@
758759
"org.jvnet.staxex:stax-ex:1.8.1",
759760
"xerces:xercesImpl:2.12.0",
760761
"com.android.tools.analytics-library:shared:31.2.0-alpha15",
761-
"com.android.tools.build:apksig:8.2.0-alpha15",
762762
"org.jetbrains.kotlin:kotlin-stdlib-common:1.9.0-Beta",
763763
"com.android.tools.build:builder-test-api:8.2.0-alpha15",
764764
"com.android.tools.layoutlib:layoutlib-api:31.2.0-alpha15",
@@ -787,6 +787,7 @@
787787
"com.android.tools:common:31.2.0-alpha15",
788788
"org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.9.0-Beta",
789789
"com.android.tools.build:builder-model:8.2.0-alpha15",
790+
"com.android.tools.build:apksig:8.3.0-alpha18",
790791
"com.android.tools.build:apkzlib:8.2.0-alpha15",
791792
"org.ow2.asm:asm-commons:9.5",
792793
"commons-codec:commons-codec:1.11",
@@ -795,7 +796,6 @@
795796
"com.android.tools.analytics-library:tracker:31.2.0-alpha15",
796797
"com.android.tools.build:manifest-merger:31.2.0-alpha15",
797798
"com.android.tools:sdk-common:31.2.0-alpha15",
798-
"com.android.tools.build:apksig:8.2.0-alpha15",
799799
"com.android.tools.build:builder-test-api:8.2.0-alpha15",
800800
"com.android.tools.layoutlib:layoutlib-api:31.2.0-alpha15",
801801
"com.android.tools.analytics-library:protos:31.2.0-alpha15",
@@ -937,6 +937,7 @@
937937
"org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.9.0-Beta",
938938
"org.glassfish.jaxb:txw2:2.3.2",
939939
"com.android.tools.build:builder-model:8.2.0-alpha15",
940+
"com.android.tools.build:apksig:8.3.0-alpha18",
940941
"io.grpc:grpc-context:1.45.1",
941942
"commons-io:commons-io:2.4",
942943
"com.google.android:annotations:4.1.1.4",
@@ -975,7 +976,6 @@
975976
"io.grpc:grpc-api:1.45.1",
976977
"com.android.tools.build:gradle-api:8.2.0-alpha15",
977978
"org.ow2.asm:asm:9.5",
978-
"com.android.tools.build:apksig:8.2.0-alpha15",
979979
"org.jetbrains.kotlin:kotlin-stdlib-common:1.9.0-Beta",
980980
"com.android.tools.lint:lint-typedef-remover:31.2.0-alpha15",
981981
"com.android.tools.build:transform-api:2.0.0-deprecated-use-gradle-api",
@@ -1737,12 +1737,12 @@
17371737
"dependencies": [
17381738
"com.android.tools:annotations:31.2.0-alpha15",
17391739
"com.android:zipflinger:8.2.0-alpha15",
1740-
"com.android.tools.build:apksig:8.2.0-alpha15"
1740+
"com.android.tools.build:apksig:8.3.0-alpha18"
17411741
],
17421742
"directDependencies": [
17431743
"com.android:zipflinger:8.2.0-alpha15",
17441744
"com.android.tools:annotations:31.2.0-alpha15",
1745-
"com.android.tools.build:apksig:8.2.0-alpha15"
1745+
"com.android.tools.build:apksig:8.3.0-alpha18"
17461746
],
17471747
"file": "v1/https/maven.google.com/com/android/signflinger/8.2.0-alpha15/signflinger-8.2.0-alpha15.jar",
17481748
"mirror_urls": [
@@ -2839,16 +2839,16 @@
28392839
"url": "https://repo1.maven.org/maven2/org/bouncycastle/bcprov-jdk15on/1.67/bcprov-jdk15on-1.67.jar"
28402840
},
28412841
{
2842-
"coord": "org.bouncycastle:bcprov-jdk18on:1.72",
2842+
"coord": "org.bouncycastle:bcprov-jdk18on:1.77",
28432843
"dependencies": [],
28442844
"directDependencies": [],
2845-
"file": "v1/https/repo1.maven.org/maven2/org/bouncycastle/bcprov-jdk18on/1.72/bcprov-jdk18on-1.72.jar",
2845+
"file": "v1/https/repo1.maven.org/maven2/org/bouncycastle/bcprov-jdk18on/1.77/bcprov-jdk18on-1.77.jar",
28462846
"mirror_urls": [
2847-
"https://maven.google.com/org/bouncycastle/bcprov-jdk18on/1.72/bcprov-jdk18on-1.72.jar",
2848-
"https://repo1.maven.org/maven2/org/bouncycastle/bcprov-jdk18on/1.72/bcprov-jdk18on-1.72.jar"
2847+
"https://maven.google.com/org/bouncycastle/bcprov-jdk18on/1.77/bcprov-jdk18on-1.77.jar",
2848+
"https://repo1.maven.org/maven2/org/bouncycastle/bcprov-jdk18on/1.77/bcprov-jdk18on-1.77.jar"
28492849
],
2850-
"sha256": "39287f2208a753db419f5ca529d6c80f094614aa74d790331126b3c9c6b85fda",
2851-
"url": "https://repo1.maven.org/maven2/org/bouncycastle/bcprov-jdk18on/1.72/bcprov-jdk18on-1.72.jar"
2850+
"sha256": "dabb98c24d72c9b9f585633d1df9c5cd58d9ad373d0cd681367e6a603a495d58",
2851+
"url": "https://repo1.maven.org/maven2/org/bouncycastle/bcprov-jdk18on/1.77/bcprov-jdk18on-1.77.jar"
28522852
},
28532853
{
28542854
"coord": "org.checkerframework:checker-qual:3.35.0",
@@ -3355,7 +3355,6 @@
33553355
"dependencies": [
33563356
"com.google.errorprone:error_prone_annotations:2.19.1",
33573357
"org.robolectric:nativeruntime:4.10.3",
3358-
"org.bouncycastle:bcprov-jdk18on:1.72",
33593358
"androidx.test.espresso:espresso-idling-resource:aar:3.5.1",
33603359
"com.google.guava:guava:32.1.2-jre",
33613360
"org.robolectric:junit:4.10.3",
@@ -3378,13 +3377,13 @@
33783377
"org.robolectric:resources:4.10.3",
33793378
"org.robolectric:sandbox:4.10.3",
33803379
"javax.annotation:javax.annotation-api:1.3.2",
3380+
"org.bouncycastle:bcprov-jdk18on:1.77",
33813381
"com.google.auto.value:auto-value-annotations:1.10.1",
33823382
"javax.inject:javax.inject:1",
33833383
"androidx.test:monitor:aar:1.7.0-alpha01",
33843384
"org.ow2.asm:asm-analysis:9.5"
33853385
],
33863386
"directDependencies": [
3387-
"org.bouncycastle:bcprov-jdk18on:1.72",
33883387
"androidx.test.espresso:espresso-idling-resource:aar:3.5.1",
33893388
"org.robolectric:junit:4.10.3",
33903389
"org.robolectric:pluginapi:4.10.3",
@@ -3397,6 +3396,7 @@
33973396
"org.robolectric:resources:4.10.3",
33983397
"org.robolectric:sandbox:4.10.3",
33993398
"javax.annotation:javax.annotation-api:1.3.2",
3399+
"org.bouncycastle:bcprov-jdk18on:1.77",
34003400
"javax.inject:javax.inject:1",
34013401
"androidx.test:monitor:aar:1.7.0-alpha01"
34023402
],

0 commit comments

Comments
 (0)