Skip to content

Commit f04670f

Browse files
author
plamen5kov
committed
enabled passing compileSdk, support version and other variables
1 parent 1b1f25b commit f04670f

3 files changed

Lines changed: 157 additions & 17 deletions

File tree

build.gradle

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
/*
2+
* Test command
3+
* gradle packar -PtargetSdk=android-23 -PminSdk=17 -PbuildToolsVersion=23.0.2 -PsupportVersion=23.0.1 -PcompileSdk=android-23
4+
* To run:
5+
* gradle packar
6+
*
7+
* Options:
8+
* -PtargetSdk=[target_sdk]
9+
* -PminSdk=[target_sdk]
10+
* -PbuildToolsVersion=[build_tools_version]
11+
* -PsupportVersion=[support_version]
12+
* -PcompileSdk=[compile_sdk_version]
13+
*/
14+
115
import groovy.json.JsonSlurper //used to parse package.json
216
import groovy.json.JsonBuilder
317
import groovy.json.JsonOutput
@@ -9,6 +23,12 @@ def pVersion = "no package version was provided by build.gradle build"
923
def arVersion = "no commit sha was provided by build.gradle build"
1024
def commitVersionFile = "commit.txt"
1125

26+
def compileSdkVer = "";
27+
def buildToolsVer = "";
28+
def minSdkVer = "";
29+
def targetSdkVer = "";
30+
def supportVer = "";
31+
1232
task checkEnvironmentVariables {
1333
if ("$System.env.JAVA_HOME" == "" || "$System.env.JAVA_HOME" == "null") {
1434
throw new GradleException("Set JAVA_HOME to point to the correct Jdk location\n");
@@ -25,6 +45,22 @@ task checkEnvironmentVariables {
2545
if(project.hasProperty("metadataGen") && !file("../android-metadata-generator/dist/tns-android-metadata-generator-0.0.1.tgz").exists()) {
2646
throw new GradleException("android-metadata-generator build output not found and no metadataGen option specified. Build android-metadata-generator first.\n");
2747
}
48+
49+
if(project.hasProperty("compileSdk")) {
50+
compileSdkVer = "-PcompileSdk=$compileSdk"
51+
}
52+
if(project.hasProperty("buildToolsVersion")) {
53+
buildToolsVer = "-PbuildToolsVersion=$buildToolsVersion"
54+
}
55+
if(project.hasProperty("minSdk")) {
56+
minSdkVer = "-PminSdk=$minSdk"
57+
}
58+
if(project.hasProperty("targetSdk")) {
59+
targetSdkVer = "-PtargetSdk=$targetSdk"
60+
}
61+
if(project.hasProperty("supportVersion")) {
62+
supportVer = "-PsupportVersion=$supportVersion"
63+
}
2864
}
2965

3066
task checkAndroidCommand(type:Exec) {
@@ -136,13 +172,13 @@ task deleteCommitFile (type: Delete) {
136172
task generateRuntime (type: Exec) {
137173
doFirst{
138174
workingDir "$rootDir/src"
139-
175+
140176
//command gradle buildar -PpackageVersion=[from_package.json] -PgitCommitVersion=[from_some_sys_variable]
141177
if(isWinOs) {
142-
commandLine "cmd", "/c" , "gradle", "buildar", "-PpackageVersion=${pVersion}", "-PgitCommitVersion=${arVersion}"
178+
commandLine "cmd", "/c" , "gradle", "buildar", "-PpackageVersion=${pVersion}", "-PgitCommitVersion=${arVersion}", compileSdkVer, buildToolsVer, minSdkVer, targetSdkVer, supportVer
143179
}
144180
else {
145-
commandLine "gradle", "buildar", "-PpackageVersion=${pVersion}", "-PgitCommitVersion=${arVersion}"
181+
commandLine "gradle", "buildar", "-PpackageVersion=${pVersion}", "-PgitCommitVersion=${arVersion}", compileSdkVer, buildToolsVer, minSdkVer, targetSdkVer, supportVer
146182
}
147183
}
148184
}

src/build.gradle

Lines changed: 63 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,17 @@
33
* It builds the C++ part of the runtime with the ndk-build command, which is currently impossible to do with the android plugin for gradle
44
* The script also builds the nativescript.jar file containing the binding generator and the rest of the android runtime
55
*
6-
* How to run script and build android runtime run: "gradle buildar"
6+
* Test command:
7+
* gradle buildar -PtargetSdk=android-23 -PminSdk=17 -PbuildToolsVersion=23.0.2 -PsupportVersion=23.0.1 -PcompileSdk=android-23
8+
* To run:
9+
* gradle buildar
10+
*
11+
* Options:
12+
* -PtargetSdk=[target_sdk] (default is 22)
13+
* -PminSdk=[target_sdk] (default is 19)
14+
* -PbuildToolsVersion=[build_tools_version] (default is 22.0.1)
15+
* -PsupportVersion=[support_version] (default (22.2.0)
16+
* -PcompileSdk=[compile_sdk_version] (default 22)
717
*/
818

919
def distDir = "$rootDir/dist"
@@ -23,14 +33,57 @@ buildscript {
2333

2434
apply plugin: 'com.android.library' //com.android.application for applications (build process is different)
2535

36+
def compiteCompileSdkVersion () {
37+
if(project.hasProperty("compileSdk")) {
38+
return compileSdk
39+
}
40+
else {
41+
return 22
42+
}
43+
}
44+
45+
def computeBuildToolsVersion() {
46+
if(project.hasProperty("buildToolsVersion")) {
47+
return buildToolsVersion
48+
}
49+
else {
50+
return "22.0.1"
51+
}
52+
}
53+
54+
def computeMinSdkVersion() {
55+
if(project.hasProperty("minSdk")) {
56+
return targetSdk
57+
}
58+
else {
59+
return 19
60+
}
61+
}
62+
63+
def computeTargetSdkVersion() {
64+
if(project.hasProperty("targetSdk")) {
65+
return targetSdk
66+
}
67+
else {
68+
return 22
69+
}
70+
}
71+
72+
def computeSupportVersion() {
73+
if(project.hasProperty("supportVersion")) {
74+
return supportVersion
75+
}
76+
return "22.2.0"
77+
}
78+
2679
//configuration of the android plugin for gradle
2780
android {
28-
compileSdkVersion 22
29-
buildToolsVersion "22.0.1"
81+
compileSdkVersion compiteCompileSdkVersion()
82+
buildToolsVersion computeBuildToolsVersion()
3083

3184
defaultConfig {
32-
minSdkVersion 19
33-
targetSdkVersion 22
85+
minSdkVersion computeMinSdkVersion()
86+
targetSdkVersion computeTargetSdkVersion()
3487
versionCode 1
3588
versionName "1.0"
3689
}
@@ -53,10 +106,11 @@ repositories {
53106

54107
dependencies {
55108
def sdkPath = android.sdkDirectory.getAbsolutePath();
56-
def androidJar = sdkPath + "/platforms/" + android.compileSdkVersion + "/android.jar"
57-
58-
compile 'com.android.support:support-v4:22.2.0'
59-
compile 'com.android.support:appcompat-v7:22.2.0'
109+
def androidJar = sdkPath + "/platforms/" + android.compileSdkVersion + "/android.jar"
110+
def suppotVer = computeSupportVersion();
111+
112+
compile "com.android.support:support-v4:$suppotVer"
113+
compile "com.android.support:appcompat-v7:$suppotVer"
60114
compile files(androidJar)
61115
compile files(pathToBindingGeneratorJar)
62116
}

test-app/build.gradle

Lines changed: 55 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
/*
2+
* Test command:
3+
* gradle runtest -PtargetSdk=android-23 -PminSdk=17 -PbuildToolsVersion=23.0.2 -PsupportVersion=23.0.1 -PcompileSdk=android-23
4+
* To run:
5+
* gradle runtest
6+
*
7+
* Options:
8+
* -PtargetSdk=[target_sdk] (default is 22)
9+
* -PminSdk=[target_sdk] (default is 17)
10+
* -PbuildToolsVersion=[build_tools_version] (default is 22.0.1)
11+
* -PsupportVersion=[support_version] (default (22.2.0)
12+
* -PcompileSdk=[compile_sdk_version] (default 22)
13+
*/
14+
115
def isWinOs = System.properties['os.name'].toLowerCase().contains('windows')
216
def allJarPaths = new LinkedList <String> ()
317

@@ -13,22 +27,56 @@ buildscript {
1327

1428
apply plugin: "com.android.application"
1529

30+
31+
def compiteCompileSdkVersion () {
32+
if(project.hasProperty("compileSdk")) {
33+
return compileSdk
34+
}
35+
else {
36+
return 22
37+
}
38+
}
39+
40+
def computeBuildToolsVersion() {
41+
if(project.hasProperty("buildToolsVersion")) {
42+
return buildToolsVersion
43+
}
44+
else {
45+
return "22.0.1"
46+
}
47+
}
48+
49+
def computeMinSdkVersion() {
50+
if(project.hasProperty("minSdk")) {
51+
return targetSdk
52+
}
53+
else {
54+
return 17
55+
}
56+
}
57+
1658
def computeTargetSdkVersion() {
1759
if(project.hasProperty("targetSdk")) {
18-
1960
return targetSdk
2061
}
2162
else {
2263
return 22
2364
}
2465
}
2566

67+
def computeSupportVersion() {
68+
if(project.hasProperty("supportVersion")) {
69+
return supportVersion
70+
}
71+
return "22.2.0"
72+
}
73+
2674
android {
27-
compileSdkVersion 22
28-
buildToolsVersion "22.0.1"
75+
compileSdkVersion compiteCompileSdkVersion()
76+
buildToolsVersion computeBuildToolsVersion()
2977

3078
defaultConfig {
31-
minSdkVersion 17
79+
minSdkVersion computeMinSdkVersion()
3280
targetSdkVersion computeTargetSdkVersion()
3381
}
3482

@@ -77,7 +125,9 @@ repositories {
77125

78126
dependencies {
79127
def nativescriptJarPath = "$rootDir/libs/nativescript.jar"
80-
compile 'com.android.support:support-v4:22.2.0'
128+
def suppotVer = computeSupportVersion();
129+
130+
compile "com.android.support:support-v4:$suppotVer"
81131
compile files(nativescriptJarPath)
82132
}
83133

0 commit comments

Comments
 (0)