Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(core): 支持AGP 8.0+所需的新版Transform API #1262

Merged
merged 3 commits into from
Dec 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 17 additions & 4 deletions .github/workflows/pr-check-gradle-plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,26 @@ jobs:
restore-keys: |
${{ runner.os }}-gradle-
- name: revert gradle wrapper mirror setting
run: echo 'distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-bin.zip' > gradle/wrapper/gradle-wrapper.properties
run: echo 'distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-bin.zip' > gradle/wrapper/gradle-wrapper.properties
- name: revert gradle wrapper mirror setting
working-directory: projects/test/gradle-plugin-agp-compat-test
run: echo 'distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-bin.zip' > gradle/wrapper/gradle-wrapper.properties
- name: test AGP compatibility when core.gradle-plugin changed
run: echo 'distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-bin.zip' > gradle/wrapper/gradle-wrapper.properties
- uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: '17'
cache: 'gradle'
- name: test AGP compatibility when core.gradle-plugin changed with JDK17
working-directory: projects/test/gradle-plugin-agp-compat-test
run: ./test_JDK17.sh
- uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: '11'
cache: 'gradle'
- name: test AGP compatibility when core.gradle-plugin changed with JDK11
working-directory: projects/test/gradle-plugin-agp-compat-test
run: ./test.sh
run: ./test_JDK11.sh

- name: stop gradle deamon for actions/cache
run: ./gradlew --stop
14 changes: 7 additions & 7 deletions .github/workflows/pr-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ jobs:
uses: rlespinasse/[email protected]
- name: checkout
uses: actions/checkout@v2
- uses: actions/setup-java@v2
- uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: '11'
java-version: '17'
cache: 'gradle'
- uses: actions/cache@v2
with:
Expand All @@ -37,7 +37,7 @@ jobs:
restore-keys: |
${{ runner.os }}-gradle-
- name: revert gradle wrapper mirror setting
run: echo 'distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-bin.zip' > gradle/wrapper/gradle-wrapper.properties
run: echo 'distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-bin.zip' > gradle/wrapper/gradle-wrapper.properties
- name: buildSdk
run: ./gradlew buildSdk -S
- name: build sample/source
Expand All @@ -64,10 +64,10 @@ jobs:
uses: rlespinasse/[email protected]
- name: checkout
uses: actions/checkout@v2
- uses: actions/setup-java@v2
- uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: '11'
java-version: '17'
cache: 'gradle'
- uses: actions/cache@v2
with:
Expand All @@ -78,7 +78,7 @@ jobs:
restore-keys: |
${{ runner.os }}-gradle-
- name: revert gradle wrapper mirror setting
run: echo 'distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-bin.zip' > gradle/wrapper/gradle-wrapper.properties
run: echo 'distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-bin.zip' > gradle/wrapper/gradle-wrapper.properties
- name: buildSdk
run: ./gradlew buildSdk -S
- name: build sample/source
Expand All @@ -103,7 +103,7 @@ jobs:
restore-keys: |
${{ runner.os }}-gradle-
- name: revert gradle wrapper mirror setting
run: echo 'distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-bin.zip' > gradle/wrapper/gradle-wrapper.properties
run: echo 'distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-bin.zip' > gradle/wrapper/gradle-wrapper.properties
- name: revert gradle wrapper mirror setting for sample host-project
working-directory: projects/sample/maven/host-project
run: echo 'distributionUrl=https\://services.gradle.org/distributions/gradle-6.6.1-bin.zip' > gradle/wrapper/gradle-wrapper.properties
Expand Down
12 changes: 6 additions & 6 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ jobs:
uses: rlespinasse/[email protected]
- name: checkout
uses: actions/checkout@v2
- uses: actions/setup-java@v2
- uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: '11'
java-version: '17'
cache: 'gradle'
- uses: actions/cache@v2
with:
Expand All @@ -29,7 +29,7 @@ jobs:
restore-keys: |
${{ runner.os }}-gradle-
- name: revert gradle wrapper mirror setting
run: echo 'distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-bin.zip' > gradle/wrapper/gradle-wrapper.properties
run: echo 'distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-bin.zip' > gradle/wrapper/gradle-wrapper.properties
- name: buildSdk
run: ./gradlew buildSdk
- name: build sample/source
Expand Down Expand Up @@ -59,10 +59,10 @@ jobs:
uses: rlespinasse/[email protected]
- name: checkout
uses: actions/checkout@v2
- uses: actions/setup-java@v2
- uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: '11'
java-version: '17'
cache: 'gradle'
- uses: actions/cache@v2
with:
Expand All @@ -73,7 +73,7 @@ jobs:
restore-keys: |
${{ runner.os }}-gradle-
- name: revert gradle wrapper mirror setting
run: echo 'distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-bin.zip' > gradle/wrapper/gradle-wrapper.properties
run: echo 'distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-bin.zip' > gradle/wrapper/gradle-wrapper.properties
- name: publish
run: ./gradlew publish
- name: stop gradle deamon for actions/cache
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/test-avd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ jobs:
uses: rlespinasse/[email protected]
- name: checkout
uses: actions/checkout@v2
- uses: actions/setup-java@v2
- uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: '11'
java-version: '17'
cache: 'gradle'
- uses: actions/cache@v2
with:
Expand All @@ -33,7 +33,7 @@ jobs:
restore-keys: |
${{ runner.os }}-gradle-
- name: revert gradle wrapper mirror setting
run: echo 'distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-bin.zip' > gradle/wrapper/gradle-wrapper.properties
run: echo 'distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-bin.zip' > gradle/wrapper/gradle-wrapper.properties
- name: buildSdk
run: ./gradlew buildSdk -S
- name: build sample/source
Expand Down
3 changes: 2 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ buildscript {
def versions_properties_path = 'buildScripts/gradle/versions.properties'
def versions = new Properties()
versions.load(file(versions_properties_path).newReader())
versions.forEach { key, value ->
versions.forEach { key, stringValue ->
def value = stringValue?.isInteger() ? stringValue as Integer : stringValue
ext.set(key, value)
}
}
Expand Down
18 changes: 7 additions & 11 deletions buildScripts/gradle/common.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,21 @@ def gitShortRev() {
}

allprojects {
ext.COMPILE_SDK_VERSION = 31
ext.MIN_SDK_VERSION = 14
ext.TARGET_SDK_VERSION = 28
ext.VERSION_CODE = 1

def versionName, versionSuffix
if ("${System.env.CI}".equalsIgnoreCase("true")) {
ext.VERSION_NAME = System.getenv("GITHUB_REF_SLUG")
versionName = System.getenv("GITHUB_REF_SLUG")
} else {
ext.VERSION_NAME = "local"
versionName = project.VERSION_NAME
}

if ("${System.env.PUBLISH_RELEASE}".equalsIgnoreCase("true")) {
ext.VERSION_SUFFIX = ""
versionSuffix = ""
} else if ("${System.env.CI}".equalsIgnoreCase("true")) {
ext.VERSION_SUFFIX = "-${System.env.GITHUB_SHA_SHORT}-SNAPSHOT"
versionSuffix = "-${System.env.GITHUB_SHA_SHORT}-SNAPSHOT"
} else {
ext.VERSION_SUFFIX = "-${gitShortRev()}-SNAPSHOT"
versionSuffix = "-${gitShortRev()}-SNAPSHOT"
}
ext.ARTIFACT_VERSION = ext.VERSION_NAME + ext.VERSION_SUFFIX
ext.ARTIFACT_VERSION = versionName + versionSuffix
ext.TEST_HOST_APP_APPLICATION_ID = 'com.tencent.shadow.test.hostapp'
ext.SAMPLE_HOST_APP_APPLICATION_ID = 'com.tencent.shadow.sample.host'
repositories {
Expand Down
7 changes: 6 additions & 1 deletion buildScripts/gradle/versions.properties
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
COMPILE_SDK_VERSION=31
MIN_SDK_VERSION=14
TARGET_SDK_VERSION=28
VERSION_CODE=1
VERSION_NAME=local
android_build_tools_version=30.0.3
android_support_annotations_version=28.0.0
android_support_version=27.1.1
androidx_activity_version=1.4.0
androidx_appcompat_version=1.4.1
androidx_test_junit_version=1.1.2
androidx_test_version=1.3.0
build_gradle_version=7.0.3
build_gradle_version=7.4.2
commons_io_android_version=2.5
commons_io_jvm_version=2.9.0
espresso_version=3.3.0
Expand Down
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
#distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-bin.zip
distributionUrl=https\://mirrors.tencent.com/gradle/gradle-7.0.2-bin.zip
#distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-bin.zip
distributionUrl=https\://mirrors.tencent.com/gradle/gradle-7.5-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,10 @@ android {


defaultConfig {
//noinspection MinSdkTooLow
minSdkVersion 8
//noinspection ExpiredTargetSdkVersion
targetSdkVersion 15
versionCode 1
versionName "1.0"
minSdkVersion project.MIN_SDK_VERSION
targetSdkVersion project.TARGET_SDK_VERSION
versionCode project.VERSION_CODE
versionName project.VERSION_NAME

testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,10 @@ android {


defaultConfig {
//noinspection MinSdkTooLow
minSdkVersion 5
//noinspection ExpiredTargetSdkVersion
targetSdkVersion 17
versionCode 1
versionName "1.0"
minSdkVersion project.MIN_SDK_VERSION
targetSdkVersion project.TARGET_SDK_VERSION
versionCode project.VERSION_CODE
versionName project.VERSION_NAME

testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

Expand Down
3 changes: 2 additions & 1 deletion projects/sdk/coding/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ buildscript {
def versions_properties_path = '../../../buildScripts/gradle/versions.properties'
def versions = new Properties()
versions.load(file(versions_properties_path).newReader())
versions.forEach { key, value ->
versions.forEach { key, stringValue ->
def value = stringValue?.isInteger() ? stringValue as Integer : stringValue
ext.set(key, value)
}
}
Expand Down
12 changes: 12 additions & 0 deletions projects/sdk/coding/code-generator/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,15 @@ dependencies {
compileOnly project(':android-jar')
testImplementation project(':android-jar')
}

compileKotlin {
kotlinOptions {
jvmTarget = "1.6"
}
}

compileTestKotlin {
kotlinOptions {
jvmTarget = "1.6"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,16 @@ import android.content.ComponentCallbacks2
import android.view.ContextThemeWrapper
import android.view.KeyEvent
import android.view.Window
import com.squareup.javapoet.*
import com.squareup.javapoet.AnnotationSpec
import com.squareup.javapoet.ClassName
import com.squareup.javapoet.CodeBlock
import com.squareup.javapoet.JavaFile
import com.squareup.javapoet.MethodSpec
import com.squareup.javapoet.ParameterSpec
import com.squareup.javapoet.TypeName
import com.squareup.javapoet.TypeSpec
import com.squareup.javapoet.TypeVariableName
import com.tencent.shadow.core.runtime.NeighborClass
import javassist.ClassMap
import javassist.ClassPool
import javassist.LoaderClassPath
Expand Down Expand Up @@ -82,7 +91,8 @@ class ActivityCodeGenerator {
val cl = Thread.currentThread().contextClassLoader
classPool.appendClassPath(LoaderClassPath(cl))
}
classPool.makeClass("$RUNTIME_PACKAGE.ShadowApplication").toClass()
classPool.makeClass("$RUNTIME_PACKAGE.ShadowApplication")
.toClass(NeighborClass::class.java)
}

val ActivityClass = Activity::class.java
Expand Down Expand Up @@ -115,7 +125,7 @@ class ActivityCodeGenerator {
}

ctClass.replaceClassName(renameMap)
return ctClass.toClass()
return ctClass.toClass(NeighborClass::class.java)
}

fun getActivityMethods(clazz: Class<*>): List<Method> {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.tencent.shadow.core.runtime

/**
* 为了兼容JDK 17和javassist
* https://github.com/jboss-javassist/javassist/issues/369
*/
class NeighborClass
2 changes: 1 addition & 1 deletion projects/sdk/coding/get-android-jar/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ android {
compileSdkVersion project.COMPILE_SDK_VERSION
}

def sdkPath = android.sdkComponents.getSdkDirectory().get().asFile.absolutePath
def sdkPath = android.sdkDirectory
def androidJarPath = new File(sdkPath, "platforms/${android.compileSdkVersion}/android.jar")

if (!androidJarPath.exists()) {
Expand Down
4 changes: 2 additions & 2 deletions projects/sdk/coding/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
#distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-bin.zip
distributionUrl=https\://mirrors.tencent.com/gradle/gradle-7.0.2-bin.zip
#distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-bin.zip
distributionUrl=https\://mirrors.tencent.com/gradle/gradle-7.5-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
3 changes: 2 additions & 1 deletion projects/sdk/core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ buildscript {
def versions_properties_path = '../../../buildScripts/gradle/versions.properties'
def versions = new Properties()
versions.load(file(versions_properties_path).newReader())
versions.forEach { key, value ->
versions.forEach { key, stringValue ->
def value = stringValue?.isInteger() ? stringValue as Integer : stringValue
ext.set(key, value)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,5 @@ internal interface AGPCompat {
fun getProcessResourcesTask(output: BaseVariantOutput): Task
fun getAaptAdditionalParameters(processResourcesTask: Task): List<String>
fun getMinSdkVersion(pluginVariant: ApplicationVariant): Int
fun hasDeprecatedTransformApi(): Boolean
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,20 @@ internal class AGPCompatImpl : AGPCompat {
return mergedFlavor.minSdkVersion?.apiLevel ?: VersionCodes.BASE
}

override fun hasDeprecatedTransformApi(): Boolean {
try {
val version = com.android.Version.ANDROID_GRADLE_PLUGIN_VERSION
val majorVersion = version.substringBefore('.', "0").toInt()
if (majorVersion >= 8) {
return false//能parse出来主版本号大于等于8,我们就认为旧版Transform API不可用了。
}
} catch (ignored: Error) {
}

//读取版本号失败,就推测是旧版本的AGP,就应该有旧版本的Transform API
return true
}

companion object {
fun getStringFromProperty(x: Any?): String {
return when (x) {
Expand Down
Loading
Loading