Are frequent builds packed and updates released constantly disrupting your tou LAN? (◐ ‿ ◑)

This is a simple “short” solution that leaves Apk’s build parameters entirely external. Build apK directly through external configuration of version information, server address, channel, build SDK version, etc., without the need for developers to modify and submit gradle files again, free your hands.

The above scenario actually comes from the recent daily needs. Because the construction, testing and release of the project are all completed in a fixed packaging server, that is, remote packaging, and then generate two-dimensional code download.

However, most of the time, server, test, or production personnel need to build some custom APK from time to time, such as different server addresses, different build SDK versions, different version number information, so filtering, and so on. Added: ak47 schematic item and loot added at first due to busy LAN, ak47 schematic item and loot added are added as needed.

Gradle already uses Groovy as the language and imports Java’s base classes by default. Groovy also supports Java language features.

Gradle can be implemented in two simple steps:

  • 1, define the method, through Java HttpURLConnection, simply obtain the user configured parameter information, through Groovy JsonSlurper parsing data.

  • 2. Fill the configuration information returned by the server into the parameters required for Gradle packaging, and then package the corresponding APK.

To start packaging, the server presents a simple page where the user selects and enters the version number, version name, channel, server address, etc. of the APK to be packaged, and then performs gradlew packaging. Gradle scripts will first request the current configuration information, fill in the APK required for direct packaging, and free you up to do your job, and then do whatever you want.

Of course, this is not necessarily the best implementation scenario, but for me, under the current conditions, it is really the most appropriate, one of the simple and convenient solutions. This article is not a profound thing, only a simple solution record, after all, I still want to use shell script to package the apK to sit the second processing ( ̄^ ̄)

Import groovy.jsonslurper def getTenantVersionName(def apkName) {// Request server address for package information def urlString ="http://xxxxxx? appName=${apkName}"
    def url = new URL(urlString)
    def packageInfoResult = null
    HttpURLConnection conn = (HttpURLConnection) url.openConnection()
    conn.setRequestMethod('GET')
    conn.setConnectTimeout(5000)
    int code = conn.getResponseCode()
    if(code == 200) {// Request succeeded InputStream is = conn.getinputStream () ByteArrayOutputStream baos = new ByteArrayOutputStream(); byte[] buffer = new byte[1024] int len = 0while((len = is.read(buffer)) ! = -1) { baos.write(buffer, 0, Byte [] byteArray = baos.tobytearray () def result = new String(byteArray) def JsonSlurper = new JsonSlurper() packageInfoResult = JsonSlurper.parseText(result) }return packageInfoResult
}
Copy the code

The last

You might just be configuring Gradle on a daily basis, but as you get deeper and deeper, you might not even want to answer your girlfriend’s phone if