問題描述
集成JPush出現(xiàn)一個神奇的bug,只要集成好JPush壳炎,環(huán)信就崩潰泞歉,打印如下錯誤
E/AndroidRuntime: FATAL EXCEPTION: main Process: com.uztek.fh, PID: 31868 java.lang.UnsatisfiedLinkError:
com.android.tools.fd.runtime.IncrementalClassLoader$DelegateClassLoader
……中間省略無效log…………
nativeLibraryDirectories=[/data/app/com.uztek.fh-1/lib/arm, /data/app/com.uztek.fh-1/base.apk!/lib/armeabi-v7a, /vendor/lib, /system/lib]]]
couldn't find "libhyphenate_av.so"
問題排查
一開始,以為是集成步驟出錯了匿辩,反復(fù)注銷相關(guān)代碼來排查問題腰耙,發(fā)現(xiàn)把設(shè)置jniLibs的代碼注銷即可。
android {
sourceSets {
main {
// jniLibs.srcDirs = ['libs-jpush']
}
}
}
問題原因
為什么呢铲球?反復(fù)觀察文件挺庞,發(fā)現(xiàn)JPush的so目錄和環(huán)信不是一致的
JPush lib庫結(jié)構(gòu).png
環(huán)信 lib庫結(jié)構(gòu).png
回看bug信息,里面nativeLibraryDirectories=[/data/app/com.uztek.fh-1/lib/arm, /data/app/com.uztek.fh-1/base.apk!/lib/armeabi-v7a, /vendor/lib, /system/lib]]]
睬辐,這幾個文件夾下都沒有環(huán)信的庫挠阁,而只有JPush的庫。所以整個流程是這樣的:
- 集成JPush之前溯饵,系統(tǒng)發(fā)現(xiàn)armeabi是最匹配的,所以在這個里面發(fā)現(xiàn)了環(huán)信的庫锨用,正常使用丰刊。
- 集成JPush之后,系統(tǒng)發(fā)現(xiàn)armeabi-v7a是最匹配的增拥,在這里找到JPush的庫啄巧,但是沒有環(huán)信的庫,所以產(chǎn)生異常掌栅,拋出崩潰秩仆。
問題解決
刪除掉只含有JPush庫的幾個文件夾即可。
附贈:JPush集成清單
- 在jPush控制臺新建相關(guān)的app猾封,獲取相應(yīng)的key值澄耍。
- 按照Android集成指南集成 jar、so晌缘、AndroidManifest.xml齐莲、res
- 通常吧so和jar放到一個單獨的目錄,比如libs-jpush磷箕,然后在build.gradle添加
android {
sourceSets {
main {
jniLibs.srcDirs = ['libs-jpush']
}
}
}
dependencies {
compile fileTree(dir: 'libs-jpush', include: ['*.jar'])
}
- 實現(xiàn)IPushInterface接口选酗,比如
iPushInterface = new IPushInterface() {
@Override
public void setDebugMode(boolean b) {
JPushInterface.setDebugMode(b);
}
@Override
public void initPush(Context context) {
JPushInterface.init(context);
}
@Override
public void setAlias(Context context, String alias) {
JPushInterface.setAlias(context, alias, new TagAliasCallback() {
@Override
public void gotResult(int i, String s, Set<String> set) {}});
}
@Override
public void resumePush(Context context) {
JPushInterface.resumePush(context);
}
@Override
public void stopPush(Context context) {
JPushInterface.stopPush(context);
}
};
- 配置消息接收器,比如:
<receiver
android:name="panda.android.lib.commonapp.push.PushReceiver"
android:exported="false"
android:enabled="true">
<intent-filter>
<action android:name="cn.jpush.android.intent.REGISTRATION" /> <!--Required 用戶注冊SDK的intent-->
<action android:name="cn.jpush.android.intent.UNREGISTRATION" />
<action android:name="cn.jpush.android.intent.MESSAGE_RECEIVED" /> <!--Required 用戶接收SDK消息的intent-->
<action android:name="cn.jpush.android.intent.NOTIFICATION_RECEIVED" /> <!--Required 用戶接收SDK通知欄信息的intent-->
<action android:name="cn.jpush.android.intent.NOTIFICATION_OPENED" /> <!--Required 用戶打開自定義通知欄的intent-->
<action android:name="cn.jpush.android.intent.ACTION_RICHPUSH_CALLBACK" /> <!--Optional 用戶接受Rich Push Javascript 回調(diào)函數(shù)的intent-->
<action android:name="cn.jpush.android.intent.CONNECTION" /><!-- 接收網(wǎng)絡(luò)變化 連接/斷開 since 1.6.3 -->
<category android:name="${applicationId}" />
</intent-filter>
</receiver>
- 在app初始化的位置初始化引擎
iPushInterface.setDebugMode(true);
iPushInterface.initPush(getActivity());
iPushInterface.setAlias(getActivity(), "alias_mi4");
- 在
AndroidManifest.xml
岳枷、build.gradle
芒填、gradle.properties
配置相關(guān)的key值
<meta-data android:name="JPUSH_APPKEY" android:value="${jpushAppkey}" /> <!-- </>值來自開發(fā)者平臺取得的AppKey-->
manifestPlaceholders = [jpushAppkey: "project.jPUSH_APP_KEY"]
jPUSH_APP_KEY=<jPush控制臺提供的key值>
- 在后臺推送通知和消息呜叫,進(jìn)行測試。
Panda
2016-05-25