-
Notifications
You must be signed in to change notification settings - Fork 630
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
support gradle plugin 3.3.0+ , gradle 5.0+
- Loading branch information
Showing
10 changed files
with
362 additions
and
97 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,10 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<!-- | ||
~ Copyright (C) 2015 Baidu, Inc. All Rights Reserved. | ||
--> | ||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:orientation="horizontal" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent"> | ||
|
||
</LinearLayout> |
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
107 changes: 107 additions & 0 deletions
107
source/src/main/groovy/com/kezong/fataar/FlavorArtifact.groovy
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,107 @@ | ||
package com.kezong.fataar | ||
|
||
import com.android.build.gradle.api.LibraryVariant | ||
import org.gradle.api.Project | ||
import org.gradle.api.Task | ||
import org.gradle.api.artifacts.ModuleVersionIdentifier | ||
import org.gradle.api.artifacts.ResolvedDependency | ||
import org.gradle.api.artifacts.component.ComponentArtifactIdentifier | ||
import org.gradle.api.artifacts.component.ComponentIdentifier | ||
import org.gradle.api.internal.artifacts.DefaultModuleVersionIdentifier | ||
import org.gradle.api.internal.artifacts.DefaultResolvedArtifact | ||
import org.gradle.api.tasks.TaskDependency | ||
import org.gradle.internal.Factory | ||
import org.gradle.internal.component.model.DefaultIvyArtifactName | ||
|
||
import javax.annotation.Nullable | ||
|
||
/** | ||
* FlavorArtifact | ||
* @author yangchao on 2019/4/25. | ||
*/ | ||
class FlavorArtifact { | ||
|
||
static DefaultResolvedArtifact createFlavorArtifact(Project project, LibraryVariant variant, ResolvedDependency unResolvedArtifact, String version) { | ||
ModuleVersionIdentifier identifier = createModuleVersionIdentifier(unResolvedArtifact) | ||
DefaultIvyArtifactName artifactName = createArtifactName(unResolvedArtifact) | ||
Project artifactProject = getArtifactProject(project, unResolvedArtifact) | ||
File artifactFile = createArtifactFile(artifactProject, variant, unResolvedArtifact, version) | ||
Factory<File> fileFactory = new Factory<File>() { | ||
@Override | ||
File create() { | ||
return artifactFile | ||
} | ||
} | ||
TaskDependency taskDependency = createTaskDependency(artifactProject, variant) | ||
ComponentArtifactIdentifier artifactIdentifier = createComponentIdentifier(artifactFile) | ||
|
||
return new DefaultResolvedArtifact(identifier, artifactName, artifactIdentifier, taskDependency, fileFactory) | ||
} | ||
|
||
private static ModuleVersionIdentifier createModuleVersionIdentifier(ResolvedDependency unResolvedArtifact) { | ||
return new DefaultModuleVersionIdentifier( | ||
unResolvedArtifact.getModuleGroup(), | ||
unResolvedArtifact.getModuleName(), | ||
unResolvedArtifact.getModuleVersion() | ||
) | ||
} | ||
|
||
private static DefaultIvyArtifactName createArtifactName(ResolvedDependency unResolvedArtifact) { | ||
return new DefaultIvyArtifactName(unResolvedArtifact.getModuleName(), "aar", "") | ||
} | ||
|
||
private static ComponentArtifactIdentifier createComponentIdentifier(final File artifactFile) { | ||
return new ComponentArtifactIdentifier() { | ||
@Override | ||
ComponentIdentifier getComponentIdentifier() { | ||
return null | ||
} | ||
|
||
@Override | ||
String getDisplayName() { | ||
return artifactFile.name | ||
} | ||
} | ||
} | ||
|
||
private static Project getArtifactProject(Project project, ResolvedDependency unResolvedArtifact) { | ||
for (Project p : project.getRootProject().getAllprojects()) { | ||
if (unResolvedArtifact.moduleName == p.name) { | ||
return p | ||
} | ||
} | ||
return null | ||
} | ||
|
||
private static File createArtifactFile(Project project, LibraryVariant variant, ResolvedDependency unResolvedArtifact, String version) { | ||
def buildPath = project.buildDir.path | ||
def outputName | ||
if (Utils.compareVersion(project.gradle.gradleVersion, "5.1.0") >= 0 && Utils.compareVersion(version, "3.4") < 0) { | ||
outputName = "$buildPath/outputs/aar/${unResolvedArtifact.moduleName}.aar" | ||
} else { | ||
outputName = "$buildPath/outputs/aar/$unResolvedArtifact.moduleName-$variant.flavorName-${variant.buildType.name}.aar" | ||
} | ||
return new File(outputName) | ||
} | ||
|
||
private static TaskDependency createTaskDependency(Project project, LibraryVariant variant) { | ||
def taskPath = 'bundle' + variant.name.capitalize() | ||
Task bundleTask = project.tasks.findByPath(taskPath) | ||
if (bundleTask == null) { | ||
taskPath = 'bundle' + variant.name.capitalize() + "Aar" | ||
bundleTask = project.tasks.findByPath(taskPath) | ||
} | ||
if (bundleTask == null) { | ||
throw new RuntimeException("Can not find task ${taskPath}!") | ||
} | ||
|
||
return new TaskDependency() { | ||
@Override | ||
Set<? extends Task> getDependencies(@Nullable Task task) { | ||
def set = new HashSet() | ||
set.add(bundleTask) | ||
return set | ||
} | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
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,49 @@ | ||
package com.kezong.fataar | ||
|
||
/** | ||
* Utils | ||
* @author kezong @since 2018-12-10 17:28 | ||
*/ | ||
class Utils { | ||
|
||
def static logError(def msg) { | ||
println("【Fat-aar-ERROR】${msg}") | ||
} | ||
|
||
def static logInfo(def msg) { | ||
println("【Fat-aar-INFO】${msg}") | ||
} | ||
|
||
static int compareVersion(String v1, String v2) { | ||
if (v1.equals(v2)) { | ||
return 0 | ||
} | ||
String[] version1Array = v1.split("[._]") | ||
String[] version2Array = v2.split("[._]") | ||
int index = 0 | ||
int minLen = Math.min(version1Array.length, version2Array.length) | ||
long diff = 0 | ||
|
||
while (index < minLen | ||
&& (diff = Long.parseLong(version1Array[index]) | ||
- Long.parseLong(version2Array[index])) == 0) { | ||
index++ | ||
} | ||
if (diff == 0) { | ||
for (int i = index; i < version1Array.length; i++) { | ||
if (Long.parseLong(version1Array[i]) > 0) { | ||
return 1 | ||
} | ||
} | ||
|
||
for (int i = index; i < version2Array.length; i++) { | ||
if (Long.parseLong(version2Array[i]) > 0) { | ||
return -1 | ||
} | ||
} | ||
return 0 | ||
} else { | ||
return diff > 0 ? 1 : -1 | ||
} | ||
} | ||
} |
Oops, something went wrong.