Skip to content

Commit 842d5ae

Browse files
author
Jens Driller
committed
Grab applicationId from product flavor (#1)
1 parent 6cf7217 commit 842d5ae

File tree

2 files changed

+4
-7
lines changed

2 files changed

+4
-7
lines changed

plugin/src/main/groovy/com/jenzz/buildconstants/BuildConstantsPlugin.groovy

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ class BuildConstantsPlugin implements Plugin<Project> {
2424
def generateConstantsTask = project.tasks.create([name : "generate${variantName}BuildConstants",
2525
description: "Generates both Java and XML build constants",
2626
type : BuildConstantsTask], {
27+
appId = variant.applicationId
2728
variantDir = variant.dirName
2829
constants = project.buildConstants.constants
2930
})

plugin/src/main/groovy/com/jenzz/buildconstants/BuildConstantsTask.groovy

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import org.gradle.api.tasks.TaskAction
1616

1717
class BuildConstantsTask extends DefaultTask {
1818

19+
@Input String appId
1920
@Input String variantDir
2021
@Input Map<String, Object> constants
2122

@@ -43,7 +44,7 @@ class BuildConstantsTask extends DefaultTask {
4344
private File createJavaFile() {
4445
String fileNameInput = project.buildConstants.javaFileName
4546
String fileName = javaFileName = new JavaFileNameSanitizer().sanitize fileNameInput
46-
new JavaFileFactory(appId(), project.buildDir.path, variantDir, new AppIdToPathMapper()).create fileName
47+
new JavaFileFactory(appId, project.buildDir.path, variantDir, new AppIdToPathMapper()).create fileName
4748
}
4849

4950
@NonNull
@@ -54,15 +55,10 @@ class BuildConstantsTask extends DefaultTask {
5455
}
5556

5657
private void brewJava() {
57-
new JavaConstantsWriter(javaFile, appId(), javaFileName).write constants
58+
new JavaConstantsWriter(javaFile, appId, javaFileName).write constants
5859
}
5960

6061
private void brewXml() {
6162
new XmlConstantsWriter(xmlFile).write constants
6263
}
63-
64-
@NonNull
65-
private String appId() {
66-
project.android.defaultConfig.applicationId
67-
}
6864
}

0 commit comments

Comments
 (0)