Support Andorid Gradle Plugin 3.0.0+ (#217)

* * compat for android gradle plugin 3.0.0+

* * transform rootLocation compat

* * plugin gradle compat
This commit is contained in:
区长 2017-07-18 15:29:44 +08:00 committed by 王玉鹏
parent 80f1bf0d98
commit cc2a0b2ecd
3 changed files with 48 additions and 8 deletions

View File

@ -98,9 +98,27 @@ public class Replugin implements Plugin<Project> {
variant.outputs.each { output ->
output.processManifest.doLast {
def manifestPath = output.processManifest.outputFile.absolutePath
def updatedContent = new File(manifestPath).getText("UTF-8").replaceAll("</application>", newManifest + "</application>")
new File(manifestPath).write(updatedContent, 'UTF-8')
output.processManifest.outputs.files.each { File file ->
def manifestFile = null;
//gradle plugin 3.0.0file是文件AndroidManifest.xml
//gradle plugin 3.0.0file是目录AndroidManifest.xml
//AndroidManifest.xml之外manifest-merger-debug-report.txt等不相干的文件
if ((file.name.equalsIgnoreCase("AndroidManifest.xml") && !file.isDirectory()) || file.isDirectory()) {
if (file.isDirectory()) {
//3.0.0AndroidManifest.xml
manifestFile = new File(file, "AndroidManifest.xml")
} else {
//3.0.0使
manifestFile = file
}
//
if (manifestFile != null && manifestFile.exists()) {
println "${AppConstant.TAG} handle manifest: ${manifestFile}"
def updatedContent = manifestFile.getText("UTF-8").replaceAll("</application>", newManifest + "</application>")
manifestFile.write(updatedContent, 'UTF-8')
}
}
}
}
}
}

View File

@ -26,8 +26,8 @@ import com.qihoo360.replugin.gradle.plugin.injector.Injectors
import javassist.ClassPool
import org.apache.commons.codec.digest.DigestUtils
import org.apache.commons.io.FileUtils
import org.gradle.api.GradleException
import org.gradle.api.Project
import java.util.regex.Pattern
/**
@ -68,10 +68,20 @@ public class ReClassTransform extends Transform {
/* 读取用户配置 */
def config = project.extensions.getByName('repluginPluginConfig')
File rootLocation = outputProvider.rootLocation
File rootLocation = null
try {
rootLocation = outputProvider.rootLocation
} catch (Throwable e) {
//android gradle plugin 3.0.0+ IntermediateFolderUtils中去
rootLocation = outputProvider.folderUtils.getRootFolder()
}
if (rootLocation == null) {
throw new GradleException("can't get transform root location")
}
println ">>> rootLocation: ${rootLocation}"
// Compatible with path separators for window and Linux, and fit split param based on 'Pattern.quote'
def variantDir = rootLocation.absolutePath.split(getName() + Pattern.quote(File.separator))[1]
println ">>> variantDir: ${variantDir}"
CommonData.appModule = config.appModule

View File

@ -17,6 +17,7 @@
package com.qihoo360.replugin.gradle.plugin.manifest
import org.gradle.api.GradleException
import org.gradle.api.Project
import java.util.regex.Pattern
@ -56,9 +57,20 @@ public class ManifestAPI {
if (processManifestTask) {
File result = null
//manifest
File manifestOutputFile = processManifestTask.getManifestOutputFile()
File manifestOutputFile = null
//instant run的manifest
File instantRunManifestOutputFile = processManifestTask.getInstantRunManifestOutputFile()
File instantRunManifestOutputFile = null
try {
manifestOutputFile = processManifestTask.getManifestOutputFile()
instantRunManifestOutputFile = processManifestTask.getInstantRunManifestOutputFile()
} catch (Exception e) {
manifestOutputFile = new File(processManifestTask.getManifestOutputDirectory(), "AndroidManifest.xml")
instantRunManifestOutputFile = new File(processManifestTask.getInstantRunManifestOutputDirectory(), "AndroidManifest.xml")
}
if (manifestOutputFile == null && instantRunManifestOutputFile == null) {
throw new GradleException("can't get manifest file")
}
//
println " manifestOutputFile:${manifestOutputFile} ${manifestOutputFile.exists()}"