Created
April 17, 2020 14:39
-
-
Save abhimuktheeswarar/ac65a7239a70a31a05af5d9f1457fc21 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import groovy.json.JsonOutput | |
import groovy.json.JsonSlurper | |
class ActivityPostBody { | |
Activity[] app_content | |
String app_id | |
String app_version | |
} | |
class Activity { | |
String ActivityName | |
String ActivityPath | |
} | |
task parseActivitiesInManifest() { | |
doLast { | |
def manifest = new XmlSlurper().parse(android.sourceSets.main.manifest.srcFile) | |
println manifest.@package | |
String pkg = manifest.@package | |
def activities = [:] | |
def activityList = [] | |
manifest.application.activity.each { | |
String actName = it.'@android:name' | |
String modifiedName = it.'@android:name' | |
if (actName.substring(0, 1) == '.') { | |
actName = actName.replace(".", "") | |
modifiedName = pkg + "." + actName | |
} | |
println("$actName -> $modifiedName") | |
activities[actName] = modifiedName | |
def activity = new Activity(ActivityName: actName, ActivityPath: modifiedName) | |
activityList.add(activity) | |
} | |
def activityPostBody = new ActivityPostBody(app_content: activityList, app_id: project.android.defaultConfig.applicationId, app_version: "${project.android.defaultConfig.versionCode}") | |
def output = JsonOutput.toJson(activityPostBody) | |
println("version = ${project.android.defaultConfig.versionCode}") | |
println(output) | |
return | |
def req = new URL('http://yourserver.com/upload').openConnection() | |
req.setRequestMethod("POST") | |
req.setRequestProperty("Content-Type", "application/json; charset=UTF-8") | |
req.setDoOutput(true) | |
req.getOutputStream().write(output.getBytes("UTF-8")) | |
logger.quiet "Status code: ${req.getResponseCode()}" | |
def resp = new JsonSlurper().parseText(req.getInputStream().getText()) | |
logger.quiet "Response: ${resp}" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment