forked from oblador/react-native-vector-icons
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(android): refactor font copy / support android gradle plugin 4.1+
- react-native JS bundle doesn't copy per-release target - react-native JS bundle adds the copy task as dependent very carefully now! - I added some metadata for the task, a "group" and "description" - Fixed formatting, 4-space indents was predominant, I went with that everywhere this is based heavily off the react-native JS bundle copy task this was developed in collaboration with @gulshan183 Fixes oblador#1265
- Loading branch information
Showing
1 changed file
with
34 additions
and
41 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,58 +1,51 @@ | ||
/** | ||
* Task to copy icon font files | ||
*/ | ||
afterEvaluate { | ||
def config = project.hasProperty("vectoricons") ? project.vectoricons : []; | ||
def iconFontsDir = config.iconFontsDir ?: "../../node_modules/react-native-vector-icons/Fonts"; | ||
def iconFontNames = config.iconFontNames ?: [ "*.ttf" ]; | ||
|
||
def config = project.hasProperty("vectoricons") ? project.vectoricons : []; | ||
|
||
def iconFontsDir = config.iconFontsDir ?: "../../node_modules/react-native-vector-icons/Fonts"; | ||
def iconFontNames = config.iconFontNames ?: [ "*.ttf" ]; | ||
|
||
gradle.projectsEvaluated { | ||
android.applicationVariants.all { def variant -> | ||
def targetName = variant.name.capitalize() | ||
def targetPath = variant.dirName | ||
|
||
// Create task for copying fonts | ||
def currentFontTask = tasks.create( | ||
name: "copy${targetName}IconFonts", | ||
type: Copy) { | ||
into("${buildDir}/intermediates") | ||
def currentFontCopyTask = tasks.create( | ||
name: "copy${targetName}ReactNativeVectorIconFonts", | ||
type: Copy) { | ||
group = "react" | ||
description = "copy fonts into ${targetName}." | ||
|
||
into("$buildDir/intermediates") | ||
|
||
iconFontNames.each { fontName -> | ||
|
||
from(iconFontsDir) { | ||
include(fontName) | ||
into("assets/${targetPath}/fonts/") | ||
} | ||
|
||
// Workaround for Android Gradle Plugin 3.2+ new asset directory | ||
from(iconFontsDir) { | ||
include(fontName) | ||
into("merged_assets/${variant.name}/merge${targetName}Assets/out/fonts/") | ||
} | ||
|
||
// Workaround for Android Gradle Plugin 3.4+ new asset directory | ||
from(iconFontsDir) { | ||
include(fontName) | ||
into("merged_assets/${variant.name}/out/fonts/") | ||
} | ||
from(iconFontsDir) { | ||
include(fontName) | ||
into("assets/${targetPath}/fonts/") | ||
} | ||
|
||
// Workaround for Android Gradle Plugin 3.2+ new asset directory | ||
from(iconFontsDir) { | ||
include(fontName) | ||
into("merged_assets/${variant.name}/merge${targetName}Assets/out/fonts/") | ||
} | ||
|
||
// Workaround for Android Gradle Plugin 3.4+ new asset directory | ||
from(iconFontsDir) { | ||
include(fontName) | ||
into("merged_assets/${variant.name}/out/fonts/") | ||
} | ||
} | ||
} | ||
|
||
currentFontTask.dependsOn("merge${targetName}Resources") | ||
currentFontTask.dependsOn("merge${targetName}Assets") | ||
|
||
[ | ||
"processArmeabi-v7a${targetName}Resources", | ||
"processX86${targetName}Resources", | ||
"processUniversal${targetName}Resources", | ||
"process${targetName}Resources" | ||
].each { name -> | ||
Task dependentTask = tasks.findByPath(name); | ||
|
||
if (dependentTask != null) { | ||
dependentTask.dependsOn(currentFontTask) | ||
} | ||
// mergeAssets must run first, as it clears the intermediates directory | ||
dependsOn(variant.mergeAssetsProvider.get()) | ||
} | ||
|
||
// mergeResources task runs before the bundle file is copied to the intermediate asset directory from Android plugin 4.1+. | ||
// This ensures to copy the bundle file before mergeResources task starts | ||
def mergeResourcesTask = tasks.findByName("merge${targetName}Resources") | ||
mergeResourcesTask.dependsOn(currentFontCopyTask) | ||
} | ||
} |