Skip to content

Plamen5kov/rebuild aar #3398

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Mar 8, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ env:
- NATIVESCRIPT_SKIP_POSTINSTALL_TASKS=1
language: node_js
node_js:
- '6'
- '8'
git:
submodules: true
install:
Expand Down
28 changes: 28 additions & 0 deletions docs/man_pages/lib-management/plugin-build.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<% if (isJekyll) { %>---
title: tns plugin build
position: 8
---<% } %>
# tns plugin build
==========

Usage | Synopsis
------|-------
General | `$ tns plugin build`

<% if(isConsole) { %>Attempts to build the plugin's Android-specific project files located in `platforms/android`. Strips and removes `include.gradle` flavor declarations, if any are present. <% } %>
<% if(isHtml) { %>Attempts to build the plugin's Android-specific project files located in `platforms/android`. The resulting Android Library (aar), and the generated Android Gradle project used to build the library can be found at `platforms/android`. Also strips and removes `include.gradle` flavor declarations, if any are present. For more information about working with plugins, see [NativeScript Plugins](https://github.com/NativeScript/nativescript-cli/blob/master/PLUGINS.md).<% } %>


<% if(isHtml) { %>
### Prerequisites

* Verify that the command is being executed in the source directory of a plugin - e.g. `nativescript-barcodescanner/src`

### Related Commands

Command | Description
----------|----------
[plugin](plugin.html) | Lets you manage the plugins for your project.
[plugin install](plugin-install.html) | Installs the specified plugin and its dependencies.
[plugin remove](plugin-remove.html) | Uninstalls the specified plugin and its dependencies.
<% } %>
2 changes: 2 additions & 0 deletions docs/man_pages/lib-management/plugin.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Lets you manage the plugins for your project.
* `update` - Uninstalls and installs the specified plugin(s) and its dependencies.
* `find` - Finds NativeScript plugins in npm.
* `search` - Finds NativeScript plugins in npm.
* `build` - Builds the Android parts of a NativeScript plugin.

<% if(isHtml) { %>
### Related Commands
Expand All @@ -28,4 +29,5 @@ Command | Description
[plugin add](plugin-add.html) | Installs the specified plugin and its dependencies.
[plugin remove](plugin-remove.html) | Uninstalls the specified plugin and its dependencies.
[plugin update](plugin-update.html) | Updates the specified plugin(s) and its dependencies.
[plugin build](plugin-build.html) | Builds the Android project of a NativeScript plugin, and updates the `include.gradle`.
<% } %>
2 changes: 2 additions & 0 deletions lib/bootstrap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ $injector.require("projectData", "./project-data");
$injector.requirePublic("projectDataService", "./services/project-data-service");
$injector.requirePublic("projectService", "./services/project-service");
$injector.require("androidProjectService", "./services/android-project-service");
$injector.require("androidPluginBuildService", "./services/android-plugin-build-service");
$injector.require("iOSEntitlementsService", "./services/ios-entitlements-service");
$injector.require("iOSProjectService", "./services/ios-project-service");
$injector.require("iOSProvisionService", "./services/ios-provision-service");
Expand Down Expand Up @@ -90,6 +91,7 @@ $injector.requireCommand("plugin|add", "./commands/plugin/add-plugin");
$injector.requireCommand("plugin|install", "./commands/plugin/add-plugin");
$injector.requireCommand("plugin|remove", "./commands/plugin/remove-plugin");
$injector.requireCommand("plugin|update", "./commands/plugin/update-plugin");
$injector.requireCommand("plugin|build", "./commands/plugin/build-plugin");

$injector.require("doctorService", "./services/doctor-service");
$injector.require("xcprojService", "./services/xcproj-service");
Expand Down
62 changes: 62 additions & 0 deletions lib/commands/plugin/build-plugin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import { EOL } from "os";
import * as path from "path";
import * as constants from "../../constants";
export class BuildPluginCommand implements ICommand {
public allowedParameters: ICommandParameter[] = [];
public pluginProjectPath: string;

constructor(private $androidPluginBuildService: IAndroidPluginBuildService,
private $errors: IErrors,
private $logger: ILogger,
private $fs: IFileSystem,
private $options: IOptions) {

this.pluginProjectPath = path.resolve(this.$options.path || ".");
}

public async execute(args: string[]): Promise<void> {
const platformsAndroidPath = path.join(this.pluginProjectPath, constants.PLATFORMS_DIR_NAME, "android");
let pluginName = "";

const pluginPackageJsonPath = path.join(this.pluginProjectPath, constants.PACKAGE_JSON_FILE_NAME);

if (this.$fs.exists(pluginPackageJsonPath)) {
const packageJsonContents = this.$fs.readJson(pluginPackageJsonPath);

if (packageJsonContents && packageJsonContents["name"]) {
pluginName = packageJsonContents["name"];
}
}

const tempAndroidProject = path.join(platformsAndroidPath, "android-project");

const options: IBuildOptions = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can use short syntax here:

const options: IBuildOptions = {
	aarOutputDir: platformsAndroidPath,
	platformsAndroidDirPath,
	pluginName,
	tempPluginDirPath: tempAndroidProject
};

But this is just a preference, so definitely not a merge stopper

aarOutputDir: platformsAndroidPath,
platformsAndroidDirPath: platformsAndroidPath,
pluginName: pluginName,
tempPluginDirPath: tempAndroidProject
};

const androidPluginBuildResult = await this.$androidPluginBuildService.buildAar(options);

if (androidPluginBuildResult) {
this.$logger.info(`${pluginName} successfully built aar at ${platformsAndroidPath}.${EOL}Temporary Android project can be found at ${tempAndroidProject}.`);
}

const migratedIncludeGradle = this.$androidPluginBuildService.migrateIncludeGradle(options);

if (migratedIncludeGradle) {
this.$logger.info(`${pluginName} include gradle updated.`);
}
}

public async canExecute(args: string[]): Promise<boolean> {
if (!this.$fs.exists(path.join(this.pluginProjectPath, constants.PLATFORMS_DIR_NAME, "android"))) {
this.$errors.failWithoutHelp("No plugin found at the current directory, or the plugin does not need to have its platforms/android components built into an `.aar`.");
}

return true;
}
}

$injector.registerCommand("plugin|build", BuildPluginCommand);
2 changes: 1 addition & 1 deletion lib/common
Submodule common updated 1 files
+11 −0 helpers.ts
2 changes: 2 additions & 0 deletions lib/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,15 @@ export const SRC_DIR = "src";
export const MAIN_DIR = "main";
export const ASSETS_DIR = "assets";
export const MANIFEST_FILE_NAME = "AndroidManifest.xml";
export const INCLUDE_GRADLE_NAME = "include.gradle";
export const BUILD_DIR = "build";
export const OUTPUTS_DIR = "outputs";
export const APK_DIR = "apk";
export const RESOURCES_DIR = "res";
export const CONFIG_NS_FILE_NAME = "nsconfig.json";
export const CONFIG_NS_APP_RESOURCES_ENTRY = "appResourcesPath";
export const CONFIG_NS_APP_ENTRY = "appPath";
export const DEPENDENCIES_JSON_NAME = "dependencies.json";

export class PackageVersion {
static NEXT = "next";
Expand Down
15 changes: 15 additions & 0 deletions lib/definitions/android-plugin-migrator.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@

interface IBuildOptions extends IAndroidBuildOptions{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This interface does not add anything to the IAndroidBuildOptions. What is the purpose of having it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In one of your previous comments, you mentioned the properties are android specific so I moved them to an android specific interface.

}

interface IAndroidBuildOptions {
platformsAndroidDirPath: string,
pluginName: string,
aarOutputDir: string,
tempPluginDirPath: string
}

interface IAndroidPluginBuildService {
buildAar(options: IBuildOptions): Promise<boolean>;
migrateIncludeGradle(options: IBuildOptions): boolean;
}
20 changes: 20 additions & 0 deletions lib/definitions/project.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,26 @@ interface IPlatformProjectService extends NodeJS.EventEmitter {
* If there are parts in the project that are inconsistent with the desired options, marks them in the changeset flags.
*/
checkForChanges(changeset: IProjectChangesInfo, options: IProjectChangesOptions, projectData: IProjectData): Promise<void>;

/**
* Build native part of a nativescript plugins if necessary
*/
prebuildNativePlugin(buildOptions: IBuildOptions): Promise<void>;

/**
* Traverse through the production dependencies and find plugins that need build/rebuild
*/
checkIfPluginsNeedBuild(projectData: IProjectData): Promise<Array<any>>;

/**
* Get gradle options the CLI generates when building project
*/
getBuildOptions(configurationFilePath?: string): Array<string>;

/**
* Get gradle options the CLI generates when building project
*/
executeCommand(projectRoot: string, args: any, childProcessOpts?: any, spawnFromEventOptions?: ISpawnFromEventOptions): Promise<ISpawnResult>;
}

interface IAndroidProjectPropertiesManager {
Expand Down
4 changes: 4 additions & 0 deletions lib/project-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,10 @@ export class ProjectData implements IProjectData {
}

private getNsConfigContent(projectDir: string): string {
if (!projectDir) {
return null;
}

const configNSFilePath = path.join(projectDir, constants.CONFIG_NS_FILE_NAME);

if (!this.$fs.exists(configNSFilePath)) {
Expand Down
Loading