12 stdenv.mkDerivation rec {
17 # use pname here because the final jar uses this as the filename
19 url = "https://android.googlesource.com/platform/tools/apksig";
20 rev = "platform-tools-${version}";
21 hash = "sha256-CKvwB9Bb12QvkL/HBOwT6DhA1PI45+QnTNfwnvReGUQ=";
25 cat >> build.gradle <<EOF
27 apply plugin: 'application'
28 mainClassName = "com.android.apksigner.ApkSignerTool"
29 sourceSets.main.java.srcDirs = [ 'src/apksigner/java', 'src/main/java' ]
31 manifest { attributes "Main-Class": "com.android.apksigner.ApkSignerTool" }
32 from { (configurations.runtimeClasspath).collect { it.isDirectory() ? it : zipTree(it) } } {
33 exclude 'META-INF/*.RSA', 'META-INF/*.SF', 'META-INF/*.DSA', 'META-INF/native/*.dll'
35 from('src/apksigner/java') {
36 include 'com/android/apksigner/*.txt'
40 sed -i -e '/conscrypt/s/testImplementation/implementation/' build.gradle
43 # fake build to pre-download deps into fixed-output derivation
44 deps = stdenv.mkDerivation {
45 pname = "${pname}-deps";
46 inherit src version postPatch;
47 nativeBuildInputs = [ gradle perl ];
49 export GRADLE_USER_HOME=$(mktemp -d)
50 gradle --no-daemon build
52 # 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)
54 find $GRADLE_USER_HOME/caches/modules-2 -type f -regex '.*\.\(jar\|pom\)' \
55 | 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' \
58 # Don't move info to share/
59 forceShare = [ "dummy" ];
60 outputHashMode = "recursive";
61 # Downloaded jars differ by platform
62 outputHash = "sha256-cs95YI0SpvzCo5x5trMXlVUGepNKIH9oZ95AfLErKIU=";
66 # Use the local packages from -deps
67 sed -i -e '/repositories {/a maven { url uri("${deps}") }' build.gradle
73 export GRADLE_USER_HOME=$(mktemp -d)
74 gradle --offline --no-daemon build
79 nativeBuildInputs = [ gradle makeWrapper ];
82 install -Dm444 build/libs/apksigner.jar -t $out/lib
83 makeWrapper "${openjdk17_headless}/bin/java" "$out/bin/apksigner" \
84 --add-flags "-jar $out/lib/apksigner.jar"
88 description = "Command line tool to sign and verify Android APKs";
89 homepage = "https://developer.android.com/studio/command-line/apksigner";
90 license = licenses.asl20;
91 maintainers = with maintainers; [ linsui ];
92 platforms = platforms.unix;