10 stdenv.mkDerivation rec {
12 version = "34.0.5-unstable-2024-03-06";
15 # use pname here because the final jar uses this as the filename
17 url = "https://android.googlesource.com/platform/tools/apksig";
18 rev = "ac5cbb07d87cc342fcf07715857a812305d69888";
19 hash = "sha256-sLAs7XEkhNkQjB/nhBODxI3QzxFvLWM1SBKDuXp6gvw=";
23 cat >> build.gradle <<EOF
25 apply plugin: 'application'
26 mainClassName = "com.android.apksigner.ApkSignerTool"
27 sourceSets.main.java.srcDirs = [ 'src/apksigner/java', 'src/main/java' ]
29 manifest { attributes "Main-Class": "com.android.apksigner.ApkSignerTool" }
30 from { (configurations.runtimeClasspath).collect { it.isDirectory() ? it : zipTree(it) } } {
31 exclude 'META-INF/*.RSA', 'META-INF/*.SF', 'META-INF/*.DSA', 'META-INF/native/*.dll'
33 from('src/apksigner/java') {
34 include 'com/android/apksigner/*.txt'
37 tasks.named("processTestResources") { dependsOn("extractTestProto") }
39 sed -i -e '/conscrypt/s/testImplementation/implementation/' build.gradle
42 # fake build to pre-download deps into fixed-output derivation
43 deps = stdenv.mkDerivation {
44 pname = "${pname}-deps";
45 inherit src version postPatch;
46 nativeBuildInputs = [ gradle perl ];
48 export GRADLE_USER_HOME=$(mktemp -d)
49 gradle --no-daemon build
51 # perl code mavenizes pathes (com.squareup.okio/okio/1.13.0/a9283170b7305c8d92d25aff02a6ab7e45d06cbe/okio-1.13.0.jar -> com/squareup/okio/okio/1.13.0/okio-1.13.0.jar)
53 find $GRADLE_USER_HOME/caches/modules-2 -type f -regex '.*\.\(jar\|pom\)' \
54 | perl -pe 's#(.*/([^/]+)/([^/]+)/([^/]+)/[0-9a-f]{30,40}/([^/\s]+))$# ($x = $2) =~ tr|\.|/|; "install -Dm444 $1 \$out/$x/$3/$4/''${\($5 =~ s/okio-jvm/okio/r)}" #e' \
57 # Don't move info to share/
58 forceShare = [ "dummy" ];
59 outputHashMode = "recursive";
60 # Downloaded jars differ by platform
61 outputHash = "sha256-cs95YI0SpvzCo5x5trMXlVUGepNKIH9oZ95AfLErKIU=";
65 # Use the local packages from -deps
66 sed -i -e '/repositories {/a maven { url uri("${deps}") }' build.gradle
72 export GRADLE_USER_HOME=$(mktemp -d)
73 gradle --offline --no-daemon build
78 nativeBuildInputs = [ gradle makeWrapper ];
81 install -Dm444 build/libs/apksigner.jar -t $out/lib
82 makeWrapper "${jdk_headless}/bin/java" "$out/bin/apksigner" \
83 --add-flags "-jar $out/lib/apksigner.jar"
86 __darwinAllowLocalNetworking = true;
89 description = "Command line tool to sign and verify Android APKs";
90 mainProgram = "apksigner";
91 homepage = "https://developer.android.com/studio/command-line/apksigner";
92 license = licenses.asl20;
93 maintainers = with maintainers; [ linsui ];
94 platforms = platforms.unix;