腾讯X5内核集成-解决遇到的问题(ABI平台匹配加载理解)

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了腾讯X5内核集成-解决遇到的问题(ABI平台匹配加载理解)相关的知识,希望对你有一定的参考价值。

参考技术A 上周项目有需要,集成了“腾讯X5浏览器内核”过程中,也遇到了一些问题。经过摸索,也顺带补充解决了之前ABI方面的理解。

APP,内容模块视频部分,使用时夏正流行H5技术。

html5的Video控件播放视频,在android平台的WebView中播放的效果,和ios播放效果有差异。IOS点击视频部分,会用系统自带的浏览器全屏播放视频,体验效果佳;而Android的WebView无法全屏。至少体验效果比IOS上的差一些。

①Html5页面使用一些开源封装过的Video,带全屏等。

结果:产品部,认为体验不佳。提出疑问:“为什么在QQ上播放那么好呢?”,这,毕竟我们是技术方, 也不好直接说“别人技术牛”。

②重写WebChromeClient的onShowCustomView开启全屏;onHideCustomView退出全屏。

结果:相信有朋友也折腾过这玩意,在Android 4.4开始的手机,大部分不会进入该回调方法。

③技术体验上,不懂技术的同事等, 都是用QQ,微信举例。那就使用腾讯X5内核吧。

①成功调用x5内核条件是安装腾讯三个常见产品之一:1、手机QQ;2、微信;3、QQ浏览器。当然版本也有限制,到这里,我们至少知道,三者中一个,是很有可能成功的,只要版本不太低,至少身边朋友的版本,都不至于太低了。

②第一次安装集成该SDK的版本必须预热(从SDK接入文档中理解,理论上是, 大部分情况第一次是启动失败的,从试验中,是kill了进程,再开启才成功)。

③ABI只提供armeabi的.so

①导入相应的.jar,  .so 文件:

libs: tbs_sdk_v1.5.1.1057_25436_obfs_20160331_144900.jar

armeabi:liblbs.so

②预热X5内核:

/**

* 开启额外进程 服务 预加载X5内核, 此操作必须在主进程调起X5内核前进行,否则将不会实现预加载

*/

private voidpreinitX5WithService()

Intent intent =newIntent(this,FirstLoadingX5Service.class);

startService(intent);



/**

* X5内核在使用preinit接口之后,对于首次安装首次加载没有效果

* 实际上,X5webview的preinit接口只是降低了webview的冷启动时间;

* 因此,现阶段要想做到首次安装首次加载X5内核,必须要让X5内核提前获取到内核的加载条件

*/

private voidpreinitX5WebCore()

if(!QbSdk.isTbsCoreInited())

// preinit只需要调用一次,如果已经完成了初始化,那么就直接构造view

QbSdk.preInit(MainActivity.this, null);// 设置X5初始化完成的回调接口





③用多台手机测试:华为4A, 华为荣耀(忘记什么型号,是64位CPU),google nenux4, 小米4C, 华为mate 7, 红米Note2 等等。APP打包测试。

结果:只有我的华为4A能播放。 为什么别的,就不正常呢?

------------------------------以下-解决篇--------------------------------

①CPU方面,华为4A是比较老的CPU, 估计就是armeabi的了,由于别的机型,我都有对应的abi目录,都各自找到相应的平台目录, 所以无法加载“liblbs.so”。

②尝试将“liblbs.so”放在各个abi目录中, 结果还是没办法启动x5。

③通过百度,google等搜索,再次进行ABI方面的理解加深,获取解决方案:

项目的“build.gradle”文件defaultConfig,增加配置

ndk

abiFilters"armeabi","armeabi-v7a","x86","mips"



结果:确实解决了问题。

①难道是别的平台都指向了最低兼容的armeabi目录? 噢,如果这样做的话,在APP中性能会有极大的损失。如arm-v7中的  浮点运算,这就损失极大。更何况64位的CPU。

②难道是机器是智能化了?先找相应平台的.so, 不行,再逐个查看向下的兼容平台?如果是这样,那就太好了。

③什么优先顺序呢?这个Android选取ABI的机制?我也想了解。 顺带这个问题一起学习。

①google一些资料,在overflow上,找到挺好的http://stackoverflow.com/questions/20674650/how-to-configure-ndk-with-android-gradle-plugin-0-7/21413011#21413011。

鬼老很务实, 他也有这种的疑问,从假象的提出,到论证,到结论。佩服。

文中的一些片段,我摘取一下:

To simply Link in Prebuilt Native Libraries, just add an ndk section to your task. For instance, I added it below in productFlavors. The abiFilter is the folder name the libs are stored in. abiFilters means both libs from the comma separated list will be added to your final APK (so you could theoretically have "armeabi", "armeabi-v7a", "x86", and "mips" all in one APK, and the O/S would choose the supported architecture lib on install):

Very helpful. Thanks indeed. BTW, do you know the default search directory for user static libraries? I opt not to use the trick of "-I" in ldLibs, if possible. – weidongxu Apr 16 '14 at 20:10

how does one explore/download the files listed here?: docs.google.com/… – Cliff Apr 26 '14 at 17:47

Found the example download but now I'm facing another issue w/ Gradle 1.11. The generated Androud.mk file uses absolute paths: stackoverflow.com/questions/23344567/… – Cliff Apr 28 '14 at 16:09

Thanks for the ldlibs tricking - I just found out that ldlibs are not kept in the order you type them in, which makes using multiple static libraries just about completely unusable. Unless they're "one" argument, after which it works. Awesome! – dascandy Jan 1 '15 at 22:15

2

This is the most detailed step-by-step introduction I've ever seen for ndk setup. Google should have hired you to rewrite all their documentations. – John Jul 15 '15 at 16:53

Thanks @John, nice of you to say. The closest interview to google I had was at Microsoft, but they told me I wasn't "the right fit for Microsoft" when I couldn't write a bubble sort algorithm on the board (who the frick would want to memorize that...). Actually, that was just 1 of 3 interviews, the other 2 offered me jobs, but I declined and started my own business. :) – reactive-core Oct 14 '15 at 18:49

@reactive-core, No wonder why Windows so fxxx up, they judge programmer by bubble sort algorithm! :) – John Oct 15 '15 at 7:17

add a comment

up vote

26

down vote

accepted

Found the answer. Including ndk.dir=path/to/ndk in the local.properties file did the trick.

Update: On the latest versions of Android Studio, you can set the value directly in the Project Structure > SDK location.

shareimprove this answer

edited Oct 8 '15 at 10:25

answered Dec 19 '13 at 7:13

user1906

1,1311920

Don't forget to accept your answer – orip Dec 23 '13 at 9:54

3

Is it a good idea to put something manually into the local.properties file, since it says "This file is automatically generated by Android Studio. Do not modify this file -- YOUR CHANGES WILL BE ERASED!" ?

从这对话中, 至少至少,都是能证明挺有料子的人。

OK,接下来,我也实验。

②项目中,有用到,信鸽,地图等一系列的.so文件。

我把armeabi的目录,只剩下腾讯x5内核的"liblbs.so"文件。用除了我手里的华为4A的,设备来安装apk, 非armeabi基础平台的设备,都能顺利加载x5内核。这是其次,最重要的是 armeabi目录删除的所有.so包的,功能存在。

结论:手机读取了对应手机平台的.so, 找不到"liblbs.so"的时候, 才去armeabi目录,找它。这样就很完美。符合提前提出的 疑问②。

①集成X5的APP, 第一次安装,多数手机是加载X5内核失败,取到sys core。

②back back 关闭应用,再打开仍然失败。要按 任务,“划掉“这个进程任务才成功。哎,这点,腾讯又不说,怎么做了。

① 启动 TBSDemo,等待几秒钟后看到提示框“x5内核安装成功,是否重启”,此时点击“重启” . 这句话是引用腾讯X5内核SDK接入文档(http://x5.tencent.com/doc?id=1003)

②重启体验不好吧,最后使用的方案是在 "关闭APP首页",时候彻底关闭这个进程。

@Override

public voidonBackPressed()

//是否新装应用、或者刚更新到本次版本的应用

booleanisFist4Video = SharePreferenceUtil.getBooleanDataByKey(this,"isFist4Video", true);

if(isFist4Video)

SharePreferenceUtil.saveBooleanDataToSharePreference(this,"isFist4Video", false);

android.os.Process.killProcess(android.os.Process.myPid());

super.onBackPressed();



super.onBackPressed(); 



③上述虽然解决了,第一次安装,不用关闭进程,而让用户back首页关闭应用而杀进程。然而体验并不是非常好。 (这玩意测试过,对是否有问题,没有影响。只是第二次就好)

合作伙伴

微信,手机QQ,QQ空间,京东58,同城,搜狐视频,新浪新闻

这些”合作伙伴“,别人都是安装完,就正常使用的?如何做到呢?朋友们,一起讨论哦。

以上是关于腾讯X5内核集成-解决遇到的问题(ABI平台匹配加载理解)的主要内容,如果未能解决你的问题,请参考以下文章

腾讯x5是啥?

集成腾讯TBS x5浏览器内核笔记

移动web时代已开启:腾讯X5内核浏览服务

腾讯X5浏览器内核静态集成方案

Ahjesus - Android Studio 最新版集成腾讯X5内核 TBS 必定成功

腾讯X5内核 语法不兼容问题