Skip to content

Commit 071d05e

Browse files
author
Adrián García
authored
Add multi-flavor environment (#12)
1 parent 5ce043e commit 071d05e

25 files changed

+878
-222
lines changed

.idea/codeStyles/Project.xml

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/jarRepositories.xml

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

CHANGELOG.md

Lines changed: 73 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,84 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
66

77
## [Unreleased]
88
### Added
9-
- No new features!
9+
- Add support for flavor and build type configuration. The sample configuration is as follows:
10+
<details open><summary>Groovy</summary>
11+
12+
```groovy
13+
poEditor {
14+
// Default config that applies to all flavor/build type configurations.
15+
// Also executed when calling 'importPoEditorStrings'
16+
}
17+
18+
android {
19+
// If you have the following flavors...
20+
flavorDimensions 'type'
21+
productFlavors {
22+
free { dimension 'type' }
23+
paid { dimension 'type' }
24+
}
25+
26+
poEditorConfig {
27+
free {
28+
// Configuration for the free flavor, same syntax as usual
29+
}
30+
paid {
31+
// Configuration for the paid flavor, same syntax as usual
32+
}
33+
debug {
34+
// Configuration for the debug build type, same syntax as usual
35+
}
36+
release {
37+
// Configuration for the release build type, same syntax as usual
38+
}
39+
}
40+
}
41+
```
42+
43+
</details>
44+
45+
<details><summary>Kotlin</summary>
46+
47+
```kt
48+
poEditor {
49+
// Default config that applies to all flavor/build type configurations.
50+
// Also executed when calling 'importPoEditorStrings'
51+
}
52+
53+
android {
54+
// If you have the following flavors...
55+
flavorDimensions("type")
56+
57+
productFlavors {
58+
register("free") { setDimension("type") }
59+
register("paid") { setDimension("type") }
60+
}
61+
62+
poEditorConfig {
63+
register("free") {
64+
// Configuration for the free flavor, same syntax as usual
65+
}
66+
register("paid") {
67+
// Configuration for the paid flavor, same syntax as usual
68+
}
69+
register("debug") {
70+
// Configuration for the debug build type, same syntax as usual
71+
}
72+
register("release") {
73+
// Configuration for the release build type, same syntax as usual
74+
}
75+
}
76+
}
77+
```
78+
79+
</details>
80+
1081
### Changed
1182
- No changed features!
1283
### Deprecated
1384
- No deprecated features!
1485
### Removed
15-
- No removed features!
86+
- The `resDirPath` parameter is no longer needed, since it gets inferred from the flavor or build type configured in the app
1687
### Fixed
1788
- No fixed issues!
1889
### Security

README.md

Lines changed: 131 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,38 +10,77 @@ It also provides a built-in syntax to handle placeholders to enhance the already
1010
## Setting Up
1111
In your main `build.gradle`, add [jitpack.io](https://jitpack.io/) repository in the `buildscript` block and include the plug-in as a dependency:
1212

13+
<details open><summary>Groovy</summary>
14+
1315
```groovy
1416
buildscript {
1517
repositories {
1618
maven { url 'https://jitpack.io' }
1719
}
1820
dependencies {
19-
classpath 'com.github.bq:poeditor-android-gradle-plugin:1.0.0'
21+
classpath 'com.github.bq:poeditor-android-gradle-plugin:1.1.0'
22+
}
23+
}
24+
```
25+
26+
</details>
27+
28+
<details><summary>Kotlin</summary>
29+
30+
```kt
31+
buildscript {
32+
repositories {
33+
maven("https://jitpack.io")
34+
}
35+
dependencies {
36+
classpath("com.github.bq:poeditor-android-gradle-plugin:1.1.0")
2037
}
2138
}
2239
```
2340

41+
</details>
42+
2443
## How to use
2544
Apply and configure the plug-in in your app's `build.gradle` file:
45+
<details open><summary>Groovy</summary>
46+
2647
```groovy
27-
apply plugin: 'com.bq.poeditor'
48+
apply plugin: "com.android.application"
49+
apply plugin: "com.bq.poeditor"
50+
51+
poEditor {
52+
apiToken = "your_api_token"
53+
projectId = 12345
54+
defaultLang = "en"
55+
}
56+
```
57+
58+
</details>
59+
60+
<details><summary>Kotlin</summary>
61+
62+
```kt
63+
plugins {
64+
id "com.android.application"
65+
id "com.bq.poeditor"
66+
}
2867

2968
poEditor {
3069
apiToken = "your_api_token"
3170
projectId = 12345
3271
defaultLang = "en"
33-
resDirPath = "${project.rootDir}/app/src/main/res"
3472
}
3573
```
3674

75+
</details>
76+
3777
The complete attribute list is the following:
3878

3979
Attribute | Description
4080
------------------------------|-----------------------------------------
4181
```apiToken``` | PoEditor API Token.
4282
```projectId``` | PoEditor project ID.
4383
```defaultLang``` | The lang to be used to build default ```strings.xml``` (```/values``` folder)
44-
```resDirPath``` | The path to the project's ```/res``` folder.
4584

4685
After the configuration is done, just run the new ```importPoEditorStrings``` task via Android Studio or command line:
4786

@@ -55,6 +94,93 @@ This task will:
5594
* Create and save strings.xml files to ```/values-<lang>``` (or ```/values``` in case of the default lang). It supports
5695
region specific languages by creating the proper folders (i.e. ```/values-es-rMX```).
5796

97+
## Handling multiple flavors and build types
98+
99+
Sometimes we might want to import different strings for a given flavor (for example, in white label apps, we could have
100+
different string definitions depending on the brand where they're used). The plugin supports this kind of apps by providing
101+
specific configurations via the `poEditorConfig` block.
102+
103+
Let's see an example configuration:
104+
105+
<details open><summary>Groovy</summary>
106+
107+
```groovy
108+
poEditor {
109+
// Default config that applies to all flavor/build type configurations.
110+
// Also executed when calling 'importPoEditorStrings'
111+
}
112+
113+
android {
114+
// If you have the following flavors...
115+
flavorDimensions 'type'
116+
productFlavors {
117+
free { dimension 'type' }
118+
paid { dimension 'type' }
119+
}
120+
121+
poEditorConfig {
122+
free {
123+
// Configuration for the free flavor, same syntax as the standard 'poEditor' block
124+
}
125+
paid {
126+
// Configuration for the paid flavor, same syntax as the standard 'poEditor' block
127+
}
128+
debug {
129+
// Configuration for the debug build type, same syntax as the standard 'poEditor' block
130+
}
131+
release {
132+
// Configuration for the release build type, same syntax as the standard 'poEditor' block
133+
}
134+
}
135+
}
136+
```
137+
138+
</details>
139+
140+
<details><summary>Kotlin</summary>
141+
142+
```kt
143+
poEditor {
144+
// Default config that applies to all flavor/build type configurations.
145+
// Also executed when calling 'importPoEditorStrings'
146+
}
147+
148+
android {
149+
// If you have the following flavors...
150+
flavorDimensions("type")
151+
152+
productFlavors {
153+
register("free") { setDimension("type") }
154+
register("paid") { setDimension("type") }
155+
}
156+
157+
poEditorConfig {
158+
register("free") {
159+
// Configuration for the free flavor, same syntax as the standard 'poEditor' block
160+
}
161+
register("paid") {
162+
// Configuration for the paid flavor, same syntax as the standard 'poEditor' block
163+
}
164+
register("debug") {
165+
// Configuration for the debug build type, same syntax as the standard 'poEditor' block
166+
}
167+
register("release") {
168+
// Configuration for the release build type, same syntax as the standard 'poEditor' block
169+
}
170+
}
171+
}
172+
```
173+
174+
</details>
175+
176+
Each flavor (`free` and `paid`) and build type (`debug` and `release`) will have its own task to import strings for said
177+
configuration: `importFreePoEditorStrings`, `importPaidPoEditorStrings`, `importDebugPoEditorStrings` and
178+
`importReleasePoEditorStrings`.
179+
180+
Now the `importPoEditorStrings` task will import the main strings configured in the `poEditor` block and also the
181+
strings for each defined flavor or build type.
182+
183+
58184
## Handling tablet specific strings
59185

60186
You can mark some strings as tablet specific strings by adding ```_tablet```suffix to the string key in PoEditor.
@@ -75,7 +201,7 @@ The plug-in will create two `strings.xml` files:
75201
<string name="welcome_message">Hey friend how are you doing today, you look great!</string>
76202
```
77203

78-
## Handle placeholders
204+
## Handling placeholders
79205
You can add placeholders to your strings. We've defined a placeholder markup to use in PoEditor string definition: it uses a double braces syntax, like this one
80206

81207
```

build.gradle.kts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@ buildscript {
2020
repositories {
2121
mavenCentral()
2222
jcenter()
23+
google().content {
24+
includeGroup("com.android")
25+
includeGroupByRegex("com\\.android\\..*")
26+
includeGroupByRegex("com\\.google\\..*")
27+
includeGroupByRegex("androidx\\..*")
28+
}
2329
}
2430

2531
dependencies {
@@ -38,11 +44,19 @@ plugins {
3844
repositories {
3945
mavenCentral()
4046
jcenter()
47+
google().content {
48+
includeGroup("com.android")
49+
includeGroupByRegex("com\\.android\\..*")
50+
includeGroupByRegex("com\\.google\\..*")
51+
includeGroupByRegex("androidx\\..*")
52+
}
4153
}
4254

4355
dependencies {
4456
implementation(localGroovy())
4557

58+
compileOnly("com.android.tools.build:gradle:4.2.0-alpha01")
59+
4660
implementation("org.jetbrains.kotlin:kotlin-stdlib:1.3.72")
4761

4862
implementation("com.squareup.moshi:moshi:1.9.2")

gradle/wrapper/gradle-wrapper.jar

3.27 KB
Binary file not shown.
Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,5 @@
1-
#
2-
# Copyright 2020 BQ
3-
#
4-
# Licensed under the Apache License, Version 2.0 (the "License");
5-
# you may not use this file except in compliance with the License.
6-
# You may obtain a copy of the License at
7-
#
8-
# http://www.apache.org/licenses/LICENSE-2.0
9-
#
10-
# Unless required by applicable law or agreed to in writing, software
11-
# distributed under the License is distributed on an "AS IS" BASIS,
12-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13-
# See the License for the specific language governing permissions and
14-
# limitations under the License.
15-
#
16-
17-
#Thu Apr 04 09:06:52 CEST 2019
181
distributionBase=GRADLE_USER_HOME
192
distributionPath=wrapper/dists
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-6.5.1-all.zip
204
zipStoreBase=GRADLE_USER_HOME
215
zipStorePath=wrapper/dists
22-
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.4-all.zip

0 commit comments

Comments
 (0)