Skip to content

Commit

Permalink
android: optimize assets copy
Browse files Browse the repository at this point in the history
Optimizes the nodejs-project copy by building a list of the
paths and files that should be copied and using them at runtime.
Avoids the use of AssetManager.list(), as it has performance issues
on older Android versions (<=6).
The copy is started asynchronously on plugin initialization.
  • Loading branch information
enricogior authored and jaimecbernardo committed Jan 16, 2018
1 parent c32ace3 commit ae837b2
Show file tree
Hide file tree
Showing 2 changed files with 246 additions and 113 deletions.
31 changes: 29 additions & 2 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ android {
main {
jniLibs.srcDirs 'libnode/bin/'
}
main.assets.srcDirs += '../../../nodejs-assets'
main.assets.srcDirs += '../install/resources/nodejs-modules'
}

Expand All @@ -57,4 +56,32 @@ repositories {
dependencies {
compile 'com.facebook.react:react-native:+'
}


task GenerateNodeProjectAssetsLists {
description "Generates a list for runtime copying"

doLast{
String file_list = "";
String dir_list = "";

def assets_tree = fileTree(dir: "${rootProject.projectDir}/../nodejs-assets/")
assets_tree.include('nodejs-project/**') // Include the node project.
assets_tree.exclude('**/.*') // Exclude files and dirs starting with .
assets_tree.exclude('**/*~') // Exclude temporary files.
assets_tree.visit { assetFile ->
if (assetFile.isDirectory()) {
dir_list += "${assetFile.relativePath}\n"
} else {
file_list += "${assetFile.relativePath}\n"
}
}
def file_list_path = new File( "${rootProject.projectDir}/../nodejs-assets/file.list")
file_list_path.write file_list
def dir_list_path = new File( "${rootProject.projectDir}/../nodejs-assets/dir.list")
dir_list_path.write dir_list
}

project.android.sourceSets.main.assets.srcDirs+="${rootProject.projectDir}/../nodejs-assets/"
}

tasks.getByPath(":${project.name}:preBuild").dependsOn GenerateNodeProjectAssetsLists
Loading

0 comments on commit ae837b2

Please sign in to comment.