@@ -79,20 +79,10 @@ def renameResultApks (variant) {
79
79
def apkDirectory = output. packageApplication. outputFile. parentFile
80
80
def apkNamePrefix = rootProject. name + " -" + variant. buildType. name
81
81
82
- if (output. zipAlign) {
83
- if (project. ext. selectedBuildType == variant. buildType. name) {
84
- output. zipAlign. dependsOn(buildMetadata)
85
- }
86
-
87
- name = apkNamePrefix + " .apk"
88
- output. outputFile = new File (apkDirectory, name);
89
- }
90
-
91
82
name = apkNamePrefix + " -unaligned.apk"
92
83
output. packageApplication. outputFile = new File (apkDirectory, name);
93
84
94
85
if (output. packageApplication && (project. ext. selectedBuildType == variant. buildType. name)) {
95
- buildMetadata. dependsOn(output. packageApplication)
96
86
project. ext. currentApkFile = output. packageApplication. outputFile. getAbsolutePath(). replace(' \\ ' , ' /' )
97
87
}
98
88
}
@@ -141,6 +131,14 @@ android {
141
131
applicationVariants. all { variant ->
142
132
renameResultApks(variant)
143
133
}
134
+
135
+
136
+ applicationVariants. all { variant ->
137
+ def variantName = variant. name. capitalize()
138
+ def compileSourcesTaskName = " compile${ variantName} Sources"
139
+ def compileSourcesTask = project. tasks. findByName(compileSourcesTaskName)
140
+ compileSourcesTask. finalizedBy " buildMetadata"
141
+ }
144
142
}
145
143
146
144
repositories {
@@ -323,7 +321,7 @@ task cleanLocalAarFiles(type: Delete) {
323
321
}
324
322
325
323
task ensureMetadataOutDir {
326
- def outputDir = file(" $rootDir /metadata/output" )
324
+ def outputDir = file(" $rootDir /metadata/output/assets/metadata " )
327
325
outputDir. mkdirs()
328
326
}
329
327
@@ -348,7 +346,7 @@ task collectAllJars {
348
346
}
349
347
350
348
metadataParams. add(" metadata-generator.jar" )
351
- metadataParams. add(" ../metadata/output" )
349
+ metadataParams. add(" ../metadata/output/assets/metadata " )
352
350
for (def i = 0 ; i < allJarPaths. size(); i++ ) {
353
351
metadataParams. add(allJarPaths. get(i));
354
352
}
@@ -382,7 +380,7 @@ task buildMetadata (type: JavaExec) {
382
380
inputs. files(allJarPaths)
383
381
inputs. dir(" build/intermediates/classes" )
384
382
385
- outputs. files(" metadata/output/treeNodeStream.dat" , " metadata/output/treeStringsStream.dat" , " metadata/output/treeValueStream.dat" )
383
+ outputs. files(" metadata/output/assets/metadata/ treeNodeStream.dat" , " metadata/output/assets/metadata/ treeStringsStream.dat" , " metadata/output/assets/metadata /treeValueStream.dat" )
386
384
387
385
doFirst {
388
386
workingDir " build-tools"
@@ -391,93 +389,32 @@ task buildMetadata (type: JavaExec) {
391
389
392
390
args metadataParams. toArray()
393
391
}
394
-
392
+
395
393
doLast {
396
- copy {
397
- from " metadata/output"
398
- into " src/main/assets/metadata"
399
- }
400
-
401
- def zip_properties = new HashMap<String , String > ()
402
- zip_properties. put(" create" , " true" )
403
- zip_properties. put(" encoding" , " UTF-8" )
404
-
405
- def currentApk = project. ext. currentApkFile
406
- def currentApkAsEncoded = currentApk. replace(" " , " %20" )
407
- def urlPrefix = " jar:file:" + (isWinOs ? " /" : " " )
408
-
409
- def zip_disk = URI . create(urlPrefix + currentApkAsEncoded);
410
-
411
- def zipfs
412
- def pathInZipfile
413
- try {
414
- zipfs = java.nio.file.FileSystems . newFileSystem(zip_disk, zip_properties)
415
-
416
- def filesToDelete = [" assets/metadata/treeNodeStream.dat" , " assets/metadata/treeStringsStream.dat" , " assets/metadata/treeValueStream.dat" ,
417
- " META-INF/CERT.RSA" , " META-INF/CERT.SF" , " META-INF/MANIFEST.MF" ]
418
-
419
- for (def file : filesToDelete) {
420
- pathInZipfile = zipfs. getPath(file)
421
- if (java.nio.file.Files . exists(pathInZipfile)) {
422
- java.nio.file.Files . delete(pathInZipfile)
423
- }
424
- }
425
-
426
- pathInZipfile = zipfs. getPath(" assets/metadata" )
427
- if (! java.nio.file.Files . exists(pathInZipfile)) {
428
- java.nio.file.Files . createDirectory(pathInZipfile)
429
- }
430
-
431
- def metadataFiles = [" treeNodeStream.dat" , " treeStringsStream.dat" , " treeValueStream.dat" ]
432
- for (def mdFile : metadataFiles) {
433
- pathInZipfile = java.nio.file.Files . createFile(zipfs. getPath(" assets/metadata/" + mdFile))
434
-
435
- def mdFilePath = java.nio.file.Paths . get(" $rootDir /metadata/output/" + mdFile)
436
- def data = java.nio.file.Files . readAllBytes(mdFilePath)
437
-
438
- java.nio.file.Files . write(pathInZipfile, data, java.nio.file.StandardOpenOption . WRITE )
439
- }
440
- } finally {
441
- if (zipfs != null ) {
442
- zipfs. close()
443
- }
444
- }
445
-
446
- def androidHome = new File (System . properties[' user.home' ], " .android" )
447
- def keyStoreFile = new File (androidHome, " debug.keystore" )
448
-
449
- def storePass
450
- def keyPass
451
- def keyStorePath
452
- def alias
453
-
454
- if (project. ext. selectedBuildType. equals(" release" )) {
455
- storePass = project. password
456
- keyPass = project. ksPassword
457
- keyStorePath = project. ksPath
458
- alias = project. alias
459
- } else {
460
- storePass = " android"
461
- keyPass = " android"
462
- keyStorePath = keyStoreFile. getAbsolutePath()
463
- alias = " androiddebugkey"
464
- }
465
- def jarSignerPath = new File (System . getenv(" JAVA_HOME" ), " bin/jarsigner" ). getAbsolutePath()
466
-
467
- def cmdParams = new ArrayList<String > ([jarSignerPath, " -sigalg" , " SHA1withRSA" , " -digestalg" , " SHA1" , " -storepass" , storePass, " -keypass" , keyPass, " -keystore" , keyStorePath, currentApk, alias])
468
-
394
+ def tmpResourceAPK = new File (" ${ buildDir} /intermediates/res/resources-${ project.ext.selectedBuildType} .ap_" )
395
+
396
+ def aaptCommand = " ${ android.getSdkDirectory().getAbsolutePath()} /build-tools/${ android.buildToolsVersion} /aapt"
469
397
if (isWinOs) {
470
- cmdParams. add(0 , " /c" )
471
- cmdParams. add(0 , " cmd" )
398
+ aaptCommand + = " .exe"
472
399
}
473
-
400
+
401
+ println " >>aapt found=" + new File (aaptCommand). exists()
402
+
403
+ def tmpAPKPath = tmpResourceAPK. getPath()
404
+
405
+ def removeCmdParams = new ArrayList<String > ([aaptCommand, " remove" , tmpAPKPath, " assets/metadata/treeNodeStream.dat" , " assets/metadata/treeStringsStream.dat" , " assets/metadata/treeValueStream.dat" ])
406
+
474
407
exec {
475
- if (isWinOs) {
476
- commandLine cmdParams. toArray()
477
- }
478
- else {
479
- commandLine cmdParams. toArray()
480
- }
408
+ ignoreExitValue true
409
+ workingDir " metadata/output"
410
+ commandLine removeCmdParams. toArray()
411
+ }
412
+
413
+ def addCmdParams = new ArrayList<String > ([aaptCommand, " add" , tmpAPKPath, " assets/metadata/treeNodeStream.dat" , " assets/metadata/treeStringsStream.dat" , " assets/metadata/treeValueStream.dat" ])
414
+
415
+ exec {
416
+ workingDir " metadata/output"
417
+ commandLine addCmdParams. toArray()
481
418
}
482
419
}
483
420
}
@@ -494,6 +431,7 @@ task deleteExplodedAarFolder (type: Delete) {
494
431
}
495
432
496
433
434
+
497
435
// //////////////////////////////////////////////////////////////////////////////////
498
436
// //////////////////////////// OPTIONAL TASKS //////////////////////////////////////
499
437
// //////////////////////////////////////////////////////////////////////////////////
0 commit comments