适配android 13
This commit is contained in:
parent
a177e6ebf7
commit
7e2507358f
|
|
@ -0,0 +1,65 @@
|
|||
/**
|
||||
* 修改 Android 12 因为 exported 的构建问题
|
||||
*/
|
||||
|
||||
android.applicationVariants.all { variant ->
|
||||
variant.outputs.each { output ->
|
||||
def processManifest = output.getProcessManifestProvider().get()
|
||||
println("-------1---- ${processManifest.name} ----------- ")
|
||||
processManifest.doLast { task ->
|
||||
def outputDir = task.multiApkManifestOutputDirectory
|
||||
File outputDirectory
|
||||
if (outputDir instanceof File) {
|
||||
outputDirectory = outputDir
|
||||
} else {
|
||||
outputDirectory = outputDir.get().asFile
|
||||
}
|
||||
File manifestOutFile = file("$outputDirectory/AndroidManifest.xml")
|
||||
|
||||
|
||||
if (manifestOutFile.exists() && manifestOutFile.canRead() && manifestOutFile.canWrite()) {
|
||||
def manifestFile = manifestOutFile
|
||||
///这里第二个参数是 false ,所以 namespace 是展开的,所以下面不能用 androidSpace,而是用 nameTag
|
||||
def xml = new groovy.util.XmlParser(false, false).parse(manifestFile)
|
||||
def exportedTag = "android:exported"
|
||||
def nameTag = "android:name"
|
||||
///指定 space
|
||||
//def androidSpace = new groovy.xml.Namespace('http://schemas.android.com/apk/res/android', 'android')
|
||||
|
||||
def nodes = xml.application[0].'*'.findAll {
|
||||
//挑选要修改的节点,没有指定的 exported 的才需要增加
|
||||
//如果 exportedTag 拿不到可以尝试 it.attribute(androidSpace.exported)
|
||||
(it.name() == 'activity' || it.name() == 'receiver' || it.name() == 'service' || it.name() == 'activity-alias') && it.attribute(exportedTag) == null
|
||||
|
||||
}
|
||||
///添加 exported,默认 false
|
||||
nodes.each {
|
||||
def isMain = false
|
||||
it.each {
|
||||
if (it.name() == "intent-filter") {
|
||||
it.each {
|
||||
if (it.name() == "action") {
|
||||
//如果 nameTag 拿不到可以尝试 it.attribute(androidSpace.name)
|
||||
if (it.attributes().get(nameTag) == "android.intent.action.MAIN") {
|
||||
isMain = true
|
||||
println("......................MAIN FOUND......................")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
it.attributes().put(exportedTag, "${isMain}")
|
||||
}
|
||||
|
||||
PrintWriter pw = new PrintWriter(manifestFile)
|
||||
pw.write(groovy.xml.XmlUtil.serialize(xml))
|
||||
pw.close()
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -15,8 +15,8 @@ import androidx.multidex.MultiDexApplication;
|
|||
|
||||
import com.alibaba.sdk.android.push.CloudPushService;
|
||||
import com.alibaba.sdk.android.push.CommonCallback;
|
||||
import com.alibaba.sdk.android.push.huawei.HuaWeiRegister;
|
||||
import com.alibaba.sdk.android.push.noonesdk.PushServiceFactory;
|
||||
import com.alibaba.sdk.android.push.register.HuaWeiRegister;
|
||||
import com.alibaba.sdk.android.push.register.MiPushRegister;
|
||||
import com.ifish.utils.SystemUtil;
|
||||
import com.p2p.core.P2PSpecial.P2PSpecial;
|
||||
|
|
@ -106,6 +106,7 @@ public class BaseApplication extends MultiDexApplication {
|
|||
|
||||
private void initalipushSDK() {
|
||||
PushServiceFactory.init(this);
|
||||
|
||||
final CloudPushService pushService = PushServiceFactory.getCloudPushService();
|
||||
pushService.register(this, new CommonCallback() {
|
||||
@Override
|
||||
|
|
@ -121,7 +122,7 @@ public class BaseApplication extends MultiDexApplication {
|
|||
});
|
||||
// 注册方法会自动判断是否支持小米系统推送,如不支持会跳过注册。
|
||||
MiPushRegister.register(this, "2882303761517421890", "5491742138890");
|
||||
// 注册方法会自动判断是否支持华为系统推送,如不支持会跳过注册。
|
||||
// 注册方法会自动判断是否支持华为系统推送,如不支持会跳过注册。
|
||||
HuaWeiRegister.register(this);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue