The preface
I will not say more about the benefits of TBS, this article is about TBS static integration, if you want to dynamic integration, you can refer to my other article TBS Tencent browsing service access and encountered pits. The biggest disadvantage of static integration is that the package will be extremely large, which should add around 30 MB, if you don’t want to see my other article. Most partners want to integrate statically because sometimes the kernel will not download or load for some unknown reason, but if it is static it can definitely use the X5 kernel. I have a solution for this download loading problem in another article.
If you don’t want to read the following article, you can download my demo directly and run it directly. If you want to use it, copy the code inside me and you can use it directly. The Demo address
The preparatory work
Download two things, and I’ll explain them all. 1. Download the JAR package loaded by TBS. Static integration JAR download address. Extract code: 1898 2. Download the so file required by the kernel. Download address
Begin to integrate
After downloading the JAR package loaded by TBS, it should have the following name. Place the JAR package in the lib.In the build.gradle file, add the following configuration.
ndk {
abiFilters /*"armeabi",*/"armeabi-v7a"."x86"
}
Copy the code
sourceSets {
main {
jniLibs.srcDirs = ['libs']
java.srcDirs = ['src/main/java']}}Copy the code
implementation fileTree(include: ['*.jar'], dir: 'libs')
Copy the code
Create a new jniLibs and create an armeabi-v7a folder in it. As is shown in
Tbs_core_045434_20201214164517_nolog_fs_obfs_release. TBS = “zip”; If shown inCopy all the files in lib to armeabi-v7a.
The processing of this file is complete. All that’s left is code integration. Create a new class that integrates Application and initializes TBS in onCreate.
public class App extends Application {
@Override
public void onCreate(a) {
super.onCreate();
initTBS();
}
public void initTBS(a) {
QbSdk.preinstallStaticTbs(getApplicationContext());
QbSdk.setTbsListener(new TbsListener() {
@Override
public void onDownloadFinish(int i) {
If the download is successful, the errorCode is 100. If the download is successful, the errorCode is 100. If the download is successful, the errorCode is 100
Log.i("QbSdk"."OnDownloadFinish --> Download X5 kernel completed:" + i);
Log.i("QbSdk"."OnDownloadFinish -- Can YOU load the X5 kernel?" + QbSdk.canLoadX5(App.this));
}
@Override
public void onInstallFinish(int i) {
If the installation is successful, the errorCode is 200. If the installation is successful, the errorCode is 200. If the installation is successful, the errorCode is 200
Log.i("QbSdk"."OnInstallFinish --> X5 installation progress:" + i);
Log.i("QbSdk"."OnInstallFinish -- Can you load the X5 kernel?" + QbSdk.canLoadX5(App.this));
}
@Override
public void onDownloadProgress(int i) {
// Download process notification, providing the current download progress [0-100]
Log.i("QbSdk"."OnDownloadProgress --> Download X5 kernel progress:" + i);
Log.i("QbSdk"."OnDownloadProgress -- Can YOU load the X5 kernel?" + QbSdk.canLoadX5(App.this)); }}); QbSdk.PreInitCallback cb =new QbSdk.PreInitCallback() {
@Override
public void onCoreInitFinished(a) {
// The kernel is initialized
Log.i("QbSdk"."onCoreInitFinished ");
Log.i("QbSdk"."OnCoreInitFinished - Whether the X5 kernel can be loaded:" + QbSdk.canLoadX5(App.this));
}
@Override
public void onViewInitFinished(boolean arg0) {
Table x5 is successfully loaded. If table x5 fails to load, the system will automatically switch to the system kernel.
Log.i("QbSdk"."Kernel loading" + arg0);
Log.i("QbSdk"."OnViewInitFinished -- Can I load the X5 kernel?" + QbSdk.canLoadX5(App.this)); }};// X5 kernel initializes the interfaceQbSdk.initX5Environment(getApplicationContext(), cb); }}Copy the code
Remember to add the name to AndroidManifest.
<? xml version="1.0" encoding="utf-8"? > <manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.jackfruit.tbslocalwebview"> <! -- Writes to the extension storage, writes data to the extension card --> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/ > <! --> <uses-permission android:name="android.permission.INTERNET"/ > <! -- Get operator information, used to support the interface that provides operator information --> <uses-permission Android :name="android.permission.ACCESS_NETWORK_STATE" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:name=".App"
android:usesCleartextTraffic="true"
android:theme="@style/Theme.TBSLocalWebview"
>
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".TBSDebugWebActivity" />
<activity android:name=".PreviewAttachmentActivity" />
</application>
</manifest>
Copy the code
One thing to remember is that these permissions must be added. Otherwise it won’t work. This is where you can use the kernel. In my demo, I have logged to check whether the log load is successful. You can check whether the log load is complete. Filter criteria enter QbSdk.
The Demo address
Now explain the two addresses you downloaded. The first is the JAR package for TBS to load the kernel. That is the last statically loaded version, which can be downloaded directly. The second is the kernel’s so file, which can be obtained this way. Use webView to open debugtbs.qq.com
This is the page to open, but I found that ordinary WebView can not open this address, the page said is not x5 kernel, can not open. So here’s what you can do. Let’s start with my other paperTBS Tencent browsing service access and encountered pitsOpen that page. Then click install line kernel.
You can look at this address at the printer’s desk. Kernel download address
I have an example of opening a file in my demo, using TbsReaderView. Can open PDF, DOCx and other files. That’s it. Finally, the demo address is attached again, which contains static and dynamic integration TBS.
Integrated Demo Address
Welcome to subscribe to my blog, persistence will always see the light.