diff --git a/app/build.gradle b/app/build.gradle index 4b5e9d28..43d7f7a2 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,6 +1,8 @@ apply plugin: 'com.android.application' apply plugin: 'kotlin-android' -apply plugin: 'android-junk-code' +if (PLUGIN_ENABLE.toBoolean()) { + apply plugin: 'android-junk-code' +} apply plugin: 'com.getkeepsafe.dexcount' apply plugin: 'kotlin-kapt' @@ -30,23 +32,62 @@ android { checkReleaseBuilds false abortOnError false } -} -androidJunkCode { - def config = { - packageBase = "cn.hx.plugin.ui" - packageCount = 30 - activityCountPerPackage = 3 - excludeActivityJavaFile = false - otherCountPerPackage = 50 - methodCountPerClass = 20 - resPrefix = "junk_" - drawableCount = 300 - stringCount = 300 + flavorDimensions 'PRODUCT' + + productFlavors { + free { + dimension 'PRODUCT' + } + pro { + dimension 'PRODUCT' + } + } + + applicationVariants.all { variant -> + def mergedFlavor = variant.mergedFlavor + switch (variant.flavorName) { + case "free": + switch (variant.buildType.name) { + case "debug": + mergedFlavor.manifestPlaceholders += ["API_KEY": "appKey1"] + break + case "release": + mergedFlavor.manifestPlaceholders += ["API_KEY": "appKey2"] + break + } + break + case "pro": + switch (variant.buildType.name) { + case "debug": + mergedFlavor.manifestPlaceholders += ["API_KEY": "appKey3"] + break + case "release": + mergedFlavor.manifestPlaceholders += ["API_KEY": "appKey4"] + break + } + break + } } - variantConfig { - debug config - release config +} + +if (PLUGIN_ENABLE.toBoolean()) { + androidJunkCode { + def config = { + packageBase = "cn.hx.plugin.ui" + packageCount = 30 + activityCountPerPackage = 30 + excludeActivityJavaFile = false + otherCountPerPackage = 50 + methodCountPerClass = 20 + resPrefix = "junk_" + drawableCount = 300 + stringCount = 300 + } + variantConfig { + freeRelease config + proRelease config + } } } diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index b6342106..3b69736b 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -10,6 +10,8 @@ android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" android:theme="@style/AppTheme"> + + diff --git a/build.gradle b/build.gradle index 284ef769..4c121e41 100644 --- a/build.gradle +++ b/build.gradle @@ -9,10 +9,9 @@ buildscript { dependencies { classpath 'com.android.tools.build:gradle:4.2.1' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" - classpath "com.github.qq549631030:android-junk-code:1.1.2" - classpath 'com.vanniktech:gradle-maven-publish-plugin:0.18.0' classpath "com.getkeepsafe.dexcount:dexcount-gradle-plugin:3.0.1" - +// classpath project(":library") + classpath "com.github.qq549631030:android-junk-code:1.1.3" // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files } diff --git a/gradle.properties b/gradle.properties index e57e9c10..50440ed9 100644 --- a/gradle.properties +++ b/gradle.properties @@ -22,4 +22,6 @@ kotlin.code.style=official org.gradle.warning.mode=all -RELEASE_SIGNING_ENABLED=true \ No newline at end of file +RELEASE_SIGNING_ENABLED=true + +PLUGIN_ENABLE = true \ No newline at end of file diff --git a/library/build.gradle b/library/build.gradle index ceef8dc2..a645b638 100644 --- a/library/build.gradle +++ b/library/build.gradle @@ -1,3 +1,13 @@ +buildscript { + repositories { + google() + mavenCentral() + } + dependencies { + classpath 'com.vanniktech:gradle-maven-publish-plugin:0.18.0' + } +} + apply plugin: 'groovy' apply plugin: "com.vanniktech.maven.publish" diff --git a/library/gradle.properties b/library/gradle.properties index 18cac610..78c78f04 100644 --- a/library/gradle.properties +++ b/library/gradle.properties @@ -1,6 +1,6 @@ #project GROUP=com.github.qq549631030 -VERSION_NAME=1.1.2 +VERSION_NAME=1.1.3 POM_ARTIFACT_ID=android-junk-code POM_NAME=AndroidJunkCode diff --git a/library/src/main/groovy/cn/hx/plugin/junkcode/ext/AndroidJunkCodeExt.groovy b/library/src/main/groovy/cn/hx/plugin/junkcode/ext/AndroidJunkCodeExt.groovy index e201cd23..f9871c7f 100644 --- a/library/src/main/groovy/cn/hx/plugin/junkcode/ext/AndroidJunkCodeExt.groovy +++ b/library/src/main/groovy/cn/hx/plugin/junkcode/ext/AndroidJunkCodeExt.groovy @@ -4,7 +4,6 @@ import org.gradle.api.Action import org.gradle.api.NamedDomainObjectContainer class AndroidJunkCodeExt { - Map> configMap = [:] NamedDomainObjectContainer variantConfig diff --git a/library/src/main/groovy/cn/hx/plugin/junkcode/plugin/AndroidJunkCodePlugin.groovy b/library/src/main/groovy/cn/hx/plugin/junkcode/plugin/AndroidJunkCodePlugin.groovy index 76b21f50..4487ec55 100644 --- a/library/src/main/groovy/cn/hx/plugin/junkcode/plugin/AndroidJunkCodePlugin.groovy +++ b/library/src/main/groovy/cn/hx/plugin/junkcode/plugin/AndroidJunkCodePlugin.groovy @@ -11,7 +11,7 @@ class AndroidJunkCodePlugin implements Plugin { @Override void apply(Project project) { - def android = project.extensions.getByType(AppExtension) + def android = project.extensions.findByType(AppExtension) if (!android) { throw IllegalArgumentException("must apply this plugin after 'com.android.application'") } @@ -25,27 +25,6 @@ class AndroidJunkCodePlugin implements Plugin { createGenerateJunkCodeTask(project, android, variant, junkCodeConfig) } } - - project.afterEvaluate { - android.applicationVariants.all { variant -> - def variantName = variant.name - def generateJunkCodeTaskName = "generate${variantName.capitalize()}JunkCode" - def generateJunkCodeTask = project.tasks.findByName(generateJunkCodeTaskName) - if (generateJunkCodeTask) { - //已经用variantConfig方式配置过了 - return - } - def closure = generateJunkCodeExt.configMap[variantName] - if (closure) { - def junkCodeConfig = new JunkCodeConfig() - closure.delegate = junkCodeConfig - closure.resolveStrategy = Closure.DELEGATE_FIRST - closure.call() - println("AndroidJunkCode: configMap配置方式已过时,请使用variantConfig配置方式") - createGenerateJunkCodeTask(project, android, variant, junkCodeConfig) - } - } - } } private def createGenerateJunkCodeTask = { project, android, variant, junkCodeConfig -> @@ -69,11 +48,7 @@ class AndroidJunkCodePlugin implements Plugin { for (int i = variant.sourceSets.size() - 1; i >= 0; i--) { def sourceSet = variant.sourceSets[i] if (!sourceSet.manifestFile.exists()) { - android.sourceSets."${sourceSet.name}".manifest.srcFile(manifestFile.absolutePath) - def processMainManifestTask = project.tasks.findByName("process${variantName.capitalize()}MainManifest") - if (processMainManifestTask) { - processMainManifestTask.dependsOn(generateJunkCodeTask) - } + sourceSet.manifest.srcFile(manifestFile.absolutePath) break } }