Skip to content

Commit bb5daf8

Browse files
committed
Use gradle wrapper instead of global gradle
See NativeScript/NativeScript#1024
1 parent 20765bd commit bb5daf8

File tree

5 files changed

+20
-69
lines changed

5 files changed

+20
-69
lines changed

README.md

Lines changed: 8 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,9 @@ You can install and run the NativeScript CLI on Windows or OS X.
6969
> On Windows systems, you can develop, build, and deploy NativeScript projects that target Android.
7070
7171
* Windows Vista or later
72-
* The latest Node.js [0.10.x](https://nodejs.org/dist/latest-v0.10.x/) or [0.12.x](https://nodejs.org/dist/latest-v0.12.x/) stable official release
72+
* The latest Node.js [0.10.x](https://nodejs.org/dist/latest-v0.10.x/), [0.12.x](https://nodejs.org/dist/latest-v0.12.x/) or [4.2.x](https://nodejs.org/dist/latest-v4.x/) stable official release
7373
* (Optional) [Chocolatey][Chocolatey]
7474
* [JDK 8][JDK 8] or a later stable official release
75-
* [Gradle 2.3][Gradle 2.3] or a later stable official release
7675
* [Android SDK 22][Android SDK 22] or a later stable official release
7776
* [Android SDK Build-tools 22.0.0][Android SDK Build-tools 22.0.0] or a later stable official release
7877
* [Android Support Repository][Android Support Repository]
@@ -81,14 +80,13 @@ You can install and run the NativeScript CLI on Windows or OS X.
8180
If you want to develop for Android, verify that you have added the following paths in the `PATH` system environment variable.
8281

8382
```
84-
Path to the bin directory in the Gradle installation folder
8583
Path to tools directory in the Android SDK installation folder
8684
Path to platform-tools directory in the Android SDK installation folder
8785
```
8886

89-
For example: PATH=...;...;C:\tools\gradle\bin;C:\Users\MyUser\AppData\Local\Android\android-sdk\tools;C:\Users\MyUser\AppData\Local\Android\android-sdk\platform-tools;
87+
For example: PATH=...;...;C:\Users\MyUser\AppData\Local\Android\android-sdk\tools;C:\Users\MyUser\AppData\Local\Android\android-sdk\platform-tools;
9088

91-
If you have installed Chocolatey, you can complete these steps to set up JDK, Gradle, and Android SDK.
89+
If you have installed Chocolatey, you can complete these steps to set up JDK, and Android SDK.
9290

9391
1. Run a Windows command prompt.
9492
1. To install JDK, run the following command.
@@ -102,25 +100,13 @@ If you have installed Chocolatey, you can complete these steps to set up JDK, Gr
102100
JAVA_HOME=Path to the jdk* install folder
103101
```
104102

105-
For example: JAVA_HOME=C:\Program Files\Java\jdk1.8.0_11
103+
For example: JAVA_HOME=C:\Program Files\Java\jdk1.8.0_66
106104

107105
```
108106
ANDROID_HOME=Path to Android installation directory
109107
```
110108

111109
For example: ANDROID_HOME=C:\Android\android-sdk
112-
1. To install Gradle, run the following command.
113-
114-
```Shell
115-
choco install gradle
116-
```
117-
1. If not present, add the following file path to the `PATH` system environment variable.
118-
119-
```
120-
Path to the bin directory in the Gradle installation folder
121-
```
122-
123-
For example: PATH=...;...;C:\tools\gradle\bin
124110
1. To install the Android SDK, run the following command.
125111

126112
```Shell
@@ -153,14 +139,13 @@ android update sdk --filter tools,platform-tools,android-22,build-tools-22.0.1,s
153139
> On OS X systems, you can develop, build, and deploy NativeScript projects that target iOS and Android.
154140
155141
* OS X Mavericks
156-
* The latest Node.js [0.10.x](https://nodejs.org/dist/latest-v0.10.x/) or [0.12.x](https://nodejs.org/dist/latest-v0.12.x/) stable official release
142+
* The latest Node.js [0.10.x](https://nodejs.org/dist/latest-v0.10.x/) or [0.12.x](https://nodejs.org/dist/latest-v0.12.x/), or [4.2.x](https://nodejs.org/dist/latest-v4.x/) stable official release
157143
* For iOS development
158144
* [Latest Xcode][12]
159145
* [Xcode command-line tools][12]
160146
* (Optional) [CocoaPods 0.38.2][CocoaPods 0.38.2]
161147
* For Android development
162148
* [JDK 8][JDK 8] or a later stable official release
163-
* [Gradle 2.3][Gradle 2.3] or a later stable official release
164149
* [Android SDK 22][Android SDK 22] or a later stable official release
165150
* [Android SDK Build-tools 22.0.0][Android SDK Build-tools 22.0.0] or a later stable official release
166151
* [Android Support Repository][Android Support Repository]
@@ -169,14 +154,13 @@ android update sdk --filter tools,platform-tools,android-22,build-tools-22.0.1,s
169154
If you want to develop for Android, verify that you have added the following paths in your `PATH` in `~/.bash_profile`.
170155

171156
```
172-
Path to the bin subdirectory in the Gradle installation directory
173157
Path to the tools subdirectory in the Android SDK installation directory
174158
Path to the platform-tools subdirectory in the Android SDK installation directory
175159
```
176160

177161
For example:
178162
```
179-
export PATH=${PATH}:/gradle/bin:/Applications/Android\ Studio.app/sdk/tools:/Applications/Android\ Studio.app/sdk/platform-tools
163+
export PATH=${PATH}:/Applications/Android\ Studio.app/sdk/tools:/Applications/Android\ Studio.app/sdk/platform-tools
180164
```
181165

182166
If not present, create the following environment variables.
@@ -204,7 +188,7 @@ echo yes | android update sdk --filter tools,platform-tools,android-22,build-too
204188
> On Linux systems, you can develop, build, and deploy NativeScript projects that target Android.
205189
206190
* Ubuntu 14.04 LTS
207-
* The latest Node.js [0.10.x](https://nodejs.org/dist/latest-v0.10.x/) or [0.12.x](https://nodejs.org/dist/latest-v0.12.x/) stable official release
191+
* The latest Node.js [0.10.x](https://nodejs.org/dist/latest-v0.10.x/) or [0.12.x](https://nodejs.org/dist/latest-v0.12.x/), or [4.2.x](https://nodejs.org/dist/latest-v4.x/) stable official release
208192

209193
> **TIP:** You can follow the instructions provided [here](https://github.com/joyent/node/wiki/Installing-Node.js-via-package-manager) to install Node.js on your system.
210194

@@ -220,7 +204,6 @@ echo yes | android update sdk --filter tools,platform-tools,android-22,build-too
220204
sudo apt-get install lib32z1 lib32ncurses5 lib32bz2-1.0 libstdc++6:i386
221205
```
222206
* [JDK 8][JDK 8] or a later stable official release
223-
* [Gradle 2.3][Gradle 2.3] or a later stable official release
224207
* [Android SDK 22][Android SDK 22] or a later stable official release
225208
* [Android SDK Build-tools 22.0.0][Android SDK Build-tools 22.0.0] or a later stable official release
226209
* [Android Support Repository][Android Support Repository]
@@ -229,14 +212,13 @@ echo yes | android update sdk --filter tools,platform-tools,android-22,build-too
229212
Verify that you have added the following paths in your `PATH`.
230213

231214
```
232-
Path to the bin subdirectory in the Gradle installation directory
233215
Path to the tools subdirectory in the Android SDK installation directory
234216
Path to the platform-tools subdirectory in the Android SDK installation directory
235217
```
236218

237219
For example:
238220
```
239-
export PATH=${PATH}:/gradle/bin:/home/user/android-sdk/tools:/home/user/android-sdk/platform-tools
221+
export PATH=${PATH}:/home/user/android-sdk/tools:/home/user/android-sdk/platform-tools
240222
```
241223

242224
If not present, create the following environment variables.
@@ -615,7 +597,6 @@ This software is licensed under the Apache 2.0 license, quoted <a href="LICENSE"
615597
[12]: https://developer.apple.com/xcode/downloads/
616598
[Chocolatey]: https://chocolatey.org/
617599
[JDK 8]: http://www.oracle.com/technetwork/java/javase/downloads/index.html
618-
[Gradle 2.3]: https://gradle.org/gradle-download/
619600
[Android SDK 22]: http://developer.android.com/sdk/index.html
620601
[Genymotion]: https://www.genymotion.com/#!/
621602
[CocoaPods 0.38.2]: https://guides.cocoapods.org/using/getting-started.html#getting-started

lib/services/android-project-service.ts

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,6 @@ export class AndroidProjectService extends projectServiceBaseLib.PlatformProject
9191
this.$errors.failWithoutHelp(`The NativeScript CLI requires Android runtime ${AndroidProjectService.MIN_RUNTIME_VERSION_WITH_GRADLE} or later to work properly.`);
9292
}
9393

94-
// TODO: Move these check to validate method once we do not support ant.
95-
this.checkGradle().wait();
96-
9794
this.$fs.ensureDirectoryExists(this.platformData.projectRoot).wait();
9895
let androidToolsInfo = this.$androidToolsInfo.getToolsInfo().wait();
9996
let targetSdkVersion = androidToolsInfo.targetSdkVersion;
@@ -109,11 +106,21 @@ export class AndroidProjectService extends projectServiceBaseLib.PlatformProject
109106
this.copy(this.platformData.projectRoot, frameworkDir, "src", "-R");
110107
this.copy(this.platformData.projectRoot, frameworkDir, "build.gradle settings.gradle", "-f");
111108

109+
if (this.useGradleWrapper(frameworkDir)) {
110+
this.copy(this.platformData.projectRoot, frameworkDir, "gradle", "-R");
111+
this.copy(this.platformData.projectRoot, frameworkDir, "gradlew gradlew.bat", "-f");
112+
}
113+
112114
this.cleanResValues(targetSdkVersion, frameworkVersion).wait();
113115

114116
}).future<any>()();
115117
}
116118

119+
private useGradleWrapper(frameworkDir: string): boolean {
120+
let gradlew = path.join(frameworkDir, "gradlew");
121+
return this.$fs.exists(gradlew).wait();
122+
}
123+
117124
private cleanResValues(targetSdkVersion: number, frameworkVersion: string): IFuture<void> {
118125
return (() => {
119126
let resDestinationDir = this.getAppResourcesDestinationDirectoryPath(frameworkVersion).wait();
@@ -189,7 +196,6 @@ export class AndroidProjectService extends projectServiceBaseLib.PlatformProject
189196
public buildProject(projectRoot: string, buildConfig?: IBuildConfig): IFuture<void> {
190197
return (() => {
191198
if(this.canUseGradle().wait()) {
192-
this.checkGradle().wait();
193199
let androidToolsInfo = this.$androidToolsInfo.getToolsInfo().wait();
194200
let compileSdk = androidToolsInfo.compileSdkVersion;
195201
let targetSdk = this.getTargetFromAndroidManifest().wait() || compileSdk;
@@ -214,7 +220,8 @@ export class AndroidProjectService extends projectServiceBaseLib.PlatformProject
214220
buildOptions.push("-PrunSBGenerator");
215221
}
216222

217-
this.spawn("gradle", buildOptions, { stdio: "inherit", cwd: this.platformData.projectRoot }).wait();
223+
let gradleBin = this.useGradleWrapper(projectRoot) ? path.join(projectRoot, "gradlew") : "gradle";
224+
this.spawn(gradleBin, buildOptions, { stdio: "inherit", cwd: this.platformData.projectRoot }).wait();
218225
} else {
219226
this.checkAnt().wait();
220227

@@ -438,16 +445,6 @@ export class AndroidProjectService extends projectServiceBaseLib.PlatformProject
438445
}).future<void>()();
439446
}
440447

441-
private checkGradle(): IFuture<void> {
442-
return (() => {
443-
if(!this.$sysInfo.getSysInfo().gradleVer) {
444-
this.$errors.failWithoutHelp("Error executing commands 'gradle'. Make sure you have Gradle installed and its bin directory added to your PATH.");
445-
}
446-
447-
this.$androidToolsInfo.validateInfo({showWarningsAsErrors: true, validateTargetSdk: true}).wait();
448-
}).future<void>()();
449-
}
450-
451448
private checkAndroid(): IFuture<void> {
452449
return (() => {
453450
try {

lib/services/doctor-service.ts

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
///<reference path="../.d.ts"/>
22
"use strict";
33
import {EOL} from "os";
4-
import * as helpers from "../common/helpers";
54
import * as semver from "semver";
65

76
class DoctorService implements IDoctorService {
8-
private static MIN_SUPPORTED_GRADLE_VERSION = "2.3";
97
private static MIN_SUPPORTED_POD_VERSION = "0.38.2";
108

119
constructor(private $androidToolsInfo: IAndroidToolsInfo,
@@ -59,20 +57,6 @@ class DoctorService implements IDoctorService {
5957
result = true;
6058
}
6159

62-
if(!sysInfo.gradleVer) {
63-
this.$logger.warn("WARNING: Gradle is not installed or is not configured properly.");
64-
this.$logger.out("You will not be able to build your projects for Android or run them in the emulator or on a connected device." + EOL
65-
+ "To be able to build for Android and run apps in the emulator or on a connected device, verify that you have installed Gradle.");
66-
result = true;
67-
}
68-
69-
if(sysInfo.gradleVer && !this.isGradleVersionSupported(sysInfo.gradleVer)) {
70-
this.$logger.warn(`WARNING: Gradle version is lower than ${DoctorService.MIN_SUPPORTED_GRADLE_VERSION}.`);
71-
this.$logger.out("You will not be able to build your projects for Android or run them in the emulator or on a connected device." + EOL
72-
+ `To be able to build for Android and run apps in the emulator or on a connected device, verify that you have at least ${DoctorService.MIN_SUPPORTED_GRADLE_VERSION} version installed.`);
73-
result = true;
74-
}
75-
7660
if(!sysInfo.javacVersion) {
7761
this.$logger.warn("WARNING: Javac is not installed or is not configured properly.");
7862
this.$logger.out("You will not be able to build your projects for Android." + EOL
@@ -106,14 +90,5 @@ class DoctorService implements IDoctorService {
10690
this.$logger.out("TIP: To avoid setting up the necessary environment variables, you can use the Homebrew package manager to install the Android SDK and its dependencies." + EOL);
10791
}
10892
}
109-
110-
private isGradleVersionSupported(gradleVersion: string): boolean {
111-
let minSupportedVersion = DoctorService.MIN_SUPPORTED_GRADLE_VERSION;
112-
let requiredLength = _.max([gradleVersion.split(".").length, minSupportedVersion.split(".").length]);
113-
gradleVersion = helpers.appendZeroesToVersion(gradleVersion, requiredLength);
114-
minSupportedVersion = helpers.appendZeroesToVersion(minSupportedVersion, requiredLength);
115-
116-
return helpers.versionCompare(gradleVersion, minSupportedVersion) !== -1;
117-
}
11893
}
11994
$injector.register("doctorService", DoctorService);

setup/native-script.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ class NativeScript < Formula
6363
depends_on "pkg-config" => :build
6464
# depends_on "node" # currently we do not work with latest node, and we manually install 0.12 (see above)
6565
depends_on "android-sdk"
66-
depends_on "gradle"
6766

6867
def install
6968
ohai "Installing NativeScript CLI..."

setup/native-script.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
cinst googlechrome
77
cinst nodejs.install -version 0.12.7
88
cinst jdk8
9-
cinst gradle -version 2.3
109
cinst android-sdk
1110

1211
# setup android sdk

0 commit comments

Comments
 (0)