diff --git a/README.md b/README.md index 2c2f513b2..ade689be3 100644 --- a/README.md +++ b/README.md @@ -32,7 +32,6 @@ Shadow不仅开源分享了插件技术的关键代码,还完整的分享了 ### 环境准备 第一次clone Shadow的代码到本地后,建议先在命令行编译一次。 -* 在编译前,**必须**设置`ANDROID_HOME`环境变量。 * 在编译时,**必须**使用`gradlew`脚本,以保证采用了项目配置的Gradle版本。 在命令行测试编译时可以执行这个任务: diff --git a/buildScripts/gradle/common.gradle b/buildScripts/gradle/common.gradle index 320b90163..be4121941 100644 --- a/buildScripts/gradle/common.gradle +++ b/buildScripts/gradle/common.gradle @@ -37,16 +37,4 @@ allprojects { jcenter() } } - //环境检查 - envCheck() } - - -def envCheck(){ - //优化错误提示,不然会出现代码中找不到android依赖的问题 - def jarFile = file("${System.getenv().get('ANDROID_HOME')}/platforms/android-${project.COMPILE_SDK_VERSION}/android.jar") - - if(!jarFile.exists()){ - throw new RuntimeException("Missing SDK Platform Android,API ${project.COMPILE_SDK_VERSION}。请确保以下文件存在: ${jarFile.absolutePath}") - } -} \ No newline at end of file diff --git a/projects/sdk/coding/code-generator/build.gradle b/projects/sdk/coding/code-generator/build.gradle index cf7a64b5c..25832a4a9 100644 --- a/projects/sdk/coding/code-generator/build.gradle +++ b/projects/sdk/coding/code-generator/build.gradle @@ -8,7 +8,6 @@ dependencies { implementation 'org.javassist:javassist:3.28.0-GA' implementation 'junit:junit:4.12' - def androidJar = files("${System.getenv().get('ANDROID_HOME')}/platforms/android-${project.COMPILE_SDK_VERSION}/android.jar") - compileOnly androidJar - testImplementation androidJar + compileOnly project(path: ":get-android-jar", configuration: 'exportAndroidJar') + testImplementation project(path: ":get-android-jar", configuration: 'exportAndroidJar') } diff --git a/projects/sdk/coding/get-android-jar/.gitignore b/projects/sdk/coding/get-android-jar/.gitignore new file mode 100644 index 000000000..796b96d1c --- /dev/null +++ b/projects/sdk/coding/get-android-jar/.gitignore @@ -0,0 +1 @@ +/build diff --git a/projects/sdk/coding/get-android-jar/build.gradle b/projects/sdk/coding/get-android-jar/build.gradle new file mode 100644 index 000000000..dfa4eab90 --- /dev/null +++ b/projects/sdk/coding/get-android-jar/build.gradle @@ -0,0 +1,18 @@ +apply plugin: 'com.android.library' + +group 'com.tencent.shadow.coding' + +android { + compileSdkVersion project.COMPILE_SDK_VERSION +} + +def sdkPath = android.sdkComponents.getSdkDirectory().get().asFile.absolutePath +def androidJarPath = new File(sdkPath, "platforms/${android.compileSdkVersion}/android.jar") + +configurations { + exportAndroidJar +} + +artifacts { + exportAndroidJar(androidJarPath) +} \ No newline at end of file diff --git a/projects/sdk/coding/get-android-jar/src/main/AndroidManifest.xml b/projects/sdk/coding/get-android-jar/src/main/AndroidManifest.xml new file mode 100644 index 000000000..19fbf212c --- /dev/null +++ b/projects/sdk/coding/get-android-jar/src/main/AndroidManifest.xml @@ -0,0 +1 @@ + diff --git a/projects/sdk/coding/settings.gradle b/projects/sdk/coding/settings.gradle index fd1d65cb0..b9f16dfa0 100644 --- a/projects/sdk/coding/settings.gradle +++ b/projects/sdk/coding/settings.gradle @@ -2,3 +2,4 @@ include 'checks', 'lint' include 'code-generator' include 'aar-to-jar-plugin' include 'common-aar-settings' +include 'get-android-jar' diff --git a/projects/sdk/core/generate-delegate-code/build.gradle b/projects/sdk/core/generate-delegate-code/build.gradle index 4e880e357..a3a337953 100644 --- a/projects/sdk/core/generate-delegate-code/build.gradle +++ b/projects/sdk/core/generate-delegate-code/build.gradle @@ -11,7 +11,7 @@ buildscript { } dependencies { - classpath files("${System.getenv().get('ANDROID_HOME')}/platforms/android-${project.COMPILE_SDK_VERSION}/android.jar") + classpath group: 'com.tencent.shadow.coding', name: 'get-android-jar', configuration: 'exportAndroidJar' classpath 'com.tencent.shadow.coding:code-generator' } } diff --git a/settings.gradle b/settings.gradle index 021ce3d23..3c491ddf6 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,11 +1,5 @@ rootProject.name = 'shadow' -if (!System.getenv().containsKey("ANDROID_HOME")) { - throw new RuntimeException("未定义ANDROID_HOME环境变量。" + - "原因:Android Studio目前不支持自动为复合构建中的子构建自动创建local.properties文件。" + - "注意:新增环境变量后,一般不会立即生效,最简单的办法是重启电脑。") -} - includeBuild 'projects/sdk/coding' includeBuild 'projects/sdk/core' includeBuild 'projects/sdk/dynamic'