2018-06-21 17:12:02 +01:00
|
|
|
{ stdenv, stdenv_32bit, fetchurl, fetchzip, unzip, makeWrapper
|
2016-10-09 11:11:55 +01:00
|
|
|
, platformTools, buildTools, support, supportRepository, platforms, sysimages, addons, sources
|
2018-02-24 13:12:44 +00:00
|
|
|
, libX11, libXext, libXrender, libxcb, libXau, libXdmcp, libXtst, libGLU_combined, alsaLib
|
2016-09-11 22:24:51 +01:00
|
|
|
, freetype, fontconfig, glib, gtk2, atk, file, jdk, coreutils, libpulseaudio, dbus
|
2016-07-25 20:47:39 +01:00
|
|
|
, zlib, glxinfo, xkeyboardconfig
|
2016-10-09 11:11:55 +01:00
|
|
|
, includeSources
|
2018-10-23 00:00:14 +01:00
|
|
|
, licenseAccepted
|
2012-11-07 20:10:39 +00:00
|
|
|
}:
|
2018-10-27 04:26:51 +01:00
|
|
|
{ platformVersions, abiVersions, useGoogleAPIs, buildToolsVersions ? [], useExtraSupportLibs ? false
|
2017-09-09 15:23:20 +01:00
|
|
|
, useGooglePlayServices ? false, useInstantApps ? false }:
|
2012-11-07 20:10:39 +00:00
|
|
|
|
2018-10-23 00:00:14 +01:00
|
|
|
if !licenseAccepted then throw ''
|
|
|
|
You must accept the Android Software Development Kit License Agreement at
|
|
|
|
https://developer.android.com/studio/terms
|
|
|
|
by setting nixpkgs config option 'android_sdk.accept_license = true;'
|
|
|
|
''
|
|
|
|
else assert licenseAccepted;
|
|
|
|
|
2018-06-21 17:12:02 +01:00
|
|
|
let inherit (stdenv.lib) makeLibraryPath;
|
|
|
|
|
|
|
|
googleRepository = let version = "gms_v9_rc41_wear_2_0_rc6";
|
|
|
|
in fetchzip rec {
|
|
|
|
url = "https://dl-ssl.google.com/android/repository/google_m2repository_${version}.zip";
|
|
|
|
sha256 = "0k99xmynv0k62d301zx5jnjkddflr51i5lb02l9incg7m5cn8kzx";
|
|
|
|
};
|
|
|
|
|
|
|
|
in
|
2015-10-05 11:23:02 +01:00
|
|
|
|
2014-05-07 23:49:19 +01:00
|
|
|
stdenv.mkDerivation rec {
|
|
|
|
name = "android-sdk-${version}";
|
2018-10-23 00:00:14 +01:00
|
|
|
version = "26.1.1";
|
2014-12-16 07:22:55 +00:00
|
|
|
|
2018-08-20 20:11:29 +01:00
|
|
|
src = if (stdenv.hostPlatform.system == "i686-linux" || stdenv.hostPlatform.system == "x86_64-linux")
|
2012-11-07 20:10:39 +00:00
|
|
|
then fetchurl {
|
2018-10-23 00:00:14 +01:00
|
|
|
url = "https://dl.google.com/android/repository/sdk-tools-linux-4333796.zip";
|
|
|
|
sha256 = "1yfy0qqxz1ixpsci1pizls1nrncmi8p16wcb9rimdn4q3mdfxzwj";
|
2012-11-07 20:10:39 +00:00
|
|
|
}
|
2018-08-20 20:11:29 +01:00
|
|
|
else if stdenv.hostPlatform.system == "x86_64-darwin" then fetchurl {
|
2018-10-23 00:00:14 +01:00
|
|
|
url = "https://dl.google.com/android/repository/sdk-tools-darwin-4333796.zip";
|
|
|
|
sha256 = "0gl5c30m40kx0vvrpbaa8cw8wq2vb89r14hgzb1df4qgpic97cpc";
|
2012-11-07 20:10:39 +00:00
|
|
|
}
|
2018-08-20 20:11:29 +01:00
|
|
|
else throw "platform not ${stdenv.hostPlatform.system} supported!";
|
2014-12-16 07:22:55 +00:00
|
|
|
|
2018-10-31 12:16:05 +00:00
|
|
|
emulator = fetchurl {
|
|
|
|
url = "https://dl.google.com/android/repository/emulator-linux-4969155.zip";
|
|
|
|
sha256 = "0iw0j6j3w9zpfalsa7xq2czz4vzgq96zk2zddjhanwwx4p8fhrfd";
|
|
|
|
};
|
|
|
|
|
2012-11-07 20:10:39 +00:00
|
|
|
buildCommand = ''
|
2012-11-08 14:01:06 +00:00
|
|
|
mkdir -p $out/libexec
|
|
|
|
cd $out/libexec
|
2014-09-02 18:18:30 +01:00
|
|
|
unpackFile $src
|
2018-10-31 12:16:05 +00:00
|
|
|
unpackFile $emulator
|
2016-07-25 20:47:39 +01:00
|
|
|
cd tools
|
2015-05-03 15:03:36 +01:00
|
|
|
|
2018-10-23 00:00:14 +01:00
|
|
|
for f in monitor bin/monkeyrunner bin/uiautomatorviewer
|
2015-05-03 15:03:36 +01:00
|
|
|
do
|
|
|
|
sed -i -e "s|/bin/ls|${coreutils}/bin/ls|" "$f"
|
|
|
|
done
|
|
|
|
|
2018-08-20 20:11:29 +01:00
|
|
|
${stdenv.lib.optionalString (stdenv.hostPlatform.system == "i686-linux" || stdenv.hostPlatform.system == "x86_64-linux")
|
2012-11-07 20:10:39 +00:00
|
|
|
''
|
|
|
|
# There are a number of native binaries. We must patch them to let them find the interpreter and libstdc++
|
2017-09-09 15:23:20 +01:00
|
|
|
|
2016-07-25 20:47:39 +01:00
|
|
|
for i in mksdcard
|
2012-11-07 20:10:39 +00:00
|
|
|
do
|
2015-04-26 18:54:51 +01:00
|
|
|
patchelf --set-interpreter ${stdenv_32bit.cc.libc.out}/lib/ld-linux.so.2 $i
|
2016-07-01 20:39:04 +01:00
|
|
|
patchelf --set-rpath ${stdenv_32bit.cc.cc.lib}/lib $i
|
2012-11-07 20:10:39 +00:00
|
|
|
done
|
2016-07-25 20:47:39 +01:00
|
|
|
|
2015-10-15 15:42:24 +01:00
|
|
|
# The following scripts used SWT and wants to dynamically load some GTK+ stuff.
|
|
|
|
# Creating these wrappers ensure that they can be found:
|
2017-09-09 15:23:20 +01:00
|
|
|
|
2013-08-07 21:12:44 +01:00
|
|
|
wrapProgram `pwd`/android \
|
2013-08-08 09:40:09 +01:00
|
|
|
--prefix PATH : ${jdk}/bin \
|
2016-09-11 22:24:51 +01:00
|
|
|
--prefix LD_LIBRARY_PATH : ${makeLibraryPath [ glib gtk2 libXtst ]}
|
2017-09-09 15:23:20 +01:00
|
|
|
|
2018-10-23 00:00:14 +01:00
|
|
|
wrapProgram `pwd`/bin/uiautomatorviewer \
|
2015-10-15 15:42:24 +01:00
|
|
|
--prefix PATH : ${jdk}/bin \
|
2016-09-11 22:24:51 +01:00
|
|
|
--prefix LD_LIBRARY_PATH : ${stdenv.lib.makeLibraryPath [ glib gtk2 libXtst ]}
|
2017-09-09 15:23:20 +01:00
|
|
|
|
2013-08-07 21:12:44 +01:00
|
|
|
# The emulators need additional libraries, which are dynamically loaded => let's wrap them
|
2016-07-25 20:47:39 +01:00
|
|
|
|
2018-08-20 20:11:29 +01:00
|
|
|
${stdenv.lib.optionalString (stdenv.hostPlatform.system == "x86_64-linux") ''
|
2018-10-31 12:16:05 +00:00
|
|
|
cd ..
|
|
|
|
for i in emulator/emulator* emulator/qemu/linux-x86_64/qemu-system-*
|
2012-12-20 13:04:52 +00:00
|
|
|
do
|
2018-10-31 12:16:05 +00:00
|
|
|
patchelf --set-interpreter ${stdenv.cc.libc.out}/lib/ld-linux-x86-64.so.2 $i
|
2012-12-20 13:04:52 +00:00
|
|
|
wrapProgram `pwd`/$i \
|
2016-08-22 23:06:51 +01:00
|
|
|
--prefix PATH : ${stdenv.lib.makeBinPath [ file glxinfo ]} \
|
2018-10-23 00:00:14 +01:00
|
|
|
--suffix LD_LIBRARY_PATH : `pwd`/lib:${makeLibraryPath [ stdenv.cc.cc libX11 libxcb libXau libXdmcp libXext libGLU_combined alsaLib zlib libpulseaudio dbus.lib ]} \
|
2016-07-25 20:47:39 +01:00
|
|
|
--suffix QT_XKB_CONFIG_ROOT : ${xkeyboardconfig}/share/X11/xkb
|
2012-12-20 13:04:52 +00:00
|
|
|
done
|
2018-10-31 12:16:05 +00:00
|
|
|
cd tools
|
2012-12-20 13:04:52 +00:00
|
|
|
''}
|
2012-11-07 20:10:39 +00:00
|
|
|
''}
|
|
|
|
|
2012-11-08 15:49:36 +00:00
|
|
|
patchShebangs .
|
2017-09-09 15:23:20 +01:00
|
|
|
|
2018-08-20 20:11:29 +01:00
|
|
|
${if stdenv.hostPlatform.system == "i686-linux" then
|
2012-11-07 20:10:39 +00:00
|
|
|
''
|
|
|
|
# The monitor requires some more patching
|
2017-09-09 15:23:20 +01:00
|
|
|
|
2012-11-07 20:10:39 +00:00
|
|
|
cd lib/monitor-x86
|
2018-11-10 19:11:15 +00:00
|
|
|
patchelf --set-interpreter ${stdenv_32bit.cc.libc.out}/lib/ld-linux.so.2 monitor
|
2015-10-05 11:23:02 +01:00
|
|
|
patchelf --set-rpath ${makeLibraryPath [ libX11 libXext libXrender freetype fontconfig ]} libcairo-swt.so
|
2017-09-09 15:23:20 +01:00
|
|
|
|
2012-11-07 20:10:39 +00:00
|
|
|
wrapProgram `pwd`/monitor \
|
2016-09-11 22:24:51 +01:00
|
|
|
--prefix LD_LIBRARY_PATH : ${makeLibraryPath [ gtk2 atk stdenv.cc.cc libXtst ]}
|
2012-11-07 20:10:39 +00:00
|
|
|
|
|
|
|
cd ../..
|
|
|
|
''
|
2018-08-20 20:11:29 +01:00
|
|
|
else if stdenv.hostPlatform.system == "x86_64-linux" then
|
2012-11-07 20:10:39 +00:00
|
|
|
''
|
|
|
|
# The monitor requires some more patching
|
2017-09-09 15:23:20 +01:00
|
|
|
|
2012-11-07 20:10:39 +00:00
|
|
|
cd lib/monitor-x86_64
|
2015-04-26 18:54:51 +01:00
|
|
|
patchelf --set-interpreter ${stdenv.cc.libc.out}/lib/ld-linux-x86-64.so.2 monitor
|
2015-10-05 11:23:02 +01:00
|
|
|
patchelf --set-rpath ${makeLibraryPath [ libX11 libXext libXrender freetype fontconfig ]} libcairo-swt.so
|
2017-09-09 15:23:20 +01:00
|
|
|
|
2012-11-07 20:10:39 +00:00
|
|
|
wrapProgram `pwd`/monitor \
|
2016-09-11 22:24:51 +01:00
|
|
|
--prefix LD_LIBRARY_PATH : ${makeLibraryPath [ gtk2 atk stdenv.cc.cc libXtst ]}
|
2012-11-07 20:10:39 +00:00
|
|
|
|
|
|
|
cd ../..
|
|
|
|
''
|
|
|
|
else ""}
|
2017-09-09 15:23:20 +01:00
|
|
|
|
2012-11-07 20:10:39 +00:00
|
|
|
# Symlink the other sub packages
|
2017-09-09 15:23:20 +01:00
|
|
|
|
2012-11-07 20:10:39 +00:00
|
|
|
cd ..
|
|
|
|
ln -s ${platformTools}/platform-tools
|
|
|
|
ln -s ${support}/support
|
2017-09-09 15:23:20 +01:00
|
|
|
|
2018-10-27 04:26:51 +01:00
|
|
|
mkdir -p build-tools
|
|
|
|
cd build-tools
|
|
|
|
|
|
|
|
${stdenv.lib.concatMapStrings
|
|
|
|
(v: "ln -s ${builtins.getAttr "v${builtins.replaceStrings ["."] ["_"] v}" buildTools}/build-tools/*")
|
|
|
|
(if (builtins.length buildToolsVersions) == 0 then platformVersions else buildToolsVersions)}
|
|
|
|
|
|
|
|
cd ..
|
|
|
|
|
2012-11-07 20:10:39 +00:00
|
|
|
# Symlink required Google API add-ons
|
2017-09-09 15:23:20 +01:00
|
|
|
|
2012-11-07 20:10:39 +00:00
|
|
|
mkdir -p add-ons
|
|
|
|
cd add-ons
|
2017-09-09 15:23:20 +01:00
|
|
|
|
2012-11-07 20:10:39 +00:00
|
|
|
${if useGoogleAPIs then
|
|
|
|
stdenv.lib.concatMapStrings (platformVersion:
|
|
|
|
if (builtins.hasAttr ("google_apis_"+platformVersion) addons) then
|
|
|
|
let
|
|
|
|
googleApis = builtins.getAttr ("google_apis_"+platformVersion) addons;
|
|
|
|
in
|
2013-12-03 01:27:53 +00:00
|
|
|
"ln -s ${googleApis}/* addon-google_apis-${platformVersion}\n"
|
2012-11-07 20:10:39 +00:00
|
|
|
else "") platformVersions
|
|
|
|
else ""}
|
2017-09-09 15:23:20 +01:00
|
|
|
|
2012-11-07 20:10:39 +00:00
|
|
|
cd ..
|
|
|
|
|
2014-08-02 02:26:21 +01:00
|
|
|
# Symlink required extras
|
|
|
|
|
|
|
|
mkdir -p extras/android
|
|
|
|
cd extras/android
|
|
|
|
|
|
|
|
ln -s ${supportRepository}/m2repository
|
|
|
|
|
2015-03-01 20:31:41 +00:00
|
|
|
${if useExtraSupportLibs then
|
|
|
|
"ln -s ${addons.android_support_extra}/support ."
|
|
|
|
else ""}
|
|
|
|
|
|
|
|
cd ..
|
|
|
|
mkdir -p google
|
|
|
|
cd google
|
|
|
|
|
|
|
|
${if useGooglePlayServices then
|
|
|
|
"ln -s ${addons.google_play_services}/google-play-services google_play_services"
|
|
|
|
else ""}
|
2017-09-09 15:23:20 +01:00
|
|
|
|
|
|
|
${stdenv.lib.optionalString useInstantApps
|
|
|
|
"ln -s ${addons.instant_apps}/whsdk instantapps"}
|
|
|
|
|
2018-06-21 17:48:05 +01:00
|
|
|
ln -s ${googleRepository} m2repository
|
2017-05-16 20:27:27 +01:00
|
|
|
|
2014-08-02 02:26:21 +01:00
|
|
|
cd ../..
|
|
|
|
|
2016-10-09 11:11:55 +01:00
|
|
|
# Symlink required sources
|
|
|
|
mkdir -p sources
|
|
|
|
cd sources
|
|
|
|
|
|
|
|
${if includeSources then
|
|
|
|
stdenv.lib.concatMapStrings (platformVersion:
|
|
|
|
if (builtins.hasAttr ("source_"+platformVersion) sources) then
|
|
|
|
let
|
|
|
|
source = builtins.getAttr ("source_"+platformVersion) sources;
|
|
|
|
in
|
|
|
|
"ln -s ${source}/* android-${platformVersion}\n"
|
|
|
|
else "") platformVersions
|
|
|
|
else ""}
|
|
|
|
|
|
|
|
cd ..
|
|
|
|
|
2012-11-07 20:10:39 +00:00
|
|
|
# Symlink required platforms
|
2017-09-09 15:23:20 +01:00
|
|
|
|
2012-11-07 20:10:39 +00:00
|
|
|
mkdir -p platforms
|
|
|
|
cd platforms
|
2017-09-09 15:23:20 +01:00
|
|
|
|
2012-11-07 20:10:39 +00:00
|
|
|
${stdenv.lib.concatMapStrings (platformVersion:
|
|
|
|
if (builtins.hasAttr ("platform_"+platformVersion) platforms) then
|
|
|
|
let
|
|
|
|
platform = builtins.getAttr ("platform_"+platformVersion) platforms;
|
|
|
|
in
|
2013-12-03 01:27:53 +00:00
|
|
|
"ln -s ${platform}/* android-${platformVersion}\n"
|
2012-11-07 20:10:39 +00:00
|
|
|
else ""
|
|
|
|
) platformVersions}
|
2017-09-09 15:23:20 +01:00
|
|
|
|
2012-11-07 20:10:39 +00:00
|
|
|
cd ..
|
2017-09-09 15:23:20 +01:00
|
|
|
|
2012-11-07 20:10:39 +00:00
|
|
|
# Symlink required system images
|
2017-09-09 15:23:20 +01:00
|
|
|
|
2012-11-07 20:10:39 +00:00
|
|
|
mkdir -p system-images
|
|
|
|
cd system-images
|
2017-09-09 15:23:20 +01:00
|
|
|
|
2013-07-31 17:56:27 +01:00
|
|
|
${stdenv.lib.concatMapStrings (abiVersion:
|
|
|
|
stdenv.lib.concatMapStrings (platformVersion:
|
|
|
|
if (builtins.hasAttr ("sysimg_" + abiVersion + "_" + platformVersion) sysimages) then
|
|
|
|
let
|
|
|
|
sysimg = builtins.getAttr ("sysimg_" + abiVersion + "_" + platformVersion) sysimages;
|
|
|
|
in
|
|
|
|
''
|
|
|
|
mkdir -p android-${platformVersion}
|
|
|
|
cd android-${platformVersion}
|
|
|
|
ln -s ${sysimg}/*
|
|
|
|
cd ..
|
|
|
|
''
|
|
|
|
else ""
|
|
|
|
) platformVersions
|
|
|
|
) abiVersions}
|
2017-09-09 15:23:20 +01:00
|
|
|
|
2012-11-08 14:01:06 +00:00
|
|
|
# Create wrappers to the most important tools and platform tools so that we can run them if the SDK is in our PATH
|
2017-09-09 15:23:20 +01:00
|
|
|
|
2014-06-30 13:56:10 +01:00
|
|
|
mkdir -p $out/bin
|
2012-11-08 14:01:06 +00:00
|
|
|
|
2016-07-25 20:47:39 +01:00
|
|
|
for i in $out/libexec/tools/*
|
2012-11-08 14:01:06 +00:00
|
|
|
do
|
|
|
|
if [ ! -d $i ] && [ -x $i ]
|
|
|
|
then
|
2013-08-07 21:12:44 +01:00
|
|
|
ln -sf $i $out/bin/$(basename $i)
|
2012-11-08 14:01:06 +00:00
|
|
|
fi
|
|
|
|
done
|
2017-09-09 15:23:20 +01:00
|
|
|
|
2018-10-23 00:00:14 +01:00
|
|
|
for i in $out/libexec/tools/bin/*
|
|
|
|
do
|
|
|
|
if [ ! -d $i ] && [ -x $i ]
|
|
|
|
then
|
|
|
|
ln -sf $i $out/bin/$(basename $i)
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
2016-07-25 20:47:39 +01:00
|
|
|
for i in $out/libexec/platform-tools/*
|
2012-11-08 14:01:06 +00:00
|
|
|
do
|
|
|
|
if [ ! -d $i ] && [ -x $i ]
|
|
|
|
then
|
2013-08-07 21:12:44 +01:00
|
|
|
ln -sf $i $out/bin/$(basename $i)
|
2012-11-08 14:01:06 +00:00
|
|
|
fi
|
|
|
|
done
|
2014-11-24 08:46:09 +00:00
|
|
|
|
2016-07-25 20:47:39 +01:00
|
|
|
for i in $out/libexec/build-tools/*/*
|
2014-11-24 08:46:09 +00:00
|
|
|
do
|
|
|
|
if [ ! -d $i ] && [ -x $i ]
|
|
|
|
then
|
|
|
|
ln -sf $i $out/bin/$(basename $i)
|
|
|
|
fi
|
|
|
|
done
|
2018-10-23 00:00:14 +01:00
|
|
|
|
2018-10-31 12:16:05 +00:00
|
|
|
for i in $out/libexec/emulator/*
|
|
|
|
do
|
|
|
|
if [ ! -d $i ] && [ -x $i ]
|
|
|
|
then
|
|
|
|
ln -sf $i $out/bin/$(basename $i)
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
2018-10-23 00:00:14 +01:00
|
|
|
wrapProgram $out/bin/sdkmanager \
|
|
|
|
--set JAVA_HOME ${jdk}
|
|
|
|
|
|
|
|
yes | ANDROID_SDK_HOME=$(mktemp -d) $out/bin/sdkmanager --licenses || true
|
2012-11-07 20:10:39 +00:00
|
|
|
'';
|
2017-09-09 15:23:20 +01:00
|
|
|
|
2012-11-08 15:49:36 +00:00
|
|
|
buildInputs = [ unzip makeWrapper ];
|
2016-08-02 17:06:29 +01:00
|
|
|
|
|
|
|
meta = {
|
|
|
|
platforms = stdenv.lib.platforms.unix;
|
2016-08-02 20:55:43 +01:00
|
|
|
hydraPlatforms = [];
|
2018-08-06 15:14:36 +01:00
|
|
|
license = stdenv.lib.licenses.unfree;
|
2016-08-02 17:06:29 +01:00
|
|
|
};
|
2012-11-07 20:10:39 +00:00
|
|
|
}
|