在集成极光推送 SDK 的时候,如果把极光推送集成到一个独立的 AAR 包中,在编译的时候会发生如下报错:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
> Task :push:processDebugAndroidTestManifest FAILED D:\Source\xxx\push\build\intermediates\tmp\manifest\androidTest\debug\tempFile1ProcessTestManifest7039673500103366995.xml Error: Attribute service#xxx.xxx.xxx.push.PushService@process at tempFile1ProcessTestManifest7039673500103366995.xml requires a placeholder substitution but no value for <JIGUANG_PRIVATES_PROCESS> is provided. D:\Source\xxx\push\build\intermediates\tmp\manifest\androidTest\debug\tempFile1ProcessTestManifest7039673500103366995.xml Error: Attribute meta-data#JIGUANG_PRIVATES_APPKEY@value at tempFile1ProcessTestManifest7039673500103366995.xml requires a placeholder substitution but no value for <JIGUANG_PRIVATES_APPKEY> is provided. D:\Source\xxx\push\build\intermediates\tmp\manifest\androidTest\debug\tempFile1ProcessTestManifest7039673500103366995.xml Error: Attribute meta-data#JIGUANG_PRIVATES_PROCESS@value at tempFile1ProcessTestManifest7039673500103366995.xml requires a placeholder substitution but no value for <JIGUANG_PRIVATES_PROCESS> is provided. D:\Source\xxx\push\build\intermediates\tmp\manifest\androidTest\debug\tempFile1ProcessTestManifest7039673500103366995.xml Error: Attribute meta-data#XIAOMI_APPID@value at tempFile1ProcessTestManifest7039673500103366995.xml requires a placeholder substitution but no value for <XIAOMI_APPID> is provided. D:\Source\xxx\push\build\intermediates\tmp\manifest\androidTest\debug\tempFile1ProcessTestManifest7039673500103366995.xml Error: Attribute meta-data#XIAOMI_APPKEY@value at tempFile1ProcessTestManifest7039673500103366995.xml requires a placeholder substitution but no value for <XIAOMI_APPKEY> is provided. D:\Source\xxx\push\build\intermediates\tmp\manifest\androidTest\debug\tempFile1ProcessTestManifest7039673500103366995.xml Error: Attribute meta-data#MEIZU_APPID@value at tempFile1ProcessTestManifest7039673500103366995.xml requires a placeholder substitution but no value for <MEIZU_APPID> is provided. D:\Source\xxx\push\build\intermediates\tmp\manifest\androidTest\debug\tempFile1ProcessTestManifest7039673500103366995.xml Error: Attribute meta-data#MEIZU_APPKEY@value at tempFile1ProcessTestManifest7039673500103366995.xml requires a placeholder substitution but no value for <MEIZU_APPKEY> is provided. D:\Source\xxx\push\build\intermediates\tmp\manifest\androidTest\debug\tempFile1ProcessTestManifest7039673500103366995.xml Error: Attribute meta-data#OPPO_APPID@value at tempFile1ProcessTestManifest7039673500103366995.xml requires a placeholder substitution but no value for <OPPO_APPID> is provided. D:\Source\xxx\push\build\intermediates\tmp\manifest\androidTest\debug\tempFile1ProcessTestManifest7039673500103366995.xml Error: Attribute meta-data#OPPO_APPKEY@value at tempFile1ProcessTestManifest7039673500103366995.xml requires a placeholder substitution but no value for <OPPO_APPKEY> is provided. D:\Source\xxx\push\build\intermediates\tmp\manifest\androidTest\debug\tempFile1ProcessTestManifest7039673500103366995.xml Error: Attribute meta-data#OPPO_APPSECRET@value at tempFile1ProcessTestManifest7039673500103366995.xml requires a placeholder substitution but no value for <OPPO_APPSECRET> is provided. D:\Source\xxx\push\build\intermediates\tmp\manifest\androidTest\debug\tempFile1ProcessTestManifest7039673500103366995.xml Error: Attribute meta-data#com.vivo.push.app_id@value at tempFile1ProcessTestManifest7039673500103366995.xml requires a placeholder substitution but no value for <VIVO_APPID> is provided. D:\Source\xxx\push\build\intermediates\tmp\manifest\androidTest\debug\tempFile1ProcessTestManifest7039673500103366995.xml Error: Attribute meta-data#com.vivo.push.api_key@value at tempFile1ProcessTestManifest7039673500103366995.xml requires a placeholder substitution but no value for <VIVO_APPKEY> is provided. See http://g.co/androidstudio/manifest-merger for more information about the manifest merger. |
如果是构建单一 APK 的情况下,可以直接在 AAR 项目里面通过 manifestPlaceholders 直接配置这些参数。
但是如果是多渠道打包的情况下,我们会在统一的地方根据不同的渠道进行配置。
这个时候直接在 AAR 项目里面配置就不合适了,此时我们观察报错信息,会发现其实真正报错的地方是执行单元测试的时候报错(processDebugAndroidTestManifest)。
其实也容易理解,执行 AndroidTest 的时候,需要生成单独测的测试 APK,这一步就必须补充完整全部的 meta-data 信息,否则无法顺利生成 APK。
通过上述的分析,解决这个问题就比较简单了,我们只需要在测试用例的时候补充这些 meta-data 信息即可。
那接下来就是怎么生成 AndroidTest 的时候的配置信息,网上搜索很久,才在 Possibility to define manifestPlaceholders or BuildConfig variables just for tests 找到相关的解决方案。
参考解决方法如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
apply plugin: 'com.android.library' android { compileSdkVersion 21 buildToolsVersion "21.1.0" defaultConfig { minSdkVersion 15 targetSdkVersion 21 versionCode 1 versionName "1.0" } } android.testVariants.all { it.mergedFlavor.manifestPlaceholders = [ localApplicationId:"com.example.manifest_merger_example.flavor"] } |
极光推送相关的解决参考如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
apply plugin: 'com.android.library' android { compileSdkVersion 21 buildToolsVersion "21.1.0" defaultConfig { minSdkVersion 15 targetSdkVersion 21 versionCode 1 versionName "1.0" } } android.testVariants.all { it.mergedFlavor.manifestPlaceholders = [ JIGUANG_PRIVATES_CHANNEL: "developer-default", JIGUANG_PRIVATES_APPKEY : "123456abcdefghi", // jiguang process,极光sdk工作所在的进程,注意:开头 JIGUANG_PRIVATES_PROCESS: ":push", //魅族设置APPKEY,必须使用 "MZ-" 开头极光内部会进行转换 MEIZU_APPKEY : "MZ-123456abcdefghigklmn", MEIZU_APPID : "MZ-123456", //OPPO设置APPKEY,必须使用 "OP-" 开头极光内部会进行转换 OPPO_APPKEY : "OP-abcadefh", OPPO_APPID : "OP-123456", OPPO_APPSECRET: "OP-abcdefghigklmnopqrstuvwxyz", VIVO_APPKEY : "123456abcdefghi", VIVO_APPID : "123456", //小米设置APPKEY,必须使用 "MI-" 开头极光内部会进行转换 XIAOMI_APPID : "MI-123123123123123123", XIAOMI_APPKEY : "MI-123123123" ] } |