From 7e2507358f906bc5adade4780cfe764af1e86c4c Mon Sep 17 00:00:00 2001 From: Lihongda <963140097@qq.com> Date: Fri, 5 Jan 2024 02:05:37 +0800 Subject: [PATCH] =?UTF-8?q?=E9=80=82=E9=85=8Dandroid=2013?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- android12.gradle | 65 +++++++++++++++++++ .../com/ifish/baseclass/BaseApplication.java | 5 +- 2 files changed, 68 insertions(+), 2 deletions(-) create mode 100644 android12.gradle diff --git a/android12.gradle b/android12.gradle new file mode 100644 index 000000000..8f3c047cb --- /dev/null +++ b/android12.gradle @@ -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() + + } + + } + + + + } +} \ No newline at end of file diff --git a/iFish7/src/main/java/com/ifish/baseclass/BaseApplication.java b/iFish7/src/main/java/com/ifish/baseclass/BaseApplication.java index c6650d2a6..7e83502ea 100644 --- a/iFish7/src/main/java/com/ifish/baseclass/BaseApplication.java +++ b/iFish7/src/main/java/com/ifish/baseclass/BaseApplication.java @@ -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); }