Skip to content

Commit

Permalink
build: 去掉对ANDROID_HOME环境变量的依赖
Browse files Browse the repository at this point in the history
通过get-android-jar模块自定义配置导出android.jar的路径。
  • Loading branch information
shifujun committed Nov 16, 2021
1 parent d27e984 commit f80ece3
Show file tree
Hide file tree
Showing 9 changed files with 24 additions and 23 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ Shadow不仅开源分享了插件技术的关键代码,还完整的分享了
### 环境准备
第一次clone Shadow的代码到本地后,建议先在命令行编译一次。

* 在编译前,**必须**设置`ANDROID_HOME`环境变量。
* 在编译时,**必须**使用`gradlew`脚本,以保证采用了项目配置的Gradle版本。

在命令行测试编译时可以执行这个任务:
Expand Down
12 changes: 0 additions & 12 deletions buildScripts/gradle/common.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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}")
}
}
5 changes: 2 additions & 3 deletions projects/sdk/coding/code-generator/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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')
}
1 change: 1 addition & 0 deletions projects/sdk/coding/get-android-jar/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
18 changes: 18 additions & 0 deletions projects/sdk/coding/get-android-jar/build.gradle
Original file line number Diff line number Diff line change
@@ -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)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<manifest package="com.tencent.shadow.coding.get_android_jar" />
1 change: 1 addition & 0 deletions projects/sdk/coding/settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ include 'checks', 'lint'
include 'code-generator'
include 'aar-to-jar-plugin'
include 'common-aar-settings'
include 'get-android-jar'
2 changes: 1 addition & 1 deletion projects/sdk/core/generate-delegate-code/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}
}
Expand Down
6 changes: 0 additions & 6 deletions settings.gradle
Original file line number Diff line number Diff line change
@@ -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'
Expand Down

0 comments on commit f80ece3

Please sign in to comment.