NativeScript / NativeScript/nativescript-cli

Plugin's include.gradle is not properly respected when building aar

Open
#3,563 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug os: android
Dominant language
JavaScript
Stars
1.1k
Forks
204
Avg merge
1d 9h
Merged PRs (30d)
8

Description

Tell us about the problem

Currently {N} CLI detects if a plugin has any Android resources/java files/etc. and tries to build an android archive (.aar) for said plugin. During building of this .aar file CLI takes into account the plugin's include.gradle file, if it exists, however the logic for this is incomplete. Instead of only taking into account certain tags (like dependencies or repositories), it seems more appropriate that the whole include.gradle be included in the process of building the plugin's .aar file.

In other words instead of any additional parsing CLI should only include a
apply from: <path-to-plugin-include.gradle-file>

section in the plugin's build.gradle.

Which platform(s) does your issue occur on?

Android

Please tell us how to recreate the issue in as much detail as possible.
  1. tns create myApp
  2. cd myApp
  3. tns plugin add nativescript-mapbox
  4. edit node_modules/nativescript-mapbox/platforms/android/include.gradle so that the contents become:
android {
    productFlavors {
        "mapbox" {
            dimension "mapbox"
        }
    }
}

repositories {
    mavenCentral()
}

def coreLibrary = 'com.mapbox.mapboxsdk:mapbox-android-sdk:5.3.1@aar'
def serviceLibrary = 'com.mapbox.mapboxsdk:mapbox-android-services:2.2.9@aar'
def pluginsString = 'com.mapbox.mapboxsdk:mapbox-android-plugin-locationlayer:0.3.0'

// see https://www.mapbox.com/android-sdk/
dependencies {
    // core library
    compile ("$coreLibrary"){
        transitive=true
    }

    // service library
    compile ("$serviceLibrary"){
        transitive=true
    }

    // plugins
    compile "$pluginsString"
}
  1. Try to execute tns build android

CLI fails to build the .aar file in this case, because the dependencies section is copied, however it is in its essence incomplete.

This is only a dummy example to illustrate the flaw in the CLI logic. The content of the include.gradle may contain more complex logic, which needs to be taken into account.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Read lib/services/android-plugin-build-service.ts around lines 232-239, then reproduce the issue with the nativescript-mapbox include.gradle example and tns build android. Trace how include.gradle is incorporated into the plugin build; done means the complete file is applied during .aar construction rather than only selected sections being copied.

Written by the indexing model from the issue text.

Assessment

Tech stack
android, groovy, javascript
Domain
build-system, cli, mobile-dev
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.