質問編集履歴

1

build.gradleファイルのソース,Cのビルド手順の追記

2017/10/24 05:21

投稿

novice_engineer
novice_engineer

スコア7

test CHANGED
File without changes
test CHANGED
@@ -33,3 +33,563 @@
33
33
  }
34
34
 
35
35
  ```
36
+
37
+
38
+
39
+ ```gradle
40
+
41
+
42
+
43
+ apply plugin: 'com.android.application'
44
+
45
+
46
+
47
+ buildscript {
48
+
49
+ repositories {
50
+
51
+ mavenCentral()
52
+
53
+ jcenter()
54
+
55
+ }
56
+
57
+
58
+
59
+ dependencies {
60
+
61
+ classpath 'com.android.tools.build:gradle:2.3.2'
62
+
63
+ }
64
+
65
+ }
66
+
67
+
68
+
69
+ allprojects {
70
+
71
+ repositories {
72
+
73
+ mavenCentral();
74
+
75
+ jcenter()
76
+
77
+ }
78
+
79
+ }
80
+
81
+
82
+
83
+ task wrapper(type: Wrapper) {
84
+
85
+ gradleVersion = '2.14.1'
86
+
87
+ }
88
+
89
+
90
+
91
+ ext {
92
+
93
+ apply from: 'CordovaLib/cordova.gradle'
94
+
95
+ if (!project.hasProperty('cdvCompileSdkVersion')) {
96
+
97
+ cdvCompileSdkVersion = null;
98
+
99
+ }
100
+
101
+ if (!project.hasProperty('cdvBuildToolsVersion')) {
102
+
103
+ cdvBuildToolsVersion = null;
104
+
105
+ }
106
+
107
+ if (!project.hasProperty('cdvVersionCode')) {
108
+
109
+ cdvVersionCode = null
110
+
111
+ }
112
+
113
+ if (!project.hasProperty('cdvMinSdkVersion')) {
114
+
115
+ cdvMinSdkVersion = null
116
+
117
+ }
118
+
119
+ if (!project.hasProperty('cdvBuildMultipleApks')) {
120
+
121
+ cdvBuildMultipleApks = null
122
+
123
+ }
124
+
125
+ if (!project.hasProperty('cdvReleaseSigningPropertiesFile')) {
126
+
127
+ cdvReleaseSigningPropertiesFile = null
128
+
129
+ }
130
+
131
+ if (!project.hasProperty('cdvDebugSigningPropertiesFile')) {
132
+
133
+ cdvDebugSigningPropertiesFile = null
134
+
135
+ }
136
+
137
+ if (!project.hasProperty('cdvBuildArch')) {
138
+
139
+ cdvBuildArch = null
140
+
141
+ }
142
+
143
+
144
+
145
+ cdvPluginPostBuildExtras = []
146
+
147
+ }
148
+
149
+
150
+
151
+ // PLUGIN GRADLE EXTENSIONS START
152
+
153
+ // PLUGIN GRADLE EXTENSIONS END
154
+
155
+
156
+
157
+ def hasBuildExtras = file('build-extras.gradle').exists()
158
+
159
+ if (hasBuildExtras) {
160
+
161
+ apply from: 'build-extras.gradle'
162
+
163
+ }
164
+
165
+
166
+
167
+ // Set property defaults after extension .gradle files.
168
+
169
+ if (ext.cdvCompileSdkVersion == null) {
170
+
171
+ ext.cdvCompileSdkVersion = privateHelpers.getProjectTarget()
172
+
173
+ }
174
+
175
+ if (ext.cdvBuildToolsVersion == null) {
176
+
177
+ ext.cdvBuildToolsVersion = privateHelpers.findLatestInstalledBuildTools()
178
+
179
+ }
180
+
181
+ if (ext.cdvDebugSigningPropertiesFile == null && file('debug-signing.properties').exists()) {
182
+
183
+ ext.cdvDebugSigningPropertiesFile = 'debug-signing.properties'
184
+
185
+ }
186
+
187
+ if (ext.cdvReleaseSigningPropertiesFile == null && file('release-signing.properties').exists()) {
188
+
189
+ ext.cdvReleaseSigningPropertiesFile = 'release-signing.properties'
190
+
191
+ }
192
+
193
+
194
+
195
+ // Cast to appropriate types.
196
+
197
+ ext.cdvBuildMultipleApks = cdvBuildMultipleApks == null ? false : cdvBuildMultipleApks.toBoolean();
198
+
199
+ ext.cdvMinSdkVersion = cdvMinSdkVersion == null ? null : Integer.parseInt('' + cdvMinSdkVersion)
200
+
201
+ ext.cdvVersionCode = cdvVersionCode == null ? null : Integer.parseInt('' + cdvVersionCode)
202
+
203
+
204
+
205
+ def computeBuildTargetName(debugBuild) {
206
+
207
+ def ret = 'assemble'
208
+
209
+ if (cdvBuildMultipleApks && cdvBuildArch) {
210
+
211
+ def arch = cdvBuildArch == 'arm' ? 'armv7' : cdvBuildArch
212
+
213
+ ret += '' + arch.toUpperCase().charAt(0) + arch.substring(1);
214
+
215
+ }
216
+
217
+ return ret + (debugBuild ? 'Debug' : 'Release')
218
+
219
+ }
220
+
221
+
222
+
223
+ // Make cdvBuild a task that depends on the debug/arch-sepecific task.
224
+
225
+ task cdvBuildDebug
226
+
227
+ cdvBuildDebug.dependsOn {
228
+
229
+ return computeBuildTargetName(true)
230
+
231
+ }
232
+
233
+
234
+
235
+ task cdvBuildRelease
236
+
237
+ cdvBuildRelease.dependsOn {
238
+
239
+ return computeBuildTargetName(false)
240
+
241
+ }
242
+
243
+
244
+
245
+ task cdvPrintProps << {
246
+
247
+ println('cdvCompileSdkVersion=' + cdvCompileSdkVersion)
248
+
249
+ println('cdvBuildToolsVersion=' + cdvBuildToolsVersion)
250
+
251
+ println('cdvVersionCode=' + cdvVersionCode)
252
+
253
+ println('cdvMinSdkVersion=' + cdvMinSdkVersion)
254
+
255
+ println('cdvBuildMultipleApks=' + cdvBuildMultipleApks)
256
+
257
+ println('cdvReleaseSigningPropertiesFile=' + cdvReleaseSigningPropertiesFile)
258
+
259
+ println('cdvDebugSigningPropertiesFile=' + cdvDebugSigningPropertiesFile)
260
+
261
+ println('cdvBuildArch=' + cdvBuildArch)
262
+
263
+ println('computedVersionCode=' + android.defaultConfig.versionCode)
264
+
265
+ android.productFlavors.each { flavor ->
266
+
267
+ println('computed' + flavor.name.capitalize() + 'VersionCode=' + flavor.versionCode)
268
+
269
+ }
270
+
271
+ }
272
+
273
+
274
+
275
+ android {
276
+
277
+ sourceSets {
278
+
279
+ main {
280
+
281
+ manifest.srcFile 'AndroidManifest.xml'
282
+
283
+ java.srcDirs = ['src']
284
+
285
+ resources.srcDirs = ['src']
286
+
287
+ aidl.srcDirs = ['src']
288
+
289
+ renderscript.srcDirs = ['src']
290
+
291
+ res.srcDirs = ['res']
292
+
293
+ assets.srcDirs = ['assets']
294
+
295
+ jniLibs.srcDirs = ['libs']
296
+
297
+ }
298
+
299
+ }
300
+
301
+
302
+
303
+ defaultConfig {
304
+
305
+ versionCode cdvVersionCode ?: new BigInteger("" + privateHelpers.extractIntFromManifest("versionCode"))
306
+
307
+ applicationId privateHelpers.extractStringFromManifest("package")
308
+
309
+
310
+
311
+ if (cdvMinSdkVersion != null) {
312
+
313
+ minSdkVersion cdvMinSdkVersion
314
+
315
+ }
316
+
317
+ }
318
+
319
+
320
+
321
+ lintOptions {
322
+
323
+ abortOnError false;
324
+
325
+ }
326
+
327
+
328
+
329
+ compileSdkVersion cdvCompileSdkVersion
330
+
331
+ buildToolsVersion cdvBuildToolsVersion
332
+
333
+
334
+
335
+ if (Boolean.valueOf(cdvBuildMultipleApks)) {
336
+
337
+ productFlavors {
338
+
339
+ armv7 {
340
+
341
+ versionCode defaultConfig.versionCode*10 + 2
342
+
343
+ ndk {
344
+
345
+ abiFilters 'armeabi-v7a'
346
+
347
+ }
348
+
349
+ }
350
+
351
+ x86 {
352
+
353
+ versionCode defaultConfig.versionCode*10 + 4
354
+
355
+ ndk {
356
+
357
+ abiFilters 'x86'
358
+
359
+ }
360
+
361
+ }
362
+
363
+ all {
364
+
365
+ ndk {
366
+
367
+ abiFilters "all", ""
368
+
369
+ }
370
+
371
+ }
372
+
373
+ }
374
+
375
+ }
376
+
377
+
378
+
379
+
380
+
381
+ compileOptions {
382
+
383
+ sourceCompatibility JavaVersion.VERSION_1_6
384
+
385
+ targetCompatibility JavaVersion.VERSION_1_6
386
+
387
+ }
388
+
389
+
390
+
391
+ if (cdvReleaseSigningPropertiesFile) {
392
+
393
+ signingConfigs {
394
+
395
+ release {
396
+
397
+ // These must be set or Gradle will complain (even if they are overridden).
398
+
399
+ keyAlias = ""
400
+
401
+ keyPassword = "__unset" // And these must be set to non-empty in order to have the signing step added to the task graph.
402
+
403
+ storeFile = null
404
+
405
+ storePassword = "__unset"
406
+
407
+ }
408
+
409
+ }
410
+
411
+ buildTypes {
412
+
413
+ release {
414
+
415
+ signingConfig signingConfigs.release
416
+
417
+ }
418
+
419
+ }
420
+
421
+ addSigningProps(cdvReleaseSigningPropertiesFile, signingConfigs.release)
422
+
423
+ }
424
+
425
+ if (cdvDebugSigningPropertiesFile) {
426
+
427
+ addSigningProps(cdvDebugSigningPropertiesFile, signingConfigs.debug)
428
+
429
+ }
430
+
431
+ }
432
+
433
+
434
+
435
+ dependencies {
436
+
437
+ compile fileTree(dir: 'libs', include: '*.jar')
438
+
439
+ // SUB-PROJECT DEPENDENCIES START
440
+
441
+ debugCompile(project(path: "CordovaLib", configuration: "debug"))
442
+
443
+ releaseCompile(project(path: "CordovaLib", configuration: "release"))
444
+
445
+ // SUB-PROJECT DEPENDENCIES END
446
+
447
+ }
448
+
449
+
450
+
451
+ def promptForReleaseKeyPassword() {
452
+
453
+ if (!cdvReleaseSigningPropertiesFile) {
454
+
455
+ return;
456
+
457
+ }
458
+
459
+ if ('__unset'.equals(android.signingConfigs.release.storePassword)) {
460
+
461
+ android.signingConfigs.release.storePassword = privateHelpers.promptForPassword('Enter key store password: ')
462
+
463
+ }
464
+
465
+ if ('__unset'.equals(android.signingConfigs.release.keyPassword)) {
466
+
467
+ android.signingConfigs.release.keyPassword = privateHelpers.promptForPassword('Enter key password: ');
468
+
469
+ }
470
+
471
+ }
472
+
473
+
474
+
475
+ gradle.taskGraph.whenReady { taskGraph ->
476
+
477
+ taskGraph.getAllTasks().each() { task ->
478
+
479
+ if (task.name == 'validateReleaseSigning' || task.name == 'validateSigningRelease') {
480
+
481
+ promptForReleaseKeyPassword()
482
+
483
+ }
484
+
485
+ }
486
+
487
+ }
488
+
489
+
490
+
491
+ def addSigningProps(propsFilePath, signingConfig) {
492
+
493
+ def propsFile = file(propsFilePath)
494
+
495
+ def props = new Properties()
496
+
497
+ propsFile.withReader { reader ->
498
+
499
+ props.load(reader)
500
+
501
+ }
502
+
503
+
504
+
505
+ def storeFile = new File(props.get('key.store') ?: privateHelpers.ensureValueExists(propsFilePath, props, 'storeFile'))
506
+
507
+ if (!storeFile.isAbsolute()) {
508
+
509
+ storeFile = RelativePath.parse(true, storeFile.toString()).getFile(propsFile.getParentFile())
510
+
511
+ }
512
+
513
+ if (!storeFile.exists()) {
514
+
515
+ throw new FileNotFoundException('Keystore file does not exist: ' + storeFile.getAbsolutePath())
516
+
517
+ }
518
+
519
+ signingConfig.keyAlias = props.get('key.alias') ?: privateHelpers.ensureValueExists(propsFilePath, props, 'keyAlias')
520
+
521
+ signingConfig.keyPassword = props.get('keyPassword', props.get('key.alias.password', signingConfig.keyPassword))
522
+
523
+ signingConfig.storeFile = storeFile
524
+
525
+ signingConfig.storePassword = props.get('storePassword', props.get('key.store.password', signingConfig.storePassword))
526
+
527
+ def storeType = props.get('storeType', props.get('key.store.type', ''))
528
+
529
+ if (!storeType) {
530
+
531
+ def filename = storeFile.getName().toLowerCase();
532
+
533
+ if (filename.endsWith('.p12') || filename.endsWith('.pfx')) {
534
+
535
+ storeType = 'pkcs12'
536
+
537
+ } else {
538
+
539
+ storeType = signingConfig.storeType // "jks"
540
+
541
+ }
542
+
543
+ }
544
+
545
+ signingConfig.storeType = storeType
546
+
547
+ }
548
+
549
+
550
+
551
+ for (def func : cdvPluginPostBuildExtras) {
552
+
553
+ func()
554
+
555
+ }
556
+
557
+
558
+
559
+ // This can be defined within build-extras.gradle as:
560
+
561
+ // ext.postBuildExtras = { ... code here ... }
562
+
563
+ if (hasProperty('postBuildExtras')) {
564
+
565
+ postBuildExtras()
566
+
567
+ }
568
+
569
+
570
+
571
+ ```
572
+
573
+
574
+
575
+ ![フォルダ構成図](19747a0917d3c78a648b5bb501a01b7c.png)
576
+
577
+
578
+
579
+ - Cのビルド方法
580
+
581
+ 0. 上記のCのソースコードを作成,編集
582
+
583
+ 0. NDK-Buildコマンドでビルド
584
+
585
+ 0. 上記のandroid/src/libsフォルダ内にアーキテクチャごとに.soファイルが生成
586
+
587
+ といった順序で共有ライブラリの作成を行いました.
588
+
589
+
590
+
591
+ AndroidStudio内のjniLibsフォルダに共有ライブラリを移動したい場合は
592
+
593
+ android/src/libsに生成されたsoファイルをandroid/libsにコピーすることで
594
+
595
+ AndroidStudio内でのjniLibsフォルダにコピーが反映されます.