From 089e026fbebacdb4dd019662a9b6d8e19d3a698a Mon Sep 17 00:00:00 2001 From: shifujun Date: Thu, 28 Oct 2021 18:57:46 +0800 Subject: [PATCH] =?UTF-8?q?build:=20=E5=8E=BB=E6=8E=89=E6=89=80=E6=9C=89ja?= =?UTF-8?q?r-wrapper=E5=B7=A5=E7=A8=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 这里主要解决的问题是需在要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文件索引了,所有类都可以直接跳转到对应的源码中。 --- .../sample/source/sample-manager/build.gradle | 4 ++-- .../sample-plugin/sample-loader/build.gradle | 8 ++++---- .../sample-plugin-app/build.gradle | 6 +++--- .../aar_to_jar_plugin/AarToJarPlugin.kt | 20 ++++++++++++++++++- .../activity-container-debug/.gitignore | 1 - .../activity-container-debug/build.gradle | 9 --------- .../activity-container-release/.gitignore | 1 - .../activity-container-release/build.gradle | 9 --------- .../core/jar-wrapper/common-debug/.gitignore | 1 - .../jar-wrapper/common-debug/build.gradle | 9 --------- .../core/jar-wrapper/common-realse/.gitignore | 1 - .../jar-wrapper/common-realse/build.gradle | 9 --------- .../core/jar-wrapper/runtime-debug/.gitignore | 1 - .../jar-wrapper/runtime-debug/build.gradle | 9 --------- .../jar-wrapper/runtime-release/.gitignore | 1 - .../jar-wrapper/runtime-release/build.gradle | 9 --------- projects/sdk/core/settings.gradle | 5 +---- projects/sdk/dynamic/settings.gradle | 3 +-- .../manager/test-dynamic-manager/build.gradle | 4 ++-- .../plugin/test-dynamic-loader/build.gradle | 8 ++++---- projects/test/lib/test-manager/build.gradle | 2 +- .../test-plugin-androidx-cases/build.gradle | 4 ++-- .../test-plugin-general-cases/build.gradle | 4 ++-- .../test-plugin-multidex-v1_0_2/build.gradle | 8 ++++---- .../test-plugin-multidex-v2_0_1/build.gradle | 8 ++++---- .../plugin-service-for-host/build.gradle | 4 ++-- 26 files changed, 51 insertions(+), 97 deletions(-) delete mode 100644 projects/sdk/core/jar-wrapper/activity-container-debug/.gitignore delete mode 100644 projects/sdk/core/jar-wrapper/activity-container-debug/build.gradle delete mode 100644 projects/sdk/core/jar-wrapper/activity-container-release/.gitignore delete mode 100644 projects/sdk/core/jar-wrapper/activity-container-release/build.gradle delete mode 100644 projects/sdk/core/jar-wrapper/common-debug/.gitignore delete mode 100644 projects/sdk/core/jar-wrapper/common-debug/build.gradle delete mode 100644 projects/sdk/core/jar-wrapper/common-realse/.gitignore delete mode 100644 projects/sdk/core/jar-wrapper/common-realse/build.gradle delete mode 100644 projects/sdk/core/jar-wrapper/runtime-debug/.gitignore delete mode 100644 projects/sdk/core/jar-wrapper/runtime-debug/build.gradle delete mode 100644 projects/sdk/core/jar-wrapper/runtime-release/.gitignore delete mode 100644 projects/sdk/core/jar-wrapper/runtime-release/build.gradle diff --git a/projects/sample/source/sample-manager/build.gradle b/projects/sample/source/sample-manager/build.gradle index 81baf7b07..6b2b7095e 100644 --- a/projects/sample/source/sample-manager/build.gradle +++ b/projects/sample/source/sample-manager/build.gradle @@ -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' } diff --git a/projects/sample/source/sample-plugin/sample-loader/build.gradle b/projects/sample/source/sample-plugin/sample-loader/build.gradle index 11bbb4d40..e9026ca25 100644 --- a/projects/sample/source/sample-plugin/sample-loader/build.gradle +++ b/projects/sample/source/sample-plugin/sample-loader/build.gradle @@ -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") } diff --git a/projects/sample/source/sample-plugin/sample-plugin-app/build.gradle b/projects/sample/source/sample-plugin/sample-plugin-app/build.gradle index 0de7f8b31..2b5ae0a50 100644 --- a/projects/sample/source/sample-plugin/sample-plugin-app/build.gradle +++ b/projects/sample/source/sample-plugin/sample-plugin-app/build.gradle @@ -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 { @@ -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' } diff --git a/projects/sdk/coding/aar-to-jar-plugin/src/main/kotlin/com/tencent/shadow/coding/aar_to_jar_plugin/AarToJarPlugin.kt b/projects/sdk/coding/aar-to-jar-plugin/src/main/kotlin/com/tencent/shadow/coding/aar_to_jar_plugin/AarToJarPlugin.kt index 3748ee7ec..ce8ae4a1d 100644 --- a/projects/sdk/coding/aar-to-jar-plugin/src/main/kotlin/com/tencent/shadow/coding/aar_to_jar_plugin/AarToJarPlugin.kt +++ b/projects/sdk/coding/aar-to-jar-plugin/src/main/kotlin/com/tencent/shadow/coding/aar_to_jar_plugin/AarToJarPlugin.kt @@ -31,7 +31,8 @@ class AarToJarPlugin : Plugin { 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) } } } @@ -59,4 +60,21 @@ class AarToJarPlugin : Plugin { ).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) + } + } } \ No newline at end of file diff --git a/projects/sdk/core/jar-wrapper/activity-container-debug/.gitignore b/projects/sdk/core/jar-wrapper/activity-container-debug/.gitignore deleted file mode 100644 index 796b96d1c..000000000 --- a/projects/sdk/core/jar-wrapper/activity-container-debug/.gitignore +++ /dev/null @@ -1 +0,0 @@ -/build diff --git a/projects/sdk/core/jar-wrapper/activity-container-debug/build.gradle b/projects/sdk/core/jar-wrapper/activity-container-debug/build.gradle deleted file mode 100644 index d7a123355..000000000 --- a/projects/sdk/core/jar-wrapper/activity-container-debug/build.gradle +++ /dev/null @@ -1,9 +0,0 @@ -apply plugin: 'java-library' - -group 'com.tencent.shadow.core' - -dependencies { - api files("${project(":activity-container").getBuildDir()}/outputs/jar/activity-container-debug.jar") -} - -compileJava.dependsOn(":activity-container:jarDebugPackage") \ No newline at end of file diff --git a/projects/sdk/core/jar-wrapper/activity-container-release/.gitignore b/projects/sdk/core/jar-wrapper/activity-container-release/.gitignore deleted file mode 100644 index 796b96d1c..000000000 --- a/projects/sdk/core/jar-wrapper/activity-container-release/.gitignore +++ /dev/null @@ -1 +0,0 @@ -/build diff --git a/projects/sdk/core/jar-wrapper/activity-container-release/build.gradle b/projects/sdk/core/jar-wrapper/activity-container-release/build.gradle deleted file mode 100644 index 733546c5f..000000000 --- a/projects/sdk/core/jar-wrapper/activity-container-release/build.gradle +++ /dev/null @@ -1,9 +0,0 @@ -apply plugin: 'java-library' - -group 'com.tencent.shadow.core' - -dependencies { - api files("${project(":activity-container").getBuildDir()}/outputs/jar/activity-container-release.jar") -} - -compileJava.dependsOn(":activity-container:jarReleasePackage") \ No newline at end of file diff --git a/projects/sdk/core/jar-wrapper/common-debug/.gitignore b/projects/sdk/core/jar-wrapper/common-debug/.gitignore deleted file mode 100644 index 796b96d1c..000000000 --- a/projects/sdk/core/jar-wrapper/common-debug/.gitignore +++ /dev/null @@ -1 +0,0 @@ -/build diff --git a/projects/sdk/core/jar-wrapper/common-debug/build.gradle b/projects/sdk/core/jar-wrapper/common-debug/build.gradle deleted file mode 100644 index dee19805c..000000000 --- a/projects/sdk/core/jar-wrapper/common-debug/build.gradle +++ /dev/null @@ -1,9 +0,0 @@ -apply plugin: 'java-library' - -group 'com.tencent.shadow.core' - -dependencies { - api files("${project(":common").getBuildDir()}/outputs/jar/common-debug.jar") -} - -compileJava.dependsOn(":common:jarDebugPackage") \ No newline at end of file diff --git a/projects/sdk/core/jar-wrapper/common-realse/.gitignore b/projects/sdk/core/jar-wrapper/common-realse/.gitignore deleted file mode 100644 index 796b96d1c..000000000 --- a/projects/sdk/core/jar-wrapper/common-realse/.gitignore +++ /dev/null @@ -1 +0,0 @@ -/build diff --git a/projects/sdk/core/jar-wrapper/common-realse/build.gradle b/projects/sdk/core/jar-wrapper/common-realse/build.gradle deleted file mode 100644 index 60b5117a7..000000000 --- a/projects/sdk/core/jar-wrapper/common-realse/build.gradle +++ /dev/null @@ -1,9 +0,0 @@ -apply plugin: 'java-library' - -group 'com.tencent.shadow.core' - -dependencies { - api files("${project(":common").getBuildDir()}/outputs/jar/common-release.jar") -} - -compileJava.dependsOn(":common:jarReleasePackage") \ No newline at end of file diff --git a/projects/sdk/core/jar-wrapper/runtime-debug/.gitignore b/projects/sdk/core/jar-wrapper/runtime-debug/.gitignore deleted file mode 100644 index 796b96d1c..000000000 --- a/projects/sdk/core/jar-wrapper/runtime-debug/.gitignore +++ /dev/null @@ -1 +0,0 @@ -/build diff --git a/projects/sdk/core/jar-wrapper/runtime-debug/build.gradle b/projects/sdk/core/jar-wrapper/runtime-debug/build.gradle deleted file mode 100644 index 54a985156..000000000 --- a/projects/sdk/core/jar-wrapper/runtime-debug/build.gradle +++ /dev/null @@ -1,9 +0,0 @@ -apply plugin: 'java-library' - -group 'com.tencent.shadow.core' - -dependencies { - api files("${project(":runtime").getBuildDir()}/outputs/jar/runtime-debug.jar") -} - -compileJava.dependsOn(":runtime:jarDebugPackage") \ No newline at end of file diff --git a/projects/sdk/core/jar-wrapper/runtime-release/.gitignore b/projects/sdk/core/jar-wrapper/runtime-release/.gitignore deleted file mode 100644 index 796b96d1c..000000000 --- a/projects/sdk/core/jar-wrapper/runtime-release/.gitignore +++ /dev/null @@ -1 +0,0 @@ -/build diff --git a/projects/sdk/core/jar-wrapper/runtime-release/build.gradle b/projects/sdk/core/jar-wrapper/runtime-release/build.gradle deleted file mode 100644 index e32f5145f..000000000 --- a/projects/sdk/core/jar-wrapper/runtime-release/build.gradle +++ /dev/null @@ -1,9 +0,0 @@ -apply plugin: 'java-library' - -group 'com.tencent.shadow.core' - -dependencies { - api files("${project(":runtime").getBuildDir()}/outputs/jar/runtime-release.jar") -} - -compileJava.dependsOn(":runtime:jarReleasePackage") \ No newline at end of file diff --git a/projects/sdk/core/settings.gradle b/projects/sdk/core/settings.gradle index 81015996c..3b14a53c6 100644 --- a/projects/sdk/core/settings.gradle +++ b/projects/sdk/core/settings.gradle @@ -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' \ No newline at end of file +include 'utils' \ No newline at end of file diff --git a/projects/sdk/dynamic/settings.gradle b/projects/sdk/dynamic/settings.gradle index c22cfd07e..f38d00eb8 100644 --- a/projects/sdk/dynamic/settings.gradle +++ b/projects/sdk/dynamic/settings.gradle @@ -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' \ No newline at end of file + 'dynamic-manager-multi-loader-ext' \ No newline at end of file diff --git a/projects/test/dynamic/manager/test-dynamic-manager/build.gradle b/projects/test/dynamic/manager/test-dynamic-manager/build.gradle index 750dbc648..5b8e9448a 100644 --- a/projects/test/dynamic/manager/test-dynamic-manager/build.gradle +++ b/projects/test/dynamic/manager/test-dynamic-manager/build.gradle @@ -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') } diff --git a/projects/test/dynamic/plugin/test-dynamic-loader/build.gradle b/projects/test/dynamic/plugin/test-dynamic-loader/build.gradle index 989c770a6..47f01d3bb 100644 --- a/projects/test/dynamic/plugin/test-dynamic-loader/build.gradle +++ b/projects/test/dynamic/plugin/test-dynamic-loader/build.gradle @@ -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' } diff --git a/projects/test/lib/test-manager/build.gradle b/projects/test/lib/test-manager/build.gradle index dee499a75..8729ed52a 100644 --- a/projects/test/lib/test-manager/build.gradle +++ b/projects/test/lib/test-manager/build.gradle @@ -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 diff --git a/projects/test/plugin/androidx-cases/test-plugin-androidx-cases/build.gradle b/projects/test/plugin/androidx-cases/test-plugin-androidx-cases/build.gradle index d7903afa7..520eabf3e 100644 --- a/projects/test/plugin/androidx-cases/test-plugin-androidx-cases/build.gradle +++ b/projects/test/plugin/androidx-cases/test-plugin-androidx-cases/build.gradle @@ -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' } diff --git a/projects/test/plugin/general-cases/test-plugin-general-cases/build.gradle b/projects/test/plugin/general-cases/test-plugin-general-cases/build.gradle index 718988127..198faa788 100644 --- a/projects/test/plugin/general-cases/test-plugin-general-cases/build.gradle +++ b/projects/test/plugin/general-cases/test-plugin-general-cases/build.gradle @@ -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' } diff --git a/projects/test/plugin/particular-cases/multidex/test-plugin-multidex-v1_0_2/build.gradle b/projects/test/plugin/particular-cases/multidex/test-plugin-multidex-v1_0_2/build.gradle index ef686ae82..fc1a7b857 100644 --- a/projects/test/plugin/particular-cases/multidex/test-plugin-multidex-v1_0_2/build.gradle +++ b/projects/test/plugin/particular-cases/multidex/test-plugin-multidex-v1_0_2/build.gradle @@ -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 { @@ -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' } diff --git a/projects/test/plugin/particular-cases/multidex/test-plugin-multidex-v2_0_1/build.gradle b/projects/test/plugin/particular-cases/multidex/test-plugin-multidex-v2_0_1/build.gradle index 39c64b962..9cae7d86a 100644 --- a/projects/test/plugin/particular-cases/multidex/test-plugin-multidex-v2_0_1/build.gradle +++ b/projects/test/plugin/particular-cases/multidex/test-plugin-multidex-v2_0_1/build.gradle @@ -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 { @@ -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' } diff --git a/projects/test/plugin/particular-cases/plugin-service-for-host/build.gradle b/projects/test/plugin/particular-cases/plugin-service-for-host/build.gradle index c6ca30e71..de38b4bad 100644 --- a/projects/test/plugin/particular-cases/plugin-service-for-host/build.gradle +++ b/projects/test/plugin/particular-cases/plugin-service-for-host/build.gradle @@ -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' }