@@ -11,7 +11,7 @@ class AndroidJunkCodePlugin implements Plugin<Project> {
1111
1212 @Override
1313 void apply (Project project ) {
14- def android = project. extensions. getByType (AppExtension )
14+ def android = project. extensions. findByType (AppExtension )
1515 if (! android) {
1616 throw IllegalArgumentException (" must apply this plugin after 'com.android.application'" )
1717 }
@@ -25,27 +25,6 @@ class AndroidJunkCodePlugin implements Plugin<Project> {
2525 createGenerateJunkCodeTask(project, android, variant, junkCodeConfig)
2626 }
2727 }
28-
29- project. afterEvaluate {
30- android. applicationVariants. all { variant ->
31- def variantName = variant. name
32- def generateJunkCodeTaskName = " generate${ variantName.capitalize()} JunkCode"
33- def generateJunkCodeTask = project. tasks. findByName(generateJunkCodeTaskName)
34- if (generateJunkCodeTask) {
35- // 已经用variantConfig方式配置过了
36- return
37- }
38- def closure = generateJunkCodeExt. configMap[variantName]
39- if (closure) {
40- def junkCodeConfig = new JunkCodeConfig ()
41- closure. delegate = junkCodeConfig
42- closure. resolveStrategy = Closure . DELEGATE_FIRST
43- closure. call()
44- println (" AndroidJunkCode: configMap配置方式已过时,请使用variantConfig配置方式" )
45- createGenerateJunkCodeTask(project, android, variant, junkCodeConfig)
46- }
47- }
48- }
4928 }
5029
5130 private def createGenerateJunkCodeTask = { project , android , variant , junkCodeConfig ->
@@ -69,11 +48,7 @@ class AndroidJunkCodePlugin implements Plugin<Project> {
6948 for (int i = variant. sourceSets. size() - 1 ; i >= 0 ; i-- ) {
7049 def sourceSet = variant. sourceSets[i]
7150 if (! sourceSet. manifestFile. exists()) {
72- android. sourceSets. " ${ sourceSet.name} " . manifest. srcFile(manifestFile. absolutePath)
73- def processMainManifestTask = project. tasks. findByName(" process${ variantName.capitalize()} MainManifest" )
74- if (processMainManifestTask) {
75- processMainManifestTask. dependsOn(generateJunkCodeTask)
76- }
51+ sourceSet. manifest. srcFile(manifestFile. absolutePath)
7752 break
7853 }
7954 }
0 commit comments