anchor.diff:      mkdir -p $out/bin
       
       cat > $out/bin/run-test-emulator << "EOF"
  -    #!/bin/sh -e
  +    #! ${stdenv.shell} -e
       
       # We need a TMPDIR
       if [ "$TMPDIR" = "" ]
  
positive.code:     echo "ready" >&2
      
      ${stdenv.lib.optionalString (app != null) ''
        # Install the App through the debugger
        
        if [ -d "${app}" ]
        then
            appPath="$(echo ${app}/*.apk)"
        else
            appPath="${app}"
        fi
        
        ${androidsdkComposition}/libexec/android-sdk-*/platform-tools/adb -s emulator-$port install "$appPath"
      
        # Start the application
        ${stdenv.lib.optionalString (package != null && activity != null) ''
  
negative.code:     
      export ANDROID_SERIAL="emulator-$port"
      
      # Create a virtual android device for testing if it does not exists
      
      if [ "$(android list avd | grep 'Name: device')" = "" ]
      then
          # Create a virtual android device
          yes "" | ${androidsdkComposition}/libexec/android-sdk-*/tools/android create avd -n device -t ${if useGoogleAPIs then "'Google Inc.:Google APIs:"+platformVersion+"'" else "android-"+platformVersion} $NIX_ANDROID_AVD_FLAGS
      
          ${stdenv.lib.optionalString enableGPU ''
            # Enable GPU acceleration
            echo "hw.gpu.enabled=yes" >> $ANDROID_SDK_HOME/.android/avd/device.avd/config.ini
          ''}
      
          ${stdenv.lib.concatMapStrings (extraAVDFile: ''
            ln -sf ${extraAVDFile} $ANDROID_SDK_HOME/.android/avd/device.avd
          '') extraAVDFiles}
      fi
      
      # Launch the emulator
      ${androidsdkComposition}/libexec/android-sdk-*/tools/emulator -avd device -no-boot-anim -port $port $NIX_ANDROID_EMULATOR_FLAGS &
  