#plugin #gradle compat provider like 4b29af3

This commit is contained in:
hyongbai 2019-05-28 17:23:19 +08:00
parent 4b29af356b
commit f43bbbe56c
5 changed files with 57 additions and 8 deletions

View File

@ -0,0 +1,40 @@
package com.qihoo360.replugin.gradle.compat
import com.android.sdklib.IAndroidTarget
/**
* @author hyongbai
*/
class ScopeCompat {
static def getAdbExecutable(def scope) {
final MetaClass scopeClz = scope.metaClass
if (scopeClz.hasProperty(scope, "androidBuilder")) {
return scope.androidBuilder.sdkInfo.adb
}
if (scopeClz.hasProperty(scope, "sdkComponents")) {
return scope.sdkComponents.adbExecutableProvider.get()
}
}
// TODO: getBuilderTarget
// static def getBuilderTarget(def scope, def target){
// final MetaClass scopeClz = scope.metaClass
//
// if (scopeClz.hasProperty(scope, "androidBuilder")) {
// return scope.getAndroidBuilder().getTarget().getPath(target) //IAndroidTarget.ANDROID_JAR
// }
//
// return globalScope.getAndroidBuilder().getTarget().getPath(IAndroidTarget.ANDROID_JAR)
// }
static def getAndroidJar(def scope){
final MetaClass scopeClz = scope.metaClass
if (scopeClz.hasProperty(scope, "androidBuilder")) {
return scope.getAndroidBuilder().getTarget().getPath(IAndroidTarget.ANDROID_JAR)
}
if (scopeClz.hasProperty(scope, "sdkComponents")) {
return scope.sdkComponents.androidJarProvider.get().getAbsolutePath()
}
}
}

View File

@ -48,6 +48,14 @@ version = "${verLine.split("\"")[1]}" // 版本
//
java.lang.System.err.println "version=${version}"
sourceSets {
main {
groovy {
srcDirs '../replugin-host-gradle/src/main/groovy/com/qihoo360/replugin/gradle/compat'
}
}
}
dependencies {
compile 'com.android.tools.build:gradle:2.1.3'
compile 'org.json:json:20160212'

View File

@ -19,6 +19,7 @@ package com.qihoo360.replugin.gradle.plugin
import com.android.build.gradle.AppExtension
import com.android.build.gradle.AppPlugin
import com.qihoo360.replugin.gradle.compat.VariantCompat
import com.qihoo360.replugin.gradle.plugin.debugger.PluginDebugger
import com.qihoo360.replugin.gradle.plugin.inner.CommonData
import com.qihoo360.replugin.gradle.plugin.inner.ReClassTransform
@ -55,7 +56,7 @@ public class ReClassPlugin implements Plugin<Project> {
def variantData = variant.variantData
def scope = variantData.scope
def assembleTask = variant.getAssemble()
def assembleTask = VariantCompat.getAssembleTask(variant)
def installPluginTaskName = scope.getTaskName(AppConstant.TASK_INSTALL_PLUGIN, "")
def installPluginTask = project.task(installPluginTaskName)

View File

@ -17,6 +17,7 @@
package com.qihoo360.replugin.gradle.plugin.debugger
import com.qihoo360.replugin.gradle.compat.ScopeCompat
import com.qihoo360.replugin.gradle.plugin.AppConstant
import com.qihoo360.replugin.gradle.plugin.util.CmdUtil
import org.gradle.api.Project
@ -56,7 +57,7 @@ class PluginDebugger {
apkFile = new File(apkDir, variantConfiguration.getBaseName() + File.separator + apkName)
}
adbFile = globalScope.androidBuilder.sdkInfo.adb;
adbFile = ScopeCompat.getAdbExecutable(globalScope)
}

View File

@ -20,11 +20,10 @@ package com.qihoo360.replugin.gradle.plugin.inner
import com.android.build.api.transform.DirectoryInput
import com.android.build.api.transform.JarInput
import com.android.build.api.transform.TransformInput
import com.android.build.gradle.internal.scope.GlobalScope
import com.android.sdklib.IAndroidTarget
import org.apache.commons.io.FileUtils
import com.google.common.base.Charsets
import com.google.common.hash.Hashing
import com.qihoo360.replugin.gradle.compat.ScopeCompat
import org.apache.commons.io.FileUtils
import org.gradle.api.Project
import java.nio.file.Files
@ -40,7 +39,7 @@ public class Util {
/** 生成 ClassPool 使用的 ClassPath 集合,同时将要处理的 jar 写入 includeJars */
def
static getClassPaths(Project project, GlobalScope globalScope, Collection<TransformInput> inputs, Set<String> includeJars, Map<String, String> map) {
static getClassPaths(Project project, def globalScope, Collection<TransformInput> inputs, Set<String> includeJars, Map<String, String> map) {
def classpathList = []
// android.jar
@ -120,8 +119,8 @@ public class Util {
/**
* android.jar
*/
def static getAndroidJarPath(GlobalScope globalScope) {
return globalScope.getAndroidBuilder().getTarget().getPath(IAndroidTarget.ANDROID_JAR)
def static getAndroidJarPath(def globalScope) {
return ScopeCompat.getAndroidJar(globalScope)
}
/**