jpush / jpush-phonegap-plugin

JPush's officially supported PhoneGap/Cordova plugin (Android & iOS). 极光推送官方支持的 PhoneGap/Cordova 插件(Android & iOS)。
https://docs.jiguang.cn
MIT License
925 stars 350 forks source link

能否对 ionic capacitor 接入进一步说明,总是提示无效 $app_key #412

Open cipchk opened 5 years ago

cipchk commented 5 years ago

WARNING: 如果不按照这个表格,我们将无法帮助你,并将忽略你的问题。

你的运行环境

期望效果

正确识别 app_key

实际效果

2019-08-08 20:24:40.355 16467-16493/? E/JIGUANG-JCore: [CheckManifestHelper] errorcode:1008,Invalid appKey : $app_key, Please get your Appkey from JIGUANG web console!

重现步骤

-

背景

Capacitor 无法跟像 Cordova 一样使用 --variable 来指定 APP_KEY,然而尝试以下几种形式的参数指定都失败:

  1. AndroidManifest.xml 增加类似 <meta-data android:name="APP_KEY">
  2. android/app/build.gradle 下增加 manifestPlaceholders 节点
manifestPlaceholders = [
            JPUSH_PKGNAME : applicationId,
            JPUSH_APPKEY : "你的 Appkey ", //JPush 上注册的包名对应的 Appkey.
            JPUSH_CHANNEL : "developer-default", //暂时填写默认值即可.
        ]

Debug logs

包括 Android 或 iOS 的日志:

cipchk commented 5 years ago

假如在 AndroidManifest.xmlmainfest/application 节点下增加:

<meta-data android:name="JPUSH_APPKEY" android:value="@string/jg_api_key"/>

其中 @string/jg_api_key 已经在 strings.xml 中定义。

会接收到:

Manifest merger failed : Attribute meta-data#JPUSH_APPKEY@value value=(@string/jg_api_key) from AndroidManifest.xml:45:48-82
    is also present at [:capacitor-cordova-android-plugins] AndroidManifest.xml:153:13-37 value=($APP_KEY).
    Suggestion: add 'tools:replace="android:value"' to <meta-data> element at AndroidManifest.xml:45:9-84 to override.

能否进一步描述问题如何解决呢? @weiruiyang @JoshLipan @huangminlinux (抱歉,这个问题已经 卡好些天,我无法单独解决它。)

Anberm commented 5 years ago

假如在 AndroidManifest.xmlmainfest/application 节点下增加:

<meta-data android:name="JPUSH_APPKEY" android:value="@string/jg_api_key"/>

其中 @string/jg_api_key 已经在 strings.xml 中定义。

会接收到:

Manifest merger failed : Attribute meta-data#JPUSH_APPKEY@value value=(@string/jg_api_key) from AndroidManifest.xml:45:48-82
  is also present at [:capacitor-cordova-android-plugins] AndroidManifest.xml:153:13-37 value=($APP_KEY).
  Suggestion: add 'tools:replace="android:value"' to <meta-data> element at AndroidManifest.xml:45:9-84 to override.

能否进一步描述问题如何解决呢? @weiruiyang @JoshLipan @huangminlinux (抱歉,这个问题已经 卡好些天,我无法单独解决它。)

@cipchk 迟来的回复,针对capacitor,暂时我还没有便捷的方式去完成这个配置,需要有开发者自己添加,极光的配置如下: 在相对目录找到配置文件 android\capacitor-cordova-android-plugins\src\main\AndroidManifest.xml 73、74行 修改相应值

<meta-data android:name="JPUSH_CHANNEL" android:value="developer-default" /> <meta-data android:name="JPUSH_APPKEY" android:value="极光Appkey" />

这样就可以正常运行,但是不好的点是,每次的 capacitor copy 操作都会还原这个值

目前基于有些插件还没有完全适配,我这边暂时还使用cordova,也没再深入处理这个问题,希望能帮到你

Anberm commented 5 years ago

@cipchk 花了点时间看了极光插件的实现,得到了合适的方式配置: 1.android\app\build.gradle 加入 manifestPlaceholders = [ JPUSH_PKGNAME : applicationId ]

2.android\app\src\main\AndroidManifest.xml 加入 `

    <!-- Required. AppKey copied from Portal -->
    <meta-data android:name="JPUSH_APPKEY" android:value="xxx" tools:replace="android:value" />

` image image

cipchk commented 5 years ago

@Anberm 感谢,的确可行,虽然我已经放弃 capacitor 了,因为除此之外许多插件都不支持 capacitor 需要这很麻烦。

同时,也希望能跟进 capacitor 的兼容,因为只需要对 plugin.xml 进行简单的升级即可。

AlwaysLoveme commented 4 years ago

@cipchk 花了点时间看了极光插件的实现,得到了合适的方式配置: 1.android\app\build.gradle 加入 manifestPlaceholders = [ JPUSH_PKGNAME : applicationId ]

2.android\app\src\main\AndroidManifest.xml 加入 <meta-data android:name="JPUSH_CHANNEL" android:value="developer-default" tools:replace="android:value" /> <!-- Required. AppKey copied from Portal --> <meta-data android:name="JPUSH_APPKEY" android:value="xxx" tools:replace="android:value" /> image image

使用capacitor,IOS平台添加此插件,构建会报“library not found for -ljcore-ios-2.1.4”错误,请问有方法解决该错误吗?比较急