-
-
Notifications
You must be signed in to change notification settings - Fork 406
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
6 changed files
with
69 additions
and
12 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,44 @@ | ||
import groovy.xml.Namespace | ||
import groovy.xml.XmlUtil | ||
|
||
/** | ||
* 修改 Android 12 因为 exported 的构建问题 | ||
*/ | ||
android.applicationVariants.all { variant -> | ||
variant.outputs.all { output -> | ||
output.processResources.doFirst { pm -> | ||
String manifestPath = output.processResources.manifestFile | ||
def manifestFile = new File(manifestPath) | ||
def xml = new XmlParser(false, true).parse(manifestFile) | ||
def exportedTag = "android:exported" | ||
def nameTag = "android:name" | ||
///指定 space | ||
def androidSpace = new Namespace('http://schemas.android.com/apk/res/android', 'android') | ||
|
||
def nodes = xml.application[0].'*'.findAll { | ||
//挑选要修改的节点,没有指定的 exported 的才需要增加 | ||
(it.name() == 'activity' || it.name() == 'receiver' || it.name() == 'service') && it.attribute(androidSpace.exported) == null | ||
} | ||
///添加 exported,默认 false | ||
nodes.each { | ||
def isMain = false | ||
it.each { | ||
if (it.name() == "intent-filter") { | ||
it.each { | ||
if (it.name() == "action") { | ||
if (it.attributes().get(androidSpace.name) == "android.intent.action.MAIN") { | ||
isMain = true | ||
println("......................MAIN FOUND......................") | ||
} | ||
} | ||
} | ||
} | ||
} | ||
it.attributes().put(exportedTag, "${isMain}") | ||
} | ||
PrintWriter pw = new PrintWriter(manifestFile) | ||
pw.write(XmlUtil.serialize(xml)) | ||
pw.close() | ||
} | ||
} | ||
} |
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