本篇分享在线客服系统海豚客服如何进行安卓SDK的接入,首先请点击下载SDK包:“dolphin_lib-release.aar”
一.将最小编译版本修改为17或者以上,通常在主module(通常名字为“app”)下gradle文件内添加或者修改,如
android {
compileSdkVersion 30
buildToolsVersion "30.0.3"
defaultConfig {
applicationId "com.example.dolphin_sdk_demo"
minSdkVersion 17
targetSdkVersion 30
versionCode 1
versionName "1.0"
}
}
二.项目根节点下的gradle文件内添加如下代码
flatDir {
dirs 'libs'
}
并在allprojects内repositories内添加
maven {
url "https://jitpack.io" }
本文档附上具体添加位置如下
allprojects {
repositories {
flatDir {
dirs 'libs'
}
maven {
url "https://jitpack.io" }
maven {
url 'http://maven.aliyun.com/nexus/content/groups/public/' }
maven {
url 'http://maven.aliyun.com/nexus/content/repositories/jcenter' }
maven {
url 'http://maven.aliyun.com/nexus/content/repositories/google' }
maven {
url 'http://maven.aliyun.com/nexus/content/repositories/gradle-plugin' }
}
}
三.将下载好的本SDK的aar包放到主module下libs目录下,目录索引如图
四.主module下gradle文件内添加依赖以导入aar包,如下
implementation(name: 'dolphin_lib-release', ext: 'aar')
五.除了添加aar包的依赖外,还要添加SDK所需依赖,成功运行SDK需要以下所有依赖,如果本身的项目里已经有其中部分依赖,则保留最新版本而去掉其他低版本
dependencies {
implementation(name: 'dolphin_lib-release', ext: 'aar')
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'com.google.android.material:material:1.2.1'
implementation 'androidx.constraintlayout:constraintlayout:2.0.2'
//Glide
implementation 'com.github.bumptech.glide:glide:4.11.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.11.0'
implementation 'com.github.bumptech.glide:okhttp3-integration:4.11.0'
//EventBus
implementation 'org.greenrobot:eventbus:3.0.0'
//dagger-rxjava2-retrofit2-okhttp3
implementation 'com.google.dagger:dagger:2.23.2'
annotationProcessor 'com.google.dagger:dagger-compiler:2.23.2'
implementation 'io.reactivex.rxjava2:rxjava:2.2.5'
implementation 'io.reactivex.rxjava2:rxandroid:2.0.2'
implementation 'com.squareup.retrofit2:retrofit:2.6.0'
implementation 'com.squareup.retrofit2:adapter-rxjava2:2.6.0'
implementation 'com.squareup.retrofit2:converter-gson:2.6.0'
implementation 'com.trello.rxlifecycle2:rxlifecycle-android:2.2.2'
implementation 'com.trello.rxlifecycle2:rxlifecycle-components:2.2.2'
implementation 'com.squareup.okhttp3:okhttp:3.12.1'
//单Activity+多Fragment
implementation 'me.yokeyword:fragmentationx:1.0.2'
implementation 'me.yokeyword:fragmentationx-swipeback:1.0.2'
implementation 'me.yokeyword:eventbus-activity-scope:1.1.0'
//WebSocket收发消息
implementation 'org.java-websocket:Java-WebSocket:1.3.6'
api 'com.github.NaikSoftware:StompProtocolAndroid:1.6.4'
}
六.清单配置文件AndroidManifest.xml中添加权限、相关Activity和Service注册以及其他设置,如下:
1.权限(manifest节点下添加,不需要代码动态申请,因为SDK内已经有此类逻辑了)
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<!-- SDCard读写数据权限 -->
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<!-- 系统照相机拍照 -->
<uses-permission android:name="android.permission.CAMERA" />
2.AndroidManifest.xml中application节点设置属性
android:allowBackup="true"
android:requestLegacyExternalStorage="true"
android:supportsRtl="true"
具体位置如下图
3.AndroidManifest.xml中application节点下添加以下代码(SDK所需Activity与Service注册以及其他数据)
<service
android:name="com.yiju.dolphin_lib.service.MsgService"
android:enabled="true"
android:exported="true" />
<activity
android:name="com.yiju.dolphin_lib.pages.activity.SessionActivity"
android:exported="true"
android:launchMode="singleTask"
android:screenOrientation="portrait"
android:theme="@style/Lib_MainActivityTheme"
android:windowSoftInputMode="adjustResize|stateHidden" />
<activity
android:name="com.yiju.dolphin_lib.pages.activity.MediaActivity"
android:launchMode="singleTop"
android:theme="@style/Lib_MediaActivityTheme" />
<activity
android:name="com.yiju.common.crop.CropImageActivity"
android:theme="@style/Theme.MaterialComponents.Light.NoActionBar" />
<!-- 添加使用Apache HTTP client库,兼容安卓P -->
<uses-library
android:name="org.apache.http.legacy"
android:required="false" />
<provider
android:name="androidx.core.content.FileProvider"
android:authorities="${applicationId}.android7.fileprovider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/file_paths" />
</provider>
4.兼容安卓7.0以上uri权限的配置
主module下res目录下添加xml目录&#