Skip to content

Commit 5607b3c

Browse files
committed
适配旧插件
1 parent 8a20316 commit 5607b3c

File tree

25 files changed

+117
-123
lines changed

25 files changed

+117
-123
lines changed

README.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,11 @@
77

88
### 更新内容
99

10+
* 使用Kotlin重构Gradle-plugin
11+
* 使用并发Transform和InstantRun提升编译速度。插件构建不需要clean
1012
* gradle-plugin 更新至4.2.2
1113
* gradle 更新至6.7.1
1214
* 仅支持AndroidX,不再支持Support包
13-
* 使用Kotlin重构Gradle-plugin
14-
* 使用并发Transform和InstantRun提升编译速度。插件构建不需要clean
15-
* 重构还未经过严格测试。稳定版本请使用[Master](https://github.com/CliffLeopard/RePlugin/tree/master)
1615

1716
### 配置
1817

build.gradle

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,16 @@
22
buildscript {
33
apply from: './plugin_config.gradle'
44
repositories {
5-
maven {
6-
url "http://s3.qbuild.corp.qihoo.net:8360/nexus/content/repositories/360zhushou_Snapshot/"
7-
}
5+
google()
6+
mavenLocal()
87
maven {
98
url "https://plugins.gradle.org/m2/"
109
}
11-
google()
1210
mavenCentral()
1311
}
1412
dependencies {
1513
classpath "com.android.tools.build:gradle:$GRADLE_PLUGIN"
16-
classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.10'
14+
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$KOTLIN_VERSION"
1715
if(SDK_PUBLISH == "false")
1816
{
1917
classpath "com.qihoo360.replugin:replugin-gradle:${RP_VERSION}"
@@ -24,10 +22,8 @@ buildscript {
2422

2523
allprojects {
2624
repositories {
27-
maven {
28-
url "http://s3.qbuild.corp.qihoo.net:8360/nexus/content/repositories/360zhushou_Snapshot/"
29-
}
3025
google()
26+
mavenLocal()
3127
mavenCentral()
3228

3329
}

plugin_config.gradle

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,17 @@
11
project.ext {
2-
32
GRADLE_PLUGIN = '4.2.2'
4-
KOTLIN_VERSION = '1.5.31'
3+
KOTLIN_VERSION = '1.7.20'
54
PLUGIN_PUBLISH_VERSION = '0.15.0'
65
ASM_VERSION = '9.2'
76

8-
RP_CompileSdkVersion = 30
9-
RP_BuildToolsVersion = '30.0.3'
10-
RP_MinSdkVersion = 16
11-
RP_TargetSdkVersion = 30
7+
RP_CompileSdk = 33
8+
RP_MinSdk = 16
9+
RP_TargetSdk = 33
1210

13-
ANDROIDX_APPCOMPAT = '1.3.1'
14-
ANDROIDX_CORE_KTX = '1.6.0'
11+
ANDROIDX_APPCOMPAT = '1.4.2'
12+
ANDROIDX_CORE_KTX = '1.8.0'
1513
LIVEDATA_KTX = '2.3.1'
16-
GOOGLE_MATERIAL = '1.4.0'
14+
GOOGLE_MATERIAL = '1.6.1'
1715
ANDROIDX_CONSTRAIN = '2.1.1'
1816

1917
JUNIT_VERSION = '4.13.2'
@@ -33,8 +31,8 @@ project.ext {
3331
ESPRESSO_VERSION = '3.3.0'
3432

3533
RP_GROUP = 'com.qihoo360.replugin'
36-
RP_VERSION = '2.4.8-SNAPSHOT'
37-
RP_VERSION_CODE = 248
34+
RP_VERSION = '2.4.9-SNAPSHOT'
35+
RP_VERSION_CODE = 249
3836

3937
RP_USER = 'replugin'
4038
RP_REPO = 'replugin'

replugin-gradle/src/main/kotlin/com/qihoo360/replugin/Constants.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ package com.qihoo360.replugin
99
*/
1010
object Constants {
1111
//版本号:不要手动修改,当发布时,会根据rp-config.gradle中的RP_VERSION自动替换
12-
private const val VER = "2.4.8-SNAPSHOT"
12+
private const val VER = "2.4.9-SNAPSHOT"
1313

1414
/** 打印信息时候的前缀 */
1515
const val HOST_TAG = "< replugin-host-$VER >"

replugin-gradle/src/main/kotlin/com/qihoo360/replugin/task/tools/BuiltInJsonCreator.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,6 @@ class PluginInfo {
9797
var ver: Long = -1
9898

9999
/** 框架版本号 */
100-
var from: Long = -1
100+
var frm: Long = -1
101101

102102
}

replugin-gradle/src/main/kotlin/com/qihoo360/replugin/task/tools/PluginInfoParser.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ class PluginInfoParser(pluginFile: File, extension: HostExtension) : DefaultHand
5555
tagVersionLow -> pluginInfo.low = attributes.getValue(androidValue).toLong()
5656
tagVersionHigh -> pluginInfo.height = attributes.getValue(androidValue).toLong()
5757
tagVersionVer -> pluginInfo.ver = attributes.getValue(androidValue).toLong()
58-
tagFrameWorkVer -> pluginInfo.from = attributes.getValue(androidValue).toLong()
58+
tagFrameWorkVer -> pluginInfo.frm = attributes.getValue(androidValue).toLong()
5959
}
6060

6161
} else if ("manifest" == qName) {

replugin-gradle/src/main/kotlin/com/qihoo360/replugin/transform/pool/JarTransformTask.kt

Lines changed: 37 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ class JarTransformTask(
3030
private val tag = "JarTransformTask"
3131
override fun compute(): Boolean {
3232
jarInputList.forEach { jarInput ->
33-
3433
val md5 = DigestUtils.md5Hex(jarInput.file.absolutePath)
3534
val out = outputProvider.getContentLocation(
3635
md5, jarInput.contentTypes, jarInput.scopes, Format.JAR
@@ -50,36 +49,11 @@ class JarTransformTask(
5049
while (entry != null) {
5150
val outEntry: ZipEntry = copyEntry(entry)
5251
if (!entry.isDirectory && entry.name.endsWith(".class")) {
53-
val name = entry.name.removeSuffix(".class")
54-
val separatorIndex = entry.name.lastIndexOf(File.separatorChar)
55-
val packageName =
56-
if (separatorIndex > -1)
57-
entry.name
58-
.substring(0, separatorIndex)
59-
.removePrefix(File.separator)
60-
.removeSuffix(File.separator)
61-
else ""
62-
val isInnerClass = entry.name.contains("$")
63-
val className =
64-
if (separatorIndex > -1)
65-
entry.name.substring(separatorIndex + 1)
66-
.removeSuffix(".class")
67-
else
68-
entry.name.removeSuffix(".class")
69-
70-
val transformClassInfo = TransformClassInfo(
71-
name,
72-
packageName,
73-
className,
74-
jarInput.file.absolutePath,
75-
out.absolutePath,
76-
jarInput,
77-
true,
78-
isInnerClass
79-
)
52+
val transformClassInfo = buildTransformClassInfo(entry.name, jarInput, out)
8053
val bytes = IOUtils.toByteArray(jar)
8154
try {
82-
val changedBytes = transForm.transformClass(transformClassInfo, bytes)
55+
val changedBytes =
56+
transForm.transformClass(transformClassInfo, bytes)
8357
if (changedBytes == null) {
8458
outJar.putNextEntry(outEntry)
8559
IOUtils.write(bytes, outJar)
@@ -107,6 +81,40 @@ class JarTransformTask(
10781
return true
10882
}
10983

84+
private fun buildTransformClassInfo(
85+
entryName: String,
86+
jarInput: JarInput,
87+
out: File
88+
): TransformClassInfo {
89+
val name = entryName.removeSuffix(".class")
90+
val separatorIndex = entryName.lastIndexOf(File.separatorChar)
91+
val packageName =
92+
if (separatorIndex > -1)
93+
entryName
94+
.substring(0, separatorIndex)
95+
.removePrefix(File.separator)
96+
.removeSuffix(File.separator)
97+
else ""
98+
val isInnerClass = entryName.contains("$")
99+
val className =
100+
if (separatorIndex > -1)
101+
entryName.substring(separatorIndex + 1)
102+
.removeSuffix(".class")
103+
else
104+
entryName.removeSuffix(".class")
105+
106+
return TransformClassInfo(
107+
name,
108+
packageName,
109+
className,
110+
jarInput.file.absolutePath,
111+
out.absolutePath,
112+
jarInput,
113+
true,
114+
isInnerClass
115+
)
116+
}
117+
110118
private fun copyEntry(entry: ZipEntry): ZipEntry {
111119
val newEntry = ZipEntry(entry.name)
112120
newEntry.comment = entry.comment

replugin-lib-base/build.gradle

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ plugins {
66
}
77

88
android {
9-
compileSdkVersion RP_CompileSdkVersion
9+
compileSdk RP_CompileSdk
1010

1111
defaultConfig {
12-
minSdkVersion RP_MinSdkVersion
13-
targetSdkVersion RP_TargetSdkVersion
12+
minSdkVersion RP_MinSdk
13+
targetSdkVersion RP_TargetSdk
1414
versionCode RP_VERSION_CODE
1515
versionName RP_VERSION
1616

replugin-lib-host/build.gradle

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,11 @@ plugins {
66
}
77

88
android {
9-
compileSdkVersion RP_CompileSdkVersion
10-
buildToolsVersion RP_BuildToolsVersion
9+
compileSdk RP_CompileSdk
1110

1211
defaultConfig {
13-
minSdkVersion RP_MinSdkVersion
14-
targetSdkVersion RP_TargetSdkVersion
12+
minSdkVersion RP_MinSdk
13+
targetSdkVersion RP_TargetSdk
1514
versionCode RP_VERSION_CODE
1615
versionName RP_VERSION
1716

replugin-lib-host/src/main/java/com/qihoo360/loader2/Loader.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ final boolean isAppLoaded() {
166166
}
167167

168168
final Context createBaseContext(Context newBase) {
169-
return new PluginContext(newBase, android.R.style.Theme, mClassLoader, mPkgResources, mPluginName, this);
169+
return mPkgContext == null ? new PluginContext(newBase, android.R.style.Theme, mClassLoader, mPkgResources, mPluginName, this) : mPkgContext;
170170
}
171171

172172
final boolean loadDex(ClassLoader parent, int load) {

0 commit comments

Comments
 (0)