Skip to content

Commit

Permalink
build: 去掉所有jar-wrapper工程
Browse files Browse the repository at this point in the history
这里主要解决的问题是需在要buildscript的dependencies中以classpath方式依赖一个Android Library。

AGP的Android Library的默认输出是一个aar包。尽管compileOnly方式依赖可以正常工作,但是classpath方式依赖不行。
所以早先没有时间深究的情况下,选择简单的新建一个普通的Java模块暴露aar中的jar包。

这次改造正常运用了Gradle的Configuration设计,添加了新的Configuration专门暴露jar包。然后classpath处显式指定依赖的configuration即可正常工作。

改造后Android Studio不会再将build目录中的jar包作为单独的jar文件索引了,所有类都可以直接跳转到对应的源码中。
  • Loading branch information
shifujun committed Oct 28, 2021
1 parent c639945 commit 089e026
Show file tree
Hide file tree
Showing 26 changed files with 51 additions and 97 deletions.
4 changes: 2 additions & 2 deletions projects/sample/source/sample-manager/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,6 @@ dependencies {
implementation 'com.tencent.shadow.dynamic:dynamic-loader'
implementation project(':sample-constant')

compileOnly 'com.tencent.shadow.core:common-debug'
compileOnly 'com.tencent.shadow.dynamic:dynamic-host-debug'
compileOnly 'com.tencent.shadow.core:common'
compileOnly 'com.tencent.shadow.dynamic:dynamic-host'
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ dependencies {
implementation 'com.tencent.shadow.dynamic:dynamic-loader-impl'
implementation project(':sample-constant')

compileOnly 'com.tencent.shadow.core:runtime-debug'
compileOnly 'com.tencent.shadow.core:activity-container-debug'
compileOnly 'com.tencent.shadow.core:common-debug'
compileOnly 'com.tencent.shadow.core:runtime'
compileOnly 'com.tencent.shadow.core:activity-container'
compileOnly 'com.tencent.shadow.core:common'
//下面这行依赖是为了防止在proguard的时候找不到LoaderFactory接口
compileOnly 'com.tencent.shadow.dynamic:dynamic-host-debug'
compileOnly 'com.tencent.shadow.dynamic:dynamic-host'

compileOnly files("${project(":sample-host-lib").getBuildDir()}/outputs/jar/sample-host-lib-debug.jar")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ android {
dependencies {
//Shadow Transform后业务代码会有一部分实际引用runtime中的类
//如果不以compileOnly方式依赖,会导致其他Transform或者Proguard找不到这些类
compileOnly 'com.tencent.shadow.core:runtime-debug'
compileOnly 'com.tencent.shadow.core:runtime'
}

buildscript {
Expand All @@ -23,8 +23,8 @@ buildscript {
}

dependencies {
classpath 'com.tencent.shadow.core:runtime-debug'
classpath 'com.tencent.shadow.core:activity-container-debug'
classpath group: 'com.tencent.shadow.core', name: 'runtime', configuration: 'jar-debug'
classpath group: 'com.tencent.shadow.core', name: 'activity-container', configuration: 'jar-debug'
classpath 'com.tencent.shadow.core:gradle-plugin'
classpath 'org.javassist:javassist:3.28.0-GA'
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ class AarToJarPlugin : Plugin<Project> {
project.afterEvaluate {
val android = it.extensions.getByName("android") as BaseExtension
android.buildTypes.forEach { buildType ->
createJarPackageTask(project, buildType.name)
val createJarPackageTask = createJarPackageTask(project, buildType.name)
addJarConfiguration(project, buildType.name, createJarPackageTask)
}
}
}
Expand Down Expand Up @@ -59,4 +60,21 @@ class AarToJarPlugin : Plugin<Project> {
).first()
)
}

/**
* 添加一个额外的Configuration,用于buildScript中以classpath方式依赖
*/
private fun addJarConfiguration(
project: Project,
buildType: String,
createJarPackageTask: Task
) {
val configurationName = "jar-${buildType}"
val jarFile =
project.file(project.buildDir.path + "/outputs/jar/${project.name}-${buildType}.jar")
project.configurations.create(configurationName)
project.artifacts.add(configurationName, jarFile) {
it.builtBy(createJarPackageTask)
}
}
}

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

1 change: 0 additions & 1 deletion projects/sdk/core/jar-wrapper/common-debug/.gitignore

This file was deleted.

9 changes: 0 additions & 9 deletions projects/sdk/core/jar-wrapper/common-debug/build.gradle

This file was deleted.

1 change: 0 additions & 1 deletion projects/sdk/core/jar-wrapper/common-realse/.gitignore

This file was deleted.

9 changes: 0 additions & 9 deletions projects/sdk/core/jar-wrapper/common-realse/build.gradle

This file was deleted.

1 change: 0 additions & 1 deletion projects/sdk/core/jar-wrapper/runtime-debug/.gitignore

This file was deleted.

9 changes: 0 additions & 9 deletions projects/sdk/core/jar-wrapper/runtime-debug/build.gradle

This file was deleted.

1 change: 0 additions & 1 deletion projects/sdk/core/jar-wrapper/runtime-release/.gitignore

This file was deleted.

9 changes: 0 additions & 9 deletions projects/sdk/core/jar-wrapper/runtime-release/build.gradle

This file was deleted.

5 changes: 1 addition & 4 deletions projects/sdk/core/settings.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
includeBuild '../coding'
include 'generate-delegate-code', 'loader', 'runtime', 'activity-container', 'transform', 'gradle-plugin', 'common', 'manager', 'load-parameters', 'transform-kit'
include 'utils'
include ':jar-wrapper:runtime-debug', ':jar-wrapper:runtime-release'
include ':jar-wrapper:activity-container-debug', ':jar-wrapper:activity-container-release'
include ':jar-wrapper:common-debug', ':jar-wrapper:common-realse'
include 'utils'
3 changes: 1 addition & 2 deletions projects/sdk/dynamic/settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,4 @@ include 'dynamic-manager',
'dynamic-loader',
'dynamic-loader-impl',
'dynamic-host-multi-loader-ext',
'dynamic-manager-multi-loader-ext'
include ':jar-wrapper:dynamic-host-debug', ':jar-wrapper:dynamic-host-realse'
'dynamic-manager-multi-loader-ext'
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ dependencies {
implementation 'com.tencent.shadow.dynamic:dynamic-loader'
implementation project(':constant')

compileOnly 'com.tencent.shadow.core:common-debug'
compileOnly 'com.tencent.shadow.dynamic:dynamic-host-debug'
compileOnly 'com.tencent.shadow.core:common'
compileOnly 'com.tencent.shadow.dynamic:dynamic-host'
compileOnly project(':test-manager')
}
8 changes: 4 additions & 4 deletions projects/test/dynamic/plugin/test-dynamic-loader/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ dependencies {
implementation 'com.tencent.shadow.dynamic:dynamic-loader-impl'
implementation project(':constant')

compileOnly 'com.tencent.shadow.core:runtime-debug'
compileOnly 'com.tencent.shadow.core:activity-container-debug'
compileOnly 'com.tencent.shadow.core:common-debug'
compileOnly 'com.tencent.shadow.core:runtime'
compileOnly 'com.tencent.shadow.core:activity-container'
compileOnly 'com.tencent.shadow.core:common'
//下面这行依赖是为了防止在proguard的时候找不到LoaderFactory接口
compileOnly 'com.tencent.shadow.dynamic:dynamic-host-debug'
compileOnly 'com.tencent.shadow.dynamic:dynamic-host'
}
2 changes: 1 addition & 1 deletion projects/test/lib/test-manager/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ apply plugin: 'java-library'
group 'com.tencent.shadow.test.lib.test-manager'

dependencies {
compileOnly 'com.tencent.shadow.dynamic:dynamic-host-debug'
compileOnly group: 'com.tencent.shadow.dynamic', name: 'dynamic-host', configuration: 'jar-debug'
}
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ buildscript {
}

dependencies {
classpath 'com.tencent.shadow.core:runtime-debug'
classpath 'com.tencent.shadow.core:activity-container-debug'
classpath group: 'com.tencent.shadow.core', name: 'runtime', configuration: 'jar-debug'
classpath group: 'com.tencent.shadow.core', name: 'activity-container', configuration: 'jar-debug'
classpath 'com.tencent.shadow.core:gradle-plugin'
classpath 'org.javassist:javassist:3.28.0-GA'
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ buildscript {
}

dependencies {
classpath 'com.tencent.shadow.core:runtime-debug'
classpath 'com.tencent.shadow.core:activity-container-debug'
classpath group: 'com.tencent.shadow.core', name: 'runtime', configuration: 'jar-debug'
classpath group: 'com.tencent.shadow.core', name: 'activity-container', configuration: 'jar-debug'
classpath 'com.tencent.shadow.core:gradle-plugin'
classpath 'org.javassist:javassist:3.28.0-GA'
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ apply from: '../apk-module-common.gradle'

dependencies {
implementation 'com.android.support:multidex:1.0.2'
compileOnly 'com.tencent.shadow.core:runtime-debug'
compileOnly 'com.tencent.shadow.core:activity-container-debug'
compileOnly 'com.tencent.shadow.core:runtime'
compileOnly 'com.tencent.shadow.core:activity-container'
}

buildscript {
Expand All @@ -17,8 +17,8 @@ buildscript {
}

dependencies {
classpath 'com.tencent.shadow.core:runtime-debug'
classpath 'com.tencent.shadow.core:activity-container-debug'
classpath group: 'com.tencent.shadow.core', name: 'runtime', configuration: 'jar-debug'
classpath group: 'com.tencent.shadow.core', name: 'activity-container', configuration: 'jar-debug'
classpath 'com.tencent.shadow.core:gradle-plugin'
classpath 'org.javassist:javassist:3.28.0-GA'
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ apply from: '../apk-module-common.gradle'

dependencies {
implementation 'androidx.multidex:multidex:2.0.1'
compileOnly 'com.tencent.shadow.core:runtime-debug'
compileOnly 'com.tencent.shadow.core:activity-container-debug'
compileOnly 'com.tencent.shadow.core:runtime'
compileOnly 'com.tencent.shadow.core:activity-container'
}

buildscript {
Expand All @@ -17,8 +17,8 @@ buildscript {
}

dependencies {
classpath 'com.tencent.shadow.core:runtime-debug'
classpath 'com.tencent.shadow.core:activity-container-debug'
classpath group: 'com.tencent.shadow.core', name: 'runtime', configuration: 'jar-debug'
classpath group: 'com.tencent.shadow.core', name: 'activity-container', configuration: 'jar-debug'
classpath 'com.tencent.shadow.core:gradle-plugin'
classpath 'org.javassist:javassist:3.28.0-GA'
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ buildscript {
}

dependencies {
classpath 'com.tencent.shadow.core:runtime-debug'
classpath 'com.tencent.shadow.core:activity-container-debug'
classpath group: 'com.tencent.shadow.core', name: 'runtime', configuration: 'jar-debug'
classpath group: 'com.tencent.shadow.core', name: 'activity-container', configuration: 'jar-debug'
classpath 'com.tencent.shadow.core:gradle-plugin'
classpath 'org.javassist:javassist:3.28.0-GA'
}
Expand Down

0 comments on commit 089e026

Please sign in to comment.