error about invalid target, first try @code{init=rm -rf bin/}; otherwise this 
 parameter should do the trick.
 
+Please note that gradle builds should be using compilesdk=.
+
+@item compilesdk=<level>
+Practically accomplishes the same that target= does when used in ant and maven
+projects. compilesdk= is used rather than target= so as to not cause any more
+confusion. It only takes effect on gradle builds in the build.gradle file,
+thus using it in any other case is not wise.
+
 @item update=xxx
 By default, 'android update project' is used to generate or update the
 build.xml file. Specifying update=no bypasses that.
 
         p = subprocess.Popen(mvncmd, cwd=root_dir, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
     elif 'gradle' in thisbuild:
         flavour = thisbuild['gradle']
-        p = subprocess.Popen([gradle, 'assemble'+flavour+'Release'], cwd=root_dir, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
+
+        if 'compilesdk' in thisbuild:
+            level = thisbuild["compilesdk"].split('-')[1]
+            subprocess.call(['sed', '-i',
+                    's@compileSdkVersion[ ]*[0-9]*@compileSdkVersion '+level+'@g',
+                    'build.gradle'], cwd=root_dir)
+
+        subprocess.call(['sed', '-i',
+                's@buildToolsVersion[ ]*["\'][0-9\.]*["\']@buildToolsVersion "'+build_tools+'"@g',
+                'build.gradle'], cwd=root_dir)
+
+        subprocess.call(['sed', '-i',
+                's@com.android.tools.build:gradle:[0-9\.\+]*@com.android.tools.build:gradle:'+target+'@g',
+                'build.gradle'], cwd=root_dir)
+        
+        if install:
+            commands = [gradle, 'assemble'+flavour+'Debug', 'install'+flavour+'Debug']
+        else:
+            commands = [gradle, 'assemble'+flavour+'Release']
+
+        p = subprocess.Popen(commands, cwd=root_dir, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
     else:
         if install:
             antcommands = ['debug','install']