mirror of
https://gitee.com/replugin/RePlugin.git
synced 2024-12-02 11:48:02 +08:00
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:
parent
80f1bf0d98
commit
cc2a0b2ecd
@ -98,9 +98,27 @@ public class Replugin implements Plugin<Project> {
|
|||||||
|
|
||||||
variant.outputs.each { output ->
|
variant.outputs.each { output ->
|
||||||
output.processManifest.doLast {
|
output.processManifest.doLast {
|
||||||
def manifestPath = output.processManifest.outputFile.absolutePath
|
output.processManifest.outputs.files.each { File file ->
|
||||||
def updatedContent = new File(manifestPath).getText("UTF-8").replaceAll("</application>", newManifest + "</application>")
|
def manifestFile = null;
|
||||||
new File(manifestPath).write(updatedContent, 'UTF-8')
|
//在gradle plugin 3.0.0之前,file是文件,且文件名为AndroidManifest.xml
|
||||||
|
//在gradle plugin 3.0.0之后,file是目录,且不包含AndroidManifest.xml,需要自己拼接
|
||||||
|
//除了目录和AndroidManifest.xml之外,还可能会包含manifest-merger-debug-report.txt等不相干的文件,过滤它
|
||||||
|
if ((file.name.equalsIgnoreCase("AndroidManifest.xml") && !file.isDirectory()) || file.isDirectory()) {
|
||||||
|
if (file.isDirectory()) {
|
||||||
|
//3.0.0之后,自己拼接AndroidManifest.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')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -26,8 +26,8 @@ import com.qihoo360.replugin.gradle.plugin.injector.Injectors
|
|||||||
import javassist.ClassPool
|
import javassist.ClassPool
|
||||||
import org.apache.commons.codec.digest.DigestUtils
|
import org.apache.commons.codec.digest.DigestUtils
|
||||||
import org.apache.commons.io.FileUtils
|
import org.apache.commons.io.FileUtils
|
||||||
|
import org.gradle.api.GradleException
|
||||||
import org.gradle.api.Project
|
import org.gradle.api.Project
|
||||||
|
|
||||||
import java.util.regex.Pattern
|
import java.util.regex.Pattern
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -68,10 +68,20 @@ public class ReClassTransform extends Transform {
|
|||||||
/* 读取用户配置 */
|
/* 读取用户配置 */
|
||||||
def config = project.extensions.getByName('repluginPluginConfig')
|
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'
|
// 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]
|
def variantDir = rootLocation.absolutePath.split(getName() + Pattern.quote(File.separator))[1]
|
||||||
|
|
||||||
println ">>> variantDir: ${variantDir}"
|
println ">>> variantDir: ${variantDir}"
|
||||||
|
|
||||||
CommonData.appModule = config.appModule
|
CommonData.appModule = config.appModule
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
|
|
||||||
package com.qihoo360.replugin.gradle.plugin.manifest
|
package com.qihoo360.replugin.gradle.plugin.manifest
|
||||||
|
|
||||||
|
import org.gradle.api.GradleException
|
||||||
import org.gradle.api.Project
|
import org.gradle.api.Project
|
||||||
|
|
||||||
import java.util.regex.Pattern
|
import java.util.regex.Pattern
|
||||||
@ -56,9 +57,20 @@ public class ManifestAPI {
|
|||||||
if (processManifestTask) {
|
if (processManifestTask) {
|
||||||
File result = null
|
File result = null
|
||||||
//正常的manifest
|
//正常的manifest
|
||||||
File manifestOutputFile = processManifestTask.getManifestOutputFile()
|
File manifestOutputFile = null
|
||||||
//instant run的manifest
|
//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()}"
|
println " manifestOutputFile:${manifestOutputFile} ${manifestOutputFile.exists()}"
|
||||||
|
Loading…
Reference in New Issue
Block a user