4

I have android sdk installed, and I want the binaries in build-tools/android-VERSION to be available in PATH, so I add few lines:

ANDROID_SDK=/Application/Binaries/adt-bundle-linux-x86_64-20140321/sdk/
ANDROID_PATH=$ANDROID_SDK/tools:$ANDROID_SDK/platform-tools:$ANDROID_SDK/build-tools/android-4.4.2/

Here's the problem, I might update the SDK at any time, so build-tools/android-4.4.2/ might change upon that. If so I would have to edit the file again and update the android-version part in $PATH

So I changed the profile to something like this,

ANDROID_SDK=/Application/Binaries/adt-bundle-linux-x86_64-20140321/sdk/
ANDROID_PATH=$ANDROID_SDK/tools:$ANDROID_SDK/platform-tools
for x in $ANDROID_SDK/build-tools/android-*/; do
    export PATH=$PATH:$x
done

That looks dumb, any better way to write it?

  • @devnull not files, "paths" – daisy Mar 30 '14 at 8:07
  • @devnull okay added a trailing slash – daisy Mar 30 '14 at 8:08
  • It's not clear what you're trying to achieve here. Are you trying to do something so as to avoid editing your ~/.bashrc or ~/.profile? – devnull Mar 30 '14 at 8:21
  • @devnull Yes exactly – daisy Mar 30 '14 at 8:22
  • @devnull Just elaborated the question – daisy Mar 30 '14 at 8:23
3

The ideal way is creating a soft link directory called adt, and re-creating it after SDK changes.

Thus, your PATH will stay the same.

  • This looks like the most reasonable one. – daisy Jul 14 '14 at 0:17
0

In this approach, on two occasions the output of ls, sorted on time and for directories only (-td), is piped to the head command which then selects the first line. The result is that the most recent version of both adt-bundle-linux-x86_64-*/sdk and of build-tools/android-*/ should be used for the modification of the PATH environment variable.

ANDROID_SDK=$( ls -td /Application/Binaries/adt-bundle-linux-x86_64-*/sdk/ | head -n 1 )
if ! [ -z $ANDROID_SDK ] ; then
    ANDROID_PATH=$ANDROID_SDK/tools:$ANDROID_SDK/platform-tools
    ANDROID_BUILDTOOLS=$( ls -td $ANDROID_SDK/build-tools/android-*/ | head -n 1 )
    if ! [ -z $ANDROID_BUILDTOOLS ] ; then
        echo "Adding $ANDROID_BUILDTOOLS to PATH"
        export PATH=$PATH:$ANDROID_BUILDTOOLS
    else
        echo "Couldn't find build tools"
    fi
else
    echo "Couldn't find SDK"
fi
0
PATH="$PATH:$(printf '%s:' $ANDROID_SDK/build-tools/android-[0-9.]*/)"

Should work.

cd ~ ; mkdir dir1 dir2 dir3
( PATH=$(printf %s: $HOME/dir[12])
echo "$PATH" )

/home/mikeserv/dir1:/home/mikeserv/dir2:

Another method:

PATH="$PATH:$( set -- `printf '%s\n' "$ANDROID_SDK"*/android[0-9.]*/ |
    sort -rV` ; [ -d "$1" ] && echo "$1" )"

That takes advantage of sort's -Version handling, which should ensure that the positional parameter "$1" is always set to the latest version of your Android SDK. For example:

WITHOUT SORT:

% printf %s\\n ~/dir[0-9]*
/home/mikeserv/dir1
/home/mikeserv/dir2
/home/mikeserv/dir23
/home/mikeserv/dir3
/home/mikeserv/dir45

WITH IT:

%  printf %s\\n ~/dir[0-9]* | sort -V
/home/mikeserv/dir1
/home/mikeserv/dir2
/home/mikeserv/dir3
/home/mikeserv/dir23
/home/mikeserv/dir45

AND REVERSED:

% printf %s\\n ~/dir[0-9]* | sort -rV
/home/mikeserv/dir45
/home/mikeserv/dir23
/home/mikeserv/dir3
/home/mikeserv/dir2
/home/mikeserv/dir1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.