-
Notifications
You must be signed in to change notification settings - Fork 464
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #47 from bytedance/yangzhiqian/master
merge internal:optimize hook proguard、improve compatibility、add checkIncrementalInDebug、fix npe cased by refer-checker
- Loading branch information
Showing
45 changed files
with
554 additions
and
311 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
apply plugin: 'java' | ||
group "$upload_group" | ||
version "$upload_version" | ||
apply from: rootProject.file('gradle/publish.gradle') | ||
dependencies { | ||
compileOnly gradleApi() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
ARTIFACT_GROUP=com.bytedance.android.byteX | ||
ARTIFACT_NAME=ProguardConfigurationResolver |
27 changes: 27 additions & 0 deletions
27
...com/ss/android/ugc/bytex/proguardconfigurationresolver/ProguardConfigurationResolver.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package com.ss.android.ugc.bytex.proguardconfigurationresolver; | ||
|
||
import org.gradle.api.Project; | ||
import org.gradle.api.Task; | ||
import org.gradle.api.file.FileCollection; | ||
|
||
import javax.annotation.Nullable; | ||
|
||
/** | ||
* Created by yangzhiqian on 2020/7/6<br/> | ||
*/ | ||
public abstract class ProguardConfigurationResolver { | ||
protected Project project; | ||
protected String variantName; | ||
|
||
public ProguardConfigurationResolver(Project project, String variantName) { | ||
this.project = project; | ||
this.variantName = variantName; | ||
} | ||
|
||
@Nullable | ||
public abstract Task getTask(); | ||
|
||
@Nullable | ||
public abstract FileCollection getAllConfigurationFiles(); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/build |
11 changes: 11 additions & 0 deletions
11
HookProguard/ProguardConfigurationResolver/task/build.gradle
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
apply plugin: 'java' | ||
group "$upload_group" | ||
version "$upload_version" | ||
|
||
dependencies { | ||
compileOnly gradleApi() | ||
compileOnly "com.android.tools.build:gradle:3.6.2" | ||
implementation project(":ProguardConfigurationResolver") | ||
} | ||
|
||
apply from: rootProject.file('gradle/publish.gradle') |
2 changes: 2 additions & 0 deletions
2
HookProguard/ProguardConfigurationResolver/task/gradle.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
ARTIFACT_GROUP=com.bytedance.android.byteX | ||
ARTIFACT_NAME=ProguardConfigurationResolver-task |
40 changes: 40 additions & 0 deletions
40
...ndroid/ugc/bytex/proguardconfigurationresolver/task/ProguardConfigurableTaskResolver.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package com.ss.android.ugc.bytex.proguardconfigurationresolver.task; | ||
|
||
import com.android.build.gradle.internal.tasks.ProguardConfigurableTask; | ||
import com.android.build.gradle.internal.tasks.ProguardTask; | ||
import com.android.build.gradle.internal.tasks.R8Task; | ||
import com.ss.android.ugc.bytex.proguardconfigurationresolver.ProguardConfigurationResolver; | ||
|
||
import org.gradle.api.Project; | ||
import org.gradle.api.Task; | ||
import org.gradle.api.file.FileCollection; | ||
|
||
/** | ||
* Created by yangzhiqian on 2020/7/6<br/> | ||
*/ | ||
public class ProguardConfigurableTaskResolver extends ProguardConfigurationResolver { | ||
|
||
public ProguardConfigurableTaskResolver(Project project, String variantName) { | ||
super(project, variantName); | ||
} | ||
|
||
@Override | ||
public Task getTask() { | ||
for (Task task : project.getTasks()) { | ||
if ((task instanceof ProguardTask || task instanceof R8Task) && | ||
((ProguardConfigurableTask) task).getVariantName().equals(variantName)) { | ||
return task; | ||
} | ||
} | ||
return null; | ||
} | ||
|
||
@Override | ||
public FileCollection getAllConfigurationFiles() { | ||
Task task = getTask(); | ||
if (task == null) { | ||
return null; | ||
} | ||
return ((ProguardConfigurableTask) getTask()).getConfigurationFiles(); | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
HookProguard/ProguardConfigurationResolver/transform/.gitignore
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/build |
11 changes: 11 additions & 0 deletions
11
HookProguard/ProguardConfigurationResolver/transform/build.gradle
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
apply plugin: 'java' | ||
group "$upload_group" | ||
version "$upload_version" | ||
|
||
dependencies { | ||
compileOnly gradleApi() | ||
compileOnly "com.android.tools.build:gradle:3.5.3" | ||
implementation project(":ProguardConfigurationResolver") | ||
} | ||
|
||
apply from: rootProject.file('gradle/publish.gradle') |
2 changes: 2 additions & 0 deletions
2
HookProguard/ProguardConfigurationResolver/transform/gradle.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
ARTIFACT_GROUP=com.bytedance.android.byteX | ||
ARTIFACT_NAME=ProguardConfigurationResolver-transform |
53 changes: 53 additions & 0 deletions
53
.../bytex/proguardconfigurationresolver/transform/ProguardConfigurableTransformResolver.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package com.ss.android.ugc.bytex.proguardconfigurationresolver.transform; | ||
|
||
import com.android.build.gradle.internal.pipeline.TransformTask; | ||
import com.android.build.gradle.internal.transforms.ProguardConfigurable; | ||
import com.ss.android.ugc.bytex.proguardconfigurationresolver.ProguardConfigurationResolver; | ||
|
||
import org.gradle.api.Project; | ||
import org.gradle.api.Task; | ||
import org.gradle.api.file.FileCollection; | ||
|
||
import java.lang.reflect.Method; | ||
|
||
/** | ||
* Created by yangzhiqian on 2020/7/6<br/> | ||
*/ | ||
public class ProguardConfigurableTransformResolver extends ProguardConfigurationResolver { | ||
|
||
public ProguardConfigurableTransformResolver(Project project, String variantName) { | ||
super(project, variantName); | ||
} | ||
|
||
@Override | ||
public Task getTask() { | ||
for (Task task : project.getTasks()) { | ||
if (task instanceof TransformTask) { | ||
TransformTask transformTask = (TransformTask) task; | ||
String name = transformTask.getTransform().getClass().getName(); | ||
if (transformTask.getVariantName().equals(variantName) && | ||
("com.android.build.gradle.internal.transforms.ProGuardTransform".equals(name) || | ||
"com.android.build.gradle.internal.transforms.R8Transform".equals(name))) { | ||
return task; | ||
} | ||
} | ||
} | ||
return null; | ||
} | ||
|
||
@Override | ||
public FileCollection getAllConfigurationFiles() { | ||
Task task = getTask(); | ||
if (task == null) { | ||
return null; | ||
} | ||
ProguardConfigurable proguardConfigurable = (ProguardConfigurable) ((TransformTask) task).getTransform(); | ||
try { | ||
Method method = ProguardConfigurable.class.getDeclaredMethod("getAllConfigurationFiles"); | ||
method.setAccessible(true); | ||
return (FileCollection) method.invoke(proguardConfigurable); | ||
} catch (Exception e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,6 @@ | ||
apply from: rootProject.file('gradle/plugin.gradle') | ||
apply from: rootProject.file('gradle/plugin.gradle') | ||
dependencies { | ||
implementation project(':ProguardConfigurationResolver') | ||
implementation project(':ProguardConfigurationResolver-task') | ||
implementation project(':ProguardConfigurationResolver-transform') | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
...main/java/com/ss/android/ugc/bytex/hookproguard/ProguardConfigurationResolverFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package com.ss.android.ugc.bytex.hookproguard; | ||
|
||
import com.android.builder.model.Version; | ||
import com.android.repository.Revision; | ||
import com.ss.android.ugc.bytex.proguardconfigurationresolver.ProguardConfigurationResolver; | ||
import com.ss.android.ugc.bytex.proguardconfigurationresolver.task.ProguardConfigurableTaskResolver; | ||
import com.ss.android.ugc.bytex.proguardconfigurationresolver.transform.ProguardConfigurableTransformResolver; | ||
|
||
import org.gradle.api.Project; | ||
|
||
/** | ||
* Created by yangzhiqian on 2020/7/27<br/> | ||
*/ | ||
class ProguardConfigurationResolverFactory { | ||
public static ProguardConfigurationResolver createProguardConfigurationResolver(Project project, String variantName) { | ||
Revision revision = Revision.parseRevision(Version.ANDROID_GRADLE_PLUGIN_VERSION); | ||
if (revision.getMajor() >= 3 && revision.getMinor() >= 6) { | ||
return new ProguardConfigurableTaskResolver(project, variantName); | ||
} else { | ||
return new ProguardConfigurableTransformResolver(project, variantName); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.