Gradle command line package APK, output to the specified path

 Under Windows system:

 

1. Open the command line tool

2. Switch to the path of gradlew

   Example: cd C:\Users\54225\Desktop\myProject\My

3. Command line input: gradlew assembleDebug generates a debug signed apk in build\Output

                         gradlew assembleRelease generates a Release-signed apk in build\Output (signature has extra steps. Please Baidu)

 

4. Apk output to the specified path

Add a piece of code after buildTypes{..}     in build.gradle

     outputPathName fill in the path you want to output

    //This is the application compilation completed
    applicationVariants.all { variant ->
        variant.outputs.each  { output ->
            //start output
            output.outputFile = new File(outputPathName)
           //举例:output.outputFile = new File('C:\\Users\\54225\\Desktop\\my.apk')
        }
    }

 

5. The method implemented in python:

  

import them
rawPath='Your Android project path'
os.chdir(rawPath) #This is the cd of the simulated command line, switching the current path
command = 'gradlew assembleDebug' # Commands that can be executed directly on the command line
r=os.popen(command)
info = r.readlines() # read command line output to a list
for line in info: # traverse by line
    line = line.strip('\r\n')
    print(line)
    if (str(line).__contains__("Success")):
        flag = True
        break

 

6. Related reference links: http://blog.csdn.net/gxl3999/article/details/44282469

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326080854&siteId=291194637