Skip to content

Commit 37dfe05

Browse files
authored
Merge pull request #1483 from NativeScript/trifonov/hotfix-6.1.1
Release 6.1.1
2 parents 0d908c1 + 257c263 commit 37dfe05

File tree

3 files changed

+59
-10
lines changed

3 files changed

+59
-10
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
6.1.1
2+
==
3+
4+
## Bug Fixes
5+
6+
- [When using kotlin sometimes the metadata is not existing in the result apk (#1476)](https://github.com/NativeScript/android-runtime/issues/1476)
7+
18
6.1.0
29
==
310

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "tns-android",
33
"description": "NativeScript Runtime for Android",
4-
"version": "6.1.0",
4+
"version": "6.1.1",
55
"repository": {
66
"type": "git",
77
"url": "https://github.com/NativeScript/android-runtime.git"

test-app/app/build.gradle

Lines changed: 51 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,29 @@ android {
290290
applyBeforePluginGradleConfiguration()
291291
applyPluginGradleConfigurations()
292292
applyAppGradleConfiguration()
293+
294+
def initializeMergedAssetsOutputPath = { ->
295+
android.applicationVariants.all { variant ->
296+
if (variant.buildType.name == project.selectedBuildType) {
297+
def task
298+
if (variant.metaClass.respondsTo(variant, "getMergeAssetsProvider")) {
299+
def provider = variant.getMergeAssetsProvider()
300+
task = provider.get();
301+
} else {
302+
// fallback for older android gradle plugin versions
303+
task = variant.getMergeAssets()
304+
}
305+
for (File file : task.getOutputs().getFiles()) {
306+
if (!file.getPath().contains("/incremental/")) {
307+
project.ext.mergedAssetsOutputPath = file.getPath()
308+
break;
309+
}
310+
}
311+
}
312+
}
313+
}
314+
315+
initializeMergedAssetsOutputPath()
293316
}
294317

295318
def externalRuntimeExists = !findProject(':runtime').is(null)
@@ -449,8 +472,7 @@ tasks.whenTaskAdded({ org.gradle.api.DefaultTask currentTask ->
449472
}
450473
if (currentTask =~ /compile.+JavaWithJavac/) {
451474
currentTask.dependsOn(runSbg)
452-
currentTask.finalizedBy(ensureMetadataOutDir)
453-
ensureMetadataOutDir.finalizedBy(buildMetadata)
475+
currentTask.finalizedBy(buildMetadata)
454476
}
455477
if (currentTask =~ /merge.*Assets/) {
456478
currentTask.shouldRunAfter(buildMetadata)
@@ -491,13 +513,6 @@ task runSbg(type: JavaExec) {
491513
}
492514
}
493515

494-
task ensureMetadataOutDir {
495-
doLast {
496-
def outputDir = file("$METADATA_OUT_PATH")
497-
outputDir.mkdirs()
498-
}
499-
}
500-
501516
def failOnCompilationWarningsEnabled() {
502517
return project.hasProperty("failOnCompilationWarnings") && (failOnCompilationWarnings || failOnCompilationWarnings.toBoolean())
503518
}
@@ -547,6 +562,14 @@ class EmptyRunnable implements Runnable {
547562
}
548563
}
549564

565+
def getMergedAssetsOutputPath() {
566+
if (!project.hasProperty("mergedAssetsOutputPath")) {
567+
// mergedAssetsOutputPath not found fallback to the default value for android gradle plugin 3.5.0
568+
project.ext.mergedAssetsOutputPath = "$projectDir/build/intermediates/merged_assets/" + project.selectedBuildType + "/out"
569+
}
570+
return project.ext.mergedAssetsOutputPath
571+
}
572+
550573
// Discover all jars and dynamically create tasks for the extraction of each of them
551574
project.ext.allJars = []
552575
afterEvaluate { project ->
@@ -695,11 +718,28 @@ task collectAllJars {
695718
}
696719
}
697720

721+
task copyMetadata {
722+
doLast {
723+
copy {
724+
from "$projectDir/src/main/assets/metadata"
725+
into getMergedAssetsOutputPath() + "/metadata"
726+
}
727+
}
728+
}
729+
698730
task buildMetadata(type: JavaExec) {
699731
if (!findProject(':android-metadata-generator').is(null)) {
700732
dependsOn ':android-metadata-generator:jar'
701733
}
702734

735+
// As some external gradle plugins can reorder the execution order of the tasks it may happen that buildMetadata is executed after merge{Debug/Release}Assets
736+
// in that case the metadata won't be included in the result apk and it will crash, so to avoid this we are adding the copyMetadata task which will manually copy
737+
// the metadata files in the merge assets folder and they will be added to the result apk
738+
739+
// The next line is added to avoid adding another copyData implementation from the firebase plugin - https://github.com/EddyVerbruggen/nativescript-plugin-firebase/blob/3943bb9147f43c41599e801d026378eba93d3f3a/publish/scripts/installer.js#L1105
740+
//buildMetadata.finalizedBy(copyMetadata)
741+
finalizedBy copyMetadata
742+
703743
description "builds metadata with provided jar dependencies"
704744

705745
inputs.files("$MDG_JAVA_DEPENDENCIES")
@@ -719,6 +759,8 @@ task buildMetadata(type: JavaExec) {
719759
// these need to be called after the classes have compiled
720760
assert file(classesDir).exists()
721761

762+
new File(getMergedAssetsOutputPath() + "/metadata").deleteDir()
763+
722764
def classesSubDirs = new File(classesDir).listFiles()
723765
def selectedBuildType = project.ext.selectedBuildType
724766

0 commit comments

Comments
 (0)