nixpkgs mirror (for testing) github.com/NixOS/nixpkgs
nix
at 16.09 240 lines 8.0 kB view raw
1{ stdenv, stdenv_32bit, fetchurl, unzip, makeWrapper 2, platformTools, buildTools, support, supportRepository, platforms, sysimages, addons 3, libX11, libXext, libXrender, libxcb, libXau, libXdmcp, libXtst, mesa, alsaLib 4, freetype, fontconfig, glib, gtk, atk, file, jdk, coreutils, libpulseaudio, dbus 5, zlib, glxinfo, xkeyboardconfig 6}: 7{ platformVersions, abiVersions, useGoogleAPIs, useExtraSupportLibs ? false, useGooglePlayServices ? false }: 8 9with { inherit (stdenv.lib) makeLibraryPath; }; 10 11stdenv.mkDerivation rec { 12 name = "android-sdk-${version}"; 13 version = "25.2.2"; 14 15 src = if (stdenv.system == "i686-linux" || stdenv.system == "x86_64-linux") 16 then fetchurl { 17 url = "http://dl.google.com/android/repository/tools_r${version}-linux.zip"; 18 sha256 = "0q53yq8fjc10kr4fz3rap5vsil3297w5nn4kw1z0ms7yz1d1im8h"; 19 } 20 else if stdenv.system == "x86_64-darwin" then fetchurl { 21 url = "http://dl.google.com/android/repository/tools_r${version}-macosx.zip"; 22 sha256 = "1wq7xm0rhy0h6qylv7fq9mhf8hqihrr1nzf7d322rc3g0jfrdrcl"; 23 } 24 else throw "platform not ${stdenv.system} supported!"; 25 26 buildCommand = '' 27 mkdir -p $out/libexec 28 cd $out/libexec 29 unpackFile $src 30 cd tools 31 32 for f in android traceview draw9patch hierarchyviewer monitor ddms screenshot2 uiautomatorviewer monkeyrunner jobb lint 33 do 34 sed -i -e "s|/bin/ls|${coreutils}/bin/ls|" "$f" 35 done 36 37 ${stdenv.lib.optionalString (stdenv.system == "i686-linux" || stdenv.system == "x86_64-linux") 38 '' 39 # There are a number of native binaries. We must patch them to let them find the interpreter and libstdc++ 40 41 for i in mksdcard 42 do 43 patchelf --set-interpreter ${stdenv_32bit.cc.libc.out}/lib/ld-linux.so.2 $i 44 patchelf --set-rpath ${stdenv_32bit.cc.cc.lib}/lib $i 45 done 46 47 ${stdenv.lib.optionalString (stdenv.system == "x86_64-linux") '' 48 for i in bin64/{mkfs.ext4,fsck.ext4,e2fsck,tune2fs,resize2fs} 49 do 50 patchelf --set-interpreter ${stdenv.cc.libc.out}/lib/ld-linux-x86-64.so.2 $i 51 patchelf --set-rpath ${stdenv.cc.cc.lib}/lib64 $i 52 done 53 ''} 54 55 ${stdenv.lib.optionalString (stdenv.system == "x86_64-linux") '' 56 # We must also patch the 64-bit emulator instances, if needed 57 58 for i in emulator emulator64-arm emulator64-mips emulator64-x86 emulator64-crash-service emulator-check qemu/linux-x86_64/qemu-system-* 59 do 60 patchelf --set-interpreter ${stdenv.cc.libc.out}/lib/ld-linux-x86-64.so.2 $i 61 patchelf --set-rpath ${stdenv.cc.cc.lib}/lib64 $i 62 done 63 ''} 64 65 # The following scripts used SWT and wants to dynamically load some GTK+ stuff. 66 # Creating these wrappers ensure that they can be found: 67 68 wrapProgram `pwd`/android \ 69 --prefix PATH : ${jdk}/bin \ 70 --prefix LD_LIBRARY_PATH : ${makeLibraryPath [ glib gtk libXtst ]} 71 72 wrapProgram `pwd`/uiautomatorviewer \ 73 --prefix PATH : ${jdk}/bin \ 74 --prefix LD_LIBRARY_PATH : ${stdenv.lib.makeLibraryPath [ glib gtk libXtst ]} 75 76 wrapProgram `pwd`/hierarchyviewer \ 77 --prefix PATH : ${jdk}/bin \ 78 --prefix LD_LIBRARY_PATH : ${stdenv.lib.makeLibraryPath [ glib gtk libXtst ]} 79 80 # The emulators need additional libraries, which are dynamically loaded => let's wrap them 81 82 ${stdenv.lib.optionalString (stdenv.system == "x86_64-linux") '' 83 for i in emulator emulator64-arm emulator64-mips emulator64-x86 emulator64-crash-service 84 do 85 wrapProgram `pwd`/$i \ 86 --prefix PATH : ${stdenv.lib.makeBinPath [ file glxinfo ]} \ 87 --suffix LD_LIBRARY_PATH : `pwd`/lib64:`pwd`/lib64/qt/lib:${makeLibraryPath [ stdenv.cc.cc libX11 libxcb libXau libXdmcp libXext mesa alsaLib zlib libpulseaudio dbus.lib ]} \ 88 --suffix QT_XKB_CONFIG_ROOT : ${xkeyboardconfig}/share/X11/xkb 89 done 90 ''} 91 ''} 92 93 patchShebangs . 94 95 ${if stdenv.system == "i686-linux" then 96 '' 97 # The monitor requires some more patching 98 99 cd lib/monitor-x86 100 patchelf --set-interpreter ${stdenv.cc.libc.out}/lib/ld-linux.so.2 monitor 101 patchelf --set-rpath ${makeLibraryPath [ libX11 libXext libXrender freetype fontconfig ]} libcairo-swt.so 102 103 wrapProgram `pwd`/monitor \ 104 --prefix LD_LIBRARY_PATH : ${makeLibraryPath [ gtk atk stdenv.cc.cc libXtst ]} 105 106 cd ../.. 107 '' 108 else if stdenv.system == "x86_64-linux" then 109 '' 110 # The monitor requires some more patching 111 112 cd lib/monitor-x86_64 113 patchelf --set-interpreter ${stdenv.cc.libc.out}/lib/ld-linux-x86-64.so.2 monitor 114 patchelf --set-rpath ${makeLibraryPath [ libX11 libXext libXrender freetype fontconfig ]} libcairo-swt.so 115 116 wrapProgram `pwd`/monitor \ 117 --prefix LD_LIBRARY_PATH : ${makeLibraryPath [ gtk atk stdenv.cc.cc libXtst ]} 118 119 cd ../.. 120 '' 121 else ""} 122 123 # Symlink the other sub packages 124 125 cd .. 126 ln -s ${platformTools}/platform-tools 127 ln -s ${buildTools}/build-tools 128 ln -s ${support}/support 129 130 # Symlink required Google API add-ons 131 132 mkdir -p add-ons 133 cd add-ons 134 135 ${if useGoogleAPIs then 136 stdenv.lib.concatMapStrings (platformVersion: 137 if (builtins.hasAttr ("google_apis_"+platformVersion) addons) then 138 let 139 googleApis = builtins.getAttr ("google_apis_"+platformVersion) addons; 140 in 141 "ln -s ${googleApis}/* addon-google_apis-${platformVersion}\n" 142 else "") platformVersions 143 else ""} 144 145 cd .. 146 147 # Symlink required extras 148 149 mkdir -p extras/android 150 cd extras/android 151 152 ln -s ${supportRepository}/m2repository 153 154 ${if useExtraSupportLibs then 155 "ln -s ${addons.android_support_extra}/support ." 156 else ""} 157 158 cd .. 159 mkdir -p google 160 cd google 161 162 ${if useGooglePlayServices then 163 "ln -s ${addons.google_play_services}/google-play-services google_play_services" 164 else ""} 165 166 cd ../.. 167 168 # Symlink required platforms 169 170 mkdir -p platforms 171 cd platforms 172 173 ${stdenv.lib.concatMapStrings (platformVersion: 174 if (builtins.hasAttr ("platform_"+platformVersion) platforms) then 175 let 176 platform = builtins.getAttr ("platform_"+platformVersion) platforms; 177 in 178 "ln -s ${platform}/* android-${platformVersion}\n" 179 else "" 180 ) platformVersions} 181 182 cd .. 183 184 # Symlink required system images 185 186 mkdir -p system-images 187 cd system-images 188 189 ${stdenv.lib.concatMapStrings (abiVersion: 190 stdenv.lib.concatMapStrings (platformVersion: 191 if (builtins.hasAttr ("sysimg_" + abiVersion + "_" + platformVersion) sysimages) then 192 let 193 sysimg = builtins.getAttr ("sysimg_" + abiVersion + "_" + platformVersion) sysimages; 194 in 195 '' 196 mkdir -p android-${platformVersion} 197 cd android-${platformVersion} 198 ln -s ${sysimg}/* 199 cd .. 200 '' 201 else "" 202 ) platformVersions 203 ) abiVersions} 204 205 # Create wrappers to the most important tools and platform tools so that we can run them if the SDK is in our PATH 206 207 mkdir -p $out/bin 208 209 for i in $out/libexec/tools/* 210 do 211 if [ ! -d $i ] && [ -x $i ] 212 then 213 ln -sf $i $out/bin/$(basename $i) 214 fi 215 done 216 217 for i in $out/libexec/platform-tools/* 218 do 219 if [ ! -d $i ] && [ -x $i ] 220 then 221 ln -sf $i $out/bin/$(basename $i) 222 fi 223 done 224 225 for i in $out/libexec/build-tools/*/* 226 do 227 if [ ! -d $i ] && [ -x $i ] 228 then 229 ln -sf $i $out/bin/$(basename $i) 230 fi 231 done 232 ''; 233 234 buildInputs = [ unzip makeWrapper ]; 235 236 meta = { 237 platforms = stdenv.lib.platforms.unix; 238 hydraPlatforms = []; 239 }; 240}