Skip to content

Commit

Permalink
#plugin #gradle compat provider like 4b29af3
Browse files Browse the repository at this point in the history
  • Loading branch information
hyongbai committed May 28, 2019
1 parent 4b29af3 commit f43bbbe
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -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()
}
}
}
8 changes: 8 additions & 0 deletions replugin-plugin-gradle/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -56,7 +57,7 @@ class PluginDebugger {
apkFile = new File(apkDir, variantConfiguration.getBaseName() + File.separator + apkName)
}

adbFile = globalScope.androidBuilder.sdkInfo.adb;
adbFile = ScopeCompat.getAdbExecutable(globalScope)

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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)
}

/**
Expand Down

1 comment on commit f43bbbe

@hyongbai
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

已在多个 gradle 和 Android build 插件的组合测试通过

组合列表

gradle android build gradle
gradle-2.14.1 com.android.tools.build:gradle:2.1.3
gradle-3.3 com.android.tools.build:gradle:2.3.3
gradle-4.10.2 com.android.tools.build:gradle:2.3.3
gradle-5.3.1 com.android.tools.build:gradle:3.4.1
gradle-5.4.1 com.android.tools.build:gradle:3.6.0-alpha01

关联

提交:

4b29af3

issue:

Please sign in to comment.