2012-11-08 15:49:36 +00:00
|
|
|
{ stdenv, stdenv_32bit, fetchurl, unzip, makeWrapper
|
2014-08-02 02:26:21 +01:00
|
|
|
, platformTools, buildTools, support, supportRepository, platforms, sysimages, addons
|
2012-11-07 20:10:39 +00:00
|
|
|
, zlib_32bit
|
2013-08-05 21:18:56 +01:00
|
|
|
, libX11_32bit, libxcb_32bit, libXau_32bit, libXdmcp_32bit, libXext_32bit, mesa_32bit, alsaLib_32bit
|
2013-08-07 21:12:44 +01:00
|
|
|
, libX11, libXext, libXrender, libxcb, libXau, libXdmcp, libXtst, mesa, alsaLib
|
2015-05-03 15:03:36 +01:00
|
|
|
, freetype, fontconfig, glib, gtk, atk, file, jdk, coreutils
|
2012-11-07 20:10:39 +00:00
|
|
|
}:
|
2015-10-06 13:27:49 +01:00
|
|
|
{ platformVersions, abiVersions, useGoogleAPIs, useExtraSupportLibs ? false, useGooglePlayServices ? false }:
|
2012-11-07 20:10:39 +00:00
|
|
|
|
2014-05-07 23:49:19 +01:00
|
|
|
stdenv.mkDerivation rec {
|
|
|
|
name = "android-sdk-${version}";
|
2015-10-06 13:27:49 +01:00
|
|
|
version = "24.3.4";
|
2014-12-16 07:22:55 +00:00
|
|
|
|
2012-11-07 20:10:39 +00:00
|
|
|
src = if (stdenv.system == "i686-linux" || stdenv.system == "x86_64-linux")
|
|
|
|
then fetchurl {
|
2014-05-07 23:49:19 +01:00
|
|
|
url = "http://dl.google.com/android/android-sdk_r${version}-linux.tgz";
|
2015-10-06 13:27:49 +01:00
|
|
|
sha1 = "fb293d7bca42e05580be56b1adc22055d46603dd";
|
2012-11-07 20:10:39 +00:00
|
|
|
}
|
|
|
|
else if stdenv.system == "x86_64-darwin" then fetchurl {
|
2014-05-07 23:49:19 +01:00
|
|
|
url = "http://dl.google.com/android/android-sdk_r${version}-macosx.zip";
|
2015-10-06 13:27:49 +01:00
|
|
|
sha1 = "128f10fba668ea490cc94a08e505a48a608879b9";
|
2012-11-07 20:10:39 +00:00
|
|
|
}
|
|
|
|
else throw "platform not ${stdenv.system} supported!";
|
2014-12-16 07:22:55 +00:00
|
|
|
|
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
|
2012-11-07 20:10:39 +00:00
|
|
|
cd android-sdk-*/tools
|
2015-05-03 15:03:36 +01:00
|
|
|
|
|
|
|
for f in android traceview draw9patch hierarchyviewer monitor ddms screenshot2 uiautomatorviewer monkeyrunner jobb lint
|
|
|
|
do
|
|
|
|
sed -i -e "s|/bin/ls|${coreutils}/bin/ls|" "$f"
|
|
|
|
done
|
|
|
|
|
2012-11-07 20:10:39 +00:00
|
|
|
${stdenv.lib.optionalString (stdenv.system == "i686-linux" || stdenv.system == "x86_64-linux")
|
|
|
|
''
|
|
|
|
# There are a number of native binaries. We must patch them to let them find the interpreter and libstdc++
|
2014-09-02 18:18:30 +01:00
|
|
|
|
|
|
|
for i in emulator emulator-arm emulator-mips emulator-x86 mksdcard
|
2012-11-07 20:10:39 +00:00
|
|
|
do
|
2014-12-26 17:33:16 +00:00
|
|
|
patchelf --set-interpreter ${stdenv_32bit.cc.libc}/lib/ld-linux.so.2 $i
|
2015-01-15 04:51:58 +00:00
|
|
|
patchelf --set-rpath ${stdenv_32bit.cc.cc}/lib $i
|
2012-11-07 20:10:39 +00:00
|
|
|
done
|
2014-09-02 18:18:30 +01:00
|
|
|
|
2012-12-20 13:04:52 +00:00
|
|
|
${stdenv.lib.optionalString (stdenv.system == "x86_64-linux") ''
|
|
|
|
# We must also patch the 64-bit emulator instances, if needed
|
|
|
|
|
|
|
|
for i in emulator64-arm emulator64-mips emulator64-x86
|
|
|
|
do
|
2014-12-17 18:11:30 +00:00
|
|
|
patchelf --set-interpreter ${stdenv.cc.libc}/lib/ld-linux-x86-64.so.2 $i
|
2015-01-15 04:25:26 +00:00
|
|
|
patchelf --set-rpath ${stdenv.cc.cc}/lib64 $i
|
2012-12-20 13:04:52 +00:00
|
|
|
done
|
|
|
|
''}
|
|
|
|
|
2013-08-07 21:12:44 +01:00
|
|
|
# The android script used SWT and wants to dynamically load some GTK+ stuff.
|
|
|
|
# The following wrapper ensures that they can be found:
|
|
|
|
wrapProgram `pwd`/android \
|
2013-08-08 09:40:09 +01:00
|
|
|
--prefix PATH : ${jdk}/bin \
|
2013-08-07 21:12:44 +01:00
|
|
|
--prefix LD_LIBRARY_PATH : ${glib}/lib:${gtk}/lib:${libXtst}/lib
|
|
|
|
|
|
|
|
# The emulators need additional libraries, which are dynamically loaded => let's wrap them
|
2012-11-07 20:10:39 +00:00
|
|
|
|
2012-12-20 13:04:52 +00:00
|
|
|
for i in emulator emulator-arm emulator-mips emulator-x86
|
2012-11-07 20:10:39 +00:00
|
|
|
do
|
|
|
|
wrapProgram `pwd`/$i \
|
2013-08-05 21:18:56 +01:00
|
|
|
--prefix PATH : ${file}/bin \
|
2013-08-01 11:43:33 +01:00
|
|
|
--suffix LD_LIBRARY_PATH : `pwd`/lib:${libX11_32bit}/lib:${libxcb_32bit}/lib:${libXau_32bit}/lib:${libXdmcp_32bit}/lib:${libXext_32bit}/lib:${mesa_32bit}/lib
|
2012-11-07 20:10:39 +00:00
|
|
|
done
|
2012-12-20 13:04:52 +00:00
|
|
|
|
|
|
|
${stdenv.lib.optionalString (stdenv.system == "x86_64-linux") ''
|
|
|
|
for i in emulator64-arm emulator64-mips emulator64-x86
|
|
|
|
do
|
|
|
|
wrapProgram `pwd`/$i \
|
2013-08-05 21:18:56 +01:00
|
|
|
--prefix PATH : ${file}/bin \
|
|
|
|
--suffix LD_LIBRARY_PATH : `pwd`/lib:${libX11}/lib:${libxcb}/lib:${libXau}/lib:${libXdmcp}/lib:${libXext}/lib:${mesa}/lib:${alsaLib}/lib
|
2012-12-20 13:04:52 +00:00
|
|
|
done
|
|
|
|
''}
|
2012-11-07 20:10:39 +00:00
|
|
|
''}
|
|
|
|
|
2012-11-08 15:49:36 +00:00
|
|
|
patchShebangs .
|
|
|
|
|
2012-11-07 20:10:39 +00:00
|
|
|
${if stdenv.system == "i686-linux" then
|
|
|
|
''
|
|
|
|
# The monitor requires some more patching
|
|
|
|
|
|
|
|
cd lib/monitor-x86
|
2014-12-17 18:11:30 +00:00
|
|
|
patchelf --set-interpreter ${stdenv.cc.libc}/lib/ld-linux.so.2 monitor
|
2012-11-07 20:10:39 +00:00
|
|
|
patchelf --set-rpath ${libX11}/lib:${libXext}/lib:${libXrender}/lib:${freetype}/lib:${fontconfig}/lib libcairo-swt.so
|
|
|
|
|
|
|
|
wrapProgram `pwd`/monitor \
|
2015-05-03 15:03:36 +01:00
|
|
|
--prefix LD_LIBRARY_PATH : ${gtk}/lib:${atk}/lib:${stdenv.cc.cc}/lib:${libXtst}/lib
|
2012-11-07 20:10:39 +00:00
|
|
|
|
|
|
|
cd ../..
|
|
|
|
''
|
|
|
|
else if stdenv.system == "x86_64-linux" then
|
|
|
|
''
|
|
|
|
# The monitor requires some more patching
|
|
|
|
|
|
|
|
cd lib/monitor-x86_64
|
2014-12-17 18:11:30 +00:00
|
|
|
patchelf --set-interpreter ${stdenv.cc.libc}/lib/ld-linux-x86-64.so.2 monitor
|
2012-11-07 20:10:39 +00:00
|
|
|
patchelf --set-rpath ${libX11}/lib:${libXext}/lib:${libXrender}/lib:${freetype}/lib:${fontconfig}/lib libcairo-swt.so
|
|
|
|
|
|
|
|
wrapProgram `pwd`/monitor \
|
2015-05-03 15:03:36 +01:00
|
|
|
--prefix LD_LIBRARY_PATH : ${gtk}/lib:${atk}/lib:${stdenv.cc.cc}/lib::${libXtst}/lib
|
2012-11-07 20:10:39 +00:00
|
|
|
|
|
|
|
cd ../..
|
|
|
|
''
|
|
|
|
else ""}
|
|
|
|
|
|
|
|
# Symlink the other sub packages
|
|
|
|
|
|
|
|
cd ..
|
|
|
|
ln -s ${platformTools}/platform-tools
|
2013-07-31 15:00:57 +01:00
|
|
|
ln -s ${buildTools}/build-tools
|
2012-11-07 20:10:39 +00:00
|
|
|
ln -s ${support}/support
|
|
|
|
|
|
|
|
# Symlink required Google API add-ons
|
|
|
|
|
|
|
|
mkdir -p add-ons
|
|
|
|
cd add-ons
|
|
|
|
|
|
|
|
${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 ""}
|
|
|
|
|
|
|
|
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 ""}
|
|
|
|
|
2014-08-02 02:26:21 +01:00
|
|
|
cd ../..
|
|
|
|
|
2012-11-07 20:10:39 +00:00
|
|
|
# Symlink required platforms
|
|
|
|
|
|
|
|
mkdir -p platforms
|
|
|
|
cd platforms
|
|
|
|
|
|
|
|
${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}
|
|
|
|
|
|
|
|
cd ..
|
|
|
|
|
|
|
|
# Symlink required system images
|
|
|
|
|
|
|
|
mkdir -p system-images
|
|
|
|
cd system-images
|
|
|
|
|
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}
|
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
|
|
|
|
|
2014-06-30 13:56:10 +01:00
|
|
|
mkdir -p $out/bin
|
2012-11-08 14:01:06 +00:00
|
|
|
|
|
|
|
for i in $out/libexec/android-sdk-*/tools/*
|
|
|
|
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
|
|
|
|
|
|
|
|
for i in $out/libexec/android-sdk-*/platform-tools/*
|
|
|
|
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
|
|
|
|
|
|
|
for i in $out/libexec/android-sdk-*/build-tools/android-*/*
|
|
|
|
do
|
|
|
|
if [ ! -d $i ] && [ -x $i ]
|
|
|
|
then
|
|
|
|
ln -sf $i $out/bin/$(basename $i)
|
|
|
|
fi
|
|
|
|
done
|
2012-11-07 20:10:39 +00:00
|
|
|
'';
|
|
|
|
|
2012-11-08 15:49:36 +00:00
|
|
|
buildInputs = [ unzip makeWrapper ];
|
2012-11-07 20:10:39 +00:00
|
|
|
}
|