@@ -20,7 +20,7 @@ apply plugin: 'com.android.model.library'
2020
2121buildscript {
2222 repositories {
23- jcenter()
23+ jcenter()
2424 }
2525 dependencies {
2626 classpath ' com.android.tools.build:gradle-experimental:0.7.0-beta3'
@@ -33,13 +33,27 @@ allprojects {
3333 }
3434}
3535
36+
37+
38+ def ndkDebuggable = false ;
39+
40+
41+ List<String > runTasks = gradle. startParameter. getTaskNames();
42+ for (String runTask : runTasks) {
43+ if (! ndkDebuggable && runTask. contains(" Debug" ) && (runTask. contains(" assemble" ) || runTask. contains(" compile" ) || runTask. contains(" generate" ))) {
44+ println " DEBUG build DETECTED. Switching ndk debuggable to true"
45+ ndkDebuggable = true ;
46+ }
47+ }
48+
49+
3650model {
3751 android {
3852 compileSdkVersion = 23
3953 buildToolsVersion = " 23.0.3"
4054
4155 defaultConfig. with {
42- minSdkVersion. apiLevel = 17
56+ minSdkVersion. apiLevel = 17
4357 targetSdkVersion. apiLevel = 22
4458 }
4559
@@ -50,8 +64,8 @@ model {
5064
5165 android. ndk {
5266 moduleName = " NativeScript"
53-
54-
67+
68+
5569 cppFlags. addAll([" -I${ file("src/main/jni")} " . toString(),
5670 " -I${ file("src/main/jni/include")} " . toString()
5771 ])
@@ -65,7 +79,7 @@ model {
6579
6680 abiFilters. addAll([" armeabi-v7a" , " x86" , " arm64-v8a" ])
6781 }
68-
82+
6983 android. sources {
7084 main {
7185 java {
@@ -89,33 +103,32 @@ model {
89103 }
90104 }
91105 }
92-
106+
93107 android. buildTypes {
94108 release {
95109 minifyEnabled = false
96110 proguardFiles. add(file(' proguard-rules.txt' ))
97-
98- ndk {
99- debuggable false
100- }
101-
111+
112+ ndk {
113+ debuggable = ndkDebuggable
114+ }
115+
102116 setRuntimeCommit. dependsOn(setPackageVersion)
103117
104118 tasks. whenTaskAdded { task ->
105- if (task. getName() == " androidRelease" )
106- {
119+ if (task. getName() == " androidRelease" ) {
107120 task. dependsOn(setRuntimeCommit)
108121 task. mustRunAfter setRuntimeCommit
109122 task. finalizedBy revertVersionFile
110- }
123+ }
111124 }
112125 }
113126 }
114127
115128 android. abis {
116129 create(" armeabi-v7a" ) {
117130 abiFilters. add(" armeabi-v7a" )
118-
131+
119132 ldLibs. add(" ${ file("src/main/libs/armeabi-v7a/libv8_base.a")} " . toString())
120133 ldLibs. add(" ${ file("src/main/libs/armeabi-v7a/libv8_libplatform.a")} " . toString())
121134 ldLibs. add(" ${ file("src/main/libs/armeabi-v7a/libv8_libbase.a")} " . toString())
@@ -125,7 +138,7 @@ model {
125138
126139 create(" x86" ) {
127140 abiFilters. add(" x86" )
128-
141+
129142 ldLibs. add(" ${ file("src/main/libs/x86/libv8_base.a")} " . toString())
130143 ldLibs. add(" ${ file("src/main/libs/x86/libv8_libplatform.a")} " . toString())
131144 ldLibs. add(" ${ file("src/main/libs/x86/libv8_libbase.a")} " . toString())
@@ -135,37 +148,31 @@ model {
135148
136149 create(" arm64-v8a" ) {
137150 abiFilters. add(" arm64-v8a" )
138-
151+
139152 ldFlags. addAll([
140- " -L${ file("src/main/libs/arm64-v8a")} " . toString(),
141- " -lv8_base" ,
142- " -lv8_libplatform" ,
143- " -lv8_libbase" ,
144- " -lv8_nosnapshot" ,
145- " -lzip"
153+ " -L${ file("src/main/libs/arm64-v8a")} " . toString(),
154+ " -lv8_base" ,
155+ " -lv8_libplatform" ,
156+ " -lv8_libbase" ,
157+ " -lv8_nosnapshot" ,
158+ " -lzip"
146159 ])
147-
160+
161+ // The correct way of setting these flags is not working hence the workaround above
148162 // ldFlags.add("-L ${file("src/main/libs/arm64-v8a")}" -l v8_base".toString())
149163 // ldFlags.add("-L ${file("src/main/libs/arm64-v8a")}" -l v8_libplatform".toString())
150164 // ldFlags.add("-L ${file("src/main/libs/arm64-v8a")}" -l v8_libbase".toString())
151165 // ldFlags.add("-L ${file("src/main/libs/arm64-v8a")}" -l v8_nosnapshot".toString())
152166 // ldFlags.add("-L ${file("src/main/libs/arm64-v8a")}" -l zip".toString())
153-
167+
154168 // ldLibs.add("${file("src/main/libs/arm64-v8a/libv8_base.a")}".toString())
155169 // ldLibs.add("${file("src/main/libs/arm64-v8a/libv8_libplatform.a")}".toString())
156170 // ldLibs.add("${file("src/main/libs/arm64-v8a/libv8_libbase.a")}".toString())
157171 // ldLibs.add("${file("src/main/libs/arm64-v8a/libv8_nosnapshot.a")}".toString())
158172 // ldLibs.add("${file("src/main/libs/arm64-v8a/libzip.a")}".toString())
159173 }
160174 }
161-
162-
163- // android.variantFilter { variant ->
164- // if (variant.buildType.name == "release") {
165-
166- // }
167- // }
168-
175+
169176 repositories {
170177 prebuilt(PrebuiltLibraries ) {
171178 v8 {
@@ -182,22 +189,21 @@ model {
182189 }
183190}
184191
185-
186192dependencies {
187- compile project(' :binding-generator' )
193+ compile project(' :binding-generator' )
188194}
189195
190196task setPackageVersion {
191- onlyIf {
197+ onlyIf {
192198 project. hasProperty(' packageVersion' )
193199 }
194-
200+
195201 doFirst {
196202 println " Setting runtime version: '${ packageVersion} '"
197-
203+
198204 def versionFile = " $rootDir /src/main/jni//Version.h"
199205 String contents = new File (versionFile). getText(" UTF-8" )
200- contents = contents. replaceAll( / 0.0.0.0/ , packageVersion)
206+ contents = contents. replaceAll(/ 0.0.0.0/ , packageVersion)
201207 new File (versionFile). write(contents, " UTF-8" )
202208 }
203209}
@@ -206,33 +212,46 @@ task setRuntimeCommit {
206212 onlyIf {
207213 project. hasProperty(' gitCommitVersion' )
208214 }
209-
215+
210216 doFirst {
211217 println " Setting runtime commit: '${ gitCommitVersion} '"
212-
218+
213219 def versionFile = " $rootDir /src/main/jni//Version.h"
214220 String contents = new File (versionFile). getText(" UTF-8" )
215221 contents = contents. replaceAll(/ RUNTIME_COMMIT_SHA_PLACEHOLDER/ , gitCommitVersion)
216222 new File (versionFile). write(contents, " UTF-8" )
217223 }
218224}
219225
220- task revertVersionFile (type : Exec ) {
221-
226+ // task setNdkDebuggable {
227+ // println "Setting ndk debuggable: " + components.android
228+ // doFirst {
229+ //
230+ // }
231+ // }
232+ //
233+ // task revertNdkDebuggable {
234+ // doFirst {
235+ // println "Reverting ndk debuggable: " + components.android
236+ // }
237+ // }
238+
239+
240+ task revertVersionFile (type : Exec ) {
241+
222242 onlyIf {
223- project. hasProperty(' packageVersion' ) || project. hasProperty(' gitCommitVersion' )
243+ project. hasProperty(' packageVersion' ) || project. hasProperty(' gitCommitVersion' )
224244 }
225-
245+
226246 doFirst {
227247 def isWinOs = System . properties[' os.name' ]. toLowerCase(). contains(' windows' )
228248 def versionFileName = " ./src/main/jni//Version.h"
229249 def versionFilePath = new File (versionFileName). getAbsolutePath()
230- println " Reverting Version.h file: ${ versionFilePath} "
231-
232- if (isWinOs) {
250+ println " Reverting Version.h file: ${ versionFilePath} "
251+
252+ if (isWinOs) {
233253 commandLine " cmd" , " /c" , " git" , " checkout" , " --" , versionFilePath
234- }
235- else {
254+ } else {
236255 commandLine " git" , " checkout" , " --" , versionFilePath
237256 }
238257 }
0 commit comments