Created
July 28, 2020 03:01
-
-
Save zyc945/a90baaba7c92a068e194433822ed75b7 to your computer and use it in GitHub Desktop.
publish-gradle
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 | |
def android = project.extensions.android | |
def list = new ArrayList<>() | |
afterEvaluate { | |
android.applicationVariants.all { variant -> | |
def variantName = variant.name.capitalize() | |
def variantOutput = variant.outputs.first() | |
def path = variantOutput.getOutputFile().path | |
def flavorList = variant.productFlavors | |
List<String> flavorNames = new ArrayList<>() | |
for (int i = 0; i < flavorList.size(); i++) { | |
flavorNames.add(flavorList.get(i).name) | |
} | |
list.add(new Model(variantName, flavorNames, path)) | |
} | |
File file = new File("variants.json") | |
file.write(JsonOutput.toJson(list)) | |
project.logger.error("Check publish.py:") | |
def f = new File('publish.py') | |
if (f.exists()) { | |
project.logger.error("publish.py exists.") | |
} else { | |
throw new RuntimeException("You need copy a file named publish.py") | |
} | |
} | |
class Model { | |
String name | |
List<String> flavorList | |
String path | |
Model(String name, List<String> flavorList, String path) { | |
this.name = name | |
this.flavorList = flavorList | |
this.path = path | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment