@@ -161,10 +161,10 @@ class TinkerPatchPlugin implements Plugin<Project> {
161
161
162
162
if (variantOutput. metaClass. hasProperty(variantOutput, ' processResourcesProvider' )) {
163
163
manifestTask. manifestPath = variantOutput. processResourcesProvider. get(). manifestFile
164
- } else if (variantOutput. processManifest. properties[' manifestOutputFile' ] != null ) {
165
- manifestTask. manifestPath = variantOutput. processManifest. manifestOutputFile
166
- } else if (variantOutput. processResources. properties[' manifestFile' ] != null ) {
164
+ } else if (variantOutput. processResources. metaClass. hasProperty(variantOutput. processResources, ' manifestFile' )) {
167
165
manifestTask. manifestPath = variantOutput. processResources. manifestFile
166
+ } else if (variantOutput. processManifest. metaClass. hasProperty(variantOutput. processManifest, ' manifestOutputFile' )) {
167
+ manifestTask. manifestPath = variantOutput. processManifest. manifestOutputFile
168
168
}
169
169
170
170
@@ -188,11 +188,15 @@ class TinkerPatchPlugin implements Plugin<Project> {
188
188
189
189
190
190
if (variantOutput. metaClass. hasProperty(variantOutput, ' processResourcesProvider' )) {
191
- applyResourceTask. resDir = variantOutput. processResourcesProvider. get(). inputResourcesDir. getFiles(). first()
192
- } else if (variantOutput. processResources. properties[' resDir' ] != null ) {
193
- applyResourceTask. resDir = variantOutput. processResources. resDir
194
- } else if (variantOutput. processResources. properties[' inputResourcesDir' ] != null ) {
191
+ try {
192
+ applyResourceTask. resDir = variantOutput. processResourcesProvider. get(). inputResourcesDir. getAsFile(). get()
193
+ } catch (Exception e) {
194
+ applyResourceTask. resDir = variantOutput. processResourcesProvider. get(). inputResourcesDir. getFiles(). first()
195
+ }
196
+ } else if (variantOutput. processResources. metaClass. hasProperty(variantOutput. processResources, ' inputResourcesDir' )) {
195
197
applyResourceTask. resDir = variantOutput. processResources. inputResourcesDir. getFiles(). first()
198
+ } else if (variantOutput. processResources. metaClass. hasProperty(variantOutput. processResources, ' resDir' )) {
199
+ applyResourceTask. resDir = variantOutput. processResources. resDir
196
200
}
197
201
198
202
// let applyResourceTask run after manifestTask
@@ -298,7 +302,11 @@ class TinkerPatchPlugin implements Plugin<Project> {
298
302
if (variant. metaClass. hasProperty(variant, ' packageApplicationProvider' )) {
299
303
def packageAndroidArtifact = variant. packageApplicationProvider. get()
300
304
if (packageAndroidArtifact != null ) {
301
- parentFile = new File (packageAndroidArtifact. outputDirectory, output. apkData. outputFileName)
305
+ try {
306
+ parentFile = new File (packageAndroidArtifact. outputDirectory. getAsFile(). get(), output. apkData. outputFileName)
307
+ } catch (Exception e) {
308
+ parentFile = new File (packageAndroidArtifact. outputDirectory, output. apkData. outputFileName)
309
+ }
302
310
} else {
303
311
parentFile = output. mainOutputFile. outputFile
304
312
}
@@ -357,7 +365,11 @@ class TinkerPatchPlugin implements Plugin<Project> {
357
365
if (variant. metaClass. hasProperty(variant, ' packageApplicationProvider' )) {
358
366
def packageAndroidArtifact = variant. packageApplicationProvider. get()
359
367
if (packageAndroidArtifact != null ) {
360
- tinkerPatchBuildTask. buildApkPath = new File (packageAndroidArtifact. outputDirectory, output. apkData. outputFileName)
368
+ try {
369
+ tinkerPatchBuildTask. buildApkPath = new File (packageAndroidArtifact. outputDirectory. getAsFile(). get(), output. apkData. outputFileName)
370
+ } catch (Exception e) {
371
+ tinkerPatchBuildTask. buildApkPath = new File (packageAndroidArtifact. outputDirectory, output. apkData. outputFileName)
372
+ }
361
373
} else {
362
374
tinkerPatchBuildTask. buildApkPath = output. mainOutputFile. outputFile
363
375
}
@@ -433,9 +445,20 @@ class TinkerPatchPlugin implements Plugin<Project> {
433
445
434
446
File getManifestMultiDexKeepProguard (def applicationVariant ) {
435
447
File multiDexKeepProguard = null
448
+
436
449
try {
437
- multiDexKeepProguard = applicationVariant. getVariantData(). getScope(). getManifestKeepListProguardFile()
450
+ File file = applicationVariant. getVariantData(). getScope(). getArtifacts(). getFinalProduct(
451
+ Class . forName(" com.android.build.gradle.internal.scope.InternalArtifactType" )
452
+ .getDeclaredField(" LEGACY_MULTIDEX_AAPT_DERIVED_PROGUARD_RULES" )
453
+ .get(null )
454
+ ). getOrNull()?. getAsFile()
455
+ if (file != null && file. getName() != ' __EMPTY_DIR__' ) {
456
+ multiDexKeepProguard = file
457
+ }
438
458
} catch (Throwable ignore) {
459
+ }
460
+
461
+ if (multiDexKeepProguard == null ) {
439
462
try {
440
463
def buildableArtifact = applicationVariant. getVariantData(). getScope(). getArtifacts(). getFinalArtifactFiles(
441
464
Class . forName(" com.android.build.gradle.internal.scope.InternalArtifactType" )
@@ -445,17 +468,30 @@ class TinkerPatchPlugin implements Plugin<Project> {
445
468
446
469
// noinspection GroovyUncheckedAssignmentOfMemberOfRawType,UnnecessaryQualifiedReference
447
470
multiDexKeepProguard = com.google.common.collect.Iterators . getOnlyElement(buildableArtifact. iterator())
448
- } catch (Throwable e ) {
471
+ } catch (Throwable ignore ) {
449
472
450
473
}
451
- if (multiDexKeepProguard == null ) {
452
- try {
453
- multiDexKeepProguard = applicationVariant. getVariantData(). getScope(). getManifestKeepListFile()
454
- } catch (Throwable e) {
455
- mProject. logger. error(" can't find getManifestKeepListFile method, exception:${ e} " )
456
- }
474
+ }
475
+
476
+ if (multiDexKeepProguard == null ) {
477
+ try {
478
+ multiDexKeepProguard = applicationVariant. getVariantData(). getScope(). getManifestKeepListProguardFile()
479
+ } catch (Throwable ignore) {
480
+
457
481
}
458
482
}
483
+
484
+ if (multiDexKeepProguard == null ) {
485
+ try {
486
+ multiDexKeepProguard = applicationVariant. getVariantData(). getScope(). getManifestKeepListFile()
487
+ } catch (Throwable ignore) {
488
+
489
+ }
490
+ }
491
+
492
+ if (multiDexKeepProguard == null ) {
493
+ mProject. logger. error(" can't get multiDexKeepProguard file" )
494
+ }
459
495
return multiDexKeepProguard
460
496
}
461
497
0 commit comments