一、下载依赖并复制到自己的项目中
shareSdk:https://github.com/MobClub/New-Unity-For-ShareSDK/tree/SourceCode
关于unity版本对应的插件选择方式

二、修改配置
这里分为两种情况:
图1(有base和launcher的gradle版本)

图2(只有一个maingradle的版本)
图1情况配置
修改launcherTemplate.gradle文件
apply plugin: 'com.android.application'dependencies {implementation project(':unityLibrary')}android {compileSdkVersion **APIVERSION**buildToolsVersion '**BUILDTOOLS**'compileOptions {sourceCompatibility JavaVersion.VERSION_1_8targetCompatibility JavaVersion.VERSION_1_8}//这里不要更改,否则无法读取unity设置中的配置defaultConfig {minSdkVersion **MINSDKVERSION**targetSdkVersion **TARGETSDKVERSION**applicationId '**APPLICATIONID**'ndk {abiFilters **ABIFILTERS**}versionCode **VERSIONCODE**versionName '**VERSIONNAME**'}aaptOptions {noCompress = ['.unity3d', '.ress', '.resource', '.obb'**STREAMING_ASSETS**]ignoreAssetsPattern = "!.svn:!.git:!.ds_store:!*.scc:.*:!CVS:!thumbs.db:!picasa.ini:!*~"}**SIGN**lintOptions {abortOnError false}//这里不要更改,否则无法读取unity设置中的配置buildTypes {debug {minifyEnabled **MINIFY_DEBUG**useProguard **PROGUARD_DEBUG**proguardFiles getDefaultProguardFile('proguard-android.txt')**SIGNCONFIG**jniDebuggable true}release {minifyEnabled **MINIFY_RELEASE**useProguard **PROGUARD_RELEASE**proguardFiles getDefaultProguardFile('proguard-android.txt')**SIGNCONFIG**}}**PACKAGING_OPTIONS****SPLITS****BUILT_APK_LOCATION**bundle {language {enableSplit = false}density {enableSplit = false}abi {enableSplit = true}}}**SPLITS_VERSION_CODE****LAUNCHER_SOURCE_BUILD_SETUP**// 下面是mob的配置apply plugin: 'com.mob.sdk'MobSDK {appKey "moba0b0c0d0"//这里改为自己的appKeyappSecret "5713f0d88511f9f4cf100cade0610a34"//这里改为自己的appSecretShareSDK {loopShare true//平台配置信息devInfo {//微信配置Wechat {id 4sortId 4appId "wx4868b35061f87885"appSecret "64020361b8ec4c99936c0e3999a9f249"userName "gh_afb25ac019c9"path "pages/index/index.html?id=1"withShareTicket trueminiprogramType 0bypassApproval falseenable true}//微信朋友圈配置,和上方微信的一致WechatMoments {id 5sortId 5appId "wx4868b35061f87885"appSecret "64020361b8ec4c99936c0e3999a9f249"bypassApproval falseenable true}//微信收藏配置,和上方微信的一致WechatFavorite {id 6sortId 6appId "wx4868b35061f87885"appSecret "64020361b8ec4c99936c0e3999a9f249"bypassApproval falseenable true}}}}// mob的配置结束
修改baseProjectTemplate.gradle文件
allprojects {buildscript {repositories {**ARTIFACTORYREPOSITORY**//添加mobSDK的maven库地址maven {url "http://mvn.mob.com/android"}google()jcenter()}dependencies {//这里的版本号是需要根据您unity设置的版本号变化的,具体设置见(附1)classpath 'com.android.tools.build:gradle:4.0.1'//添加mobSDK的classpathclasspath 'com.mob.sdk:MobSDK:+'}}repositories {**ARTIFACTORYREPOSITORY**//添加mobSDK的maven库地址maven {url "http://mvn.mob.com/android"}google()jcenter()flatDir {dirs "${project(':unityLibrary').projectDir}/libs"}}}task clean(type: Delete) {delete rootProject.buildDir}
图2情况
修改mainTemplate.gradle
buildscript {repositories {jcenter()google()}dependencies {classpath 'com.android.tools.build:gradle:3.4.0'// 注册MobSDKclasspath 'com.mob.sdk:MobSDK:2018.0319.1724'}}allprojects {repositories {jcenter()google()}}apply plugin: 'com.android.application'dependencies {implementation fileTree(dir: 'libs', include: ['*.jar'])implementation project(':ShareSDK')}android {compileSdkVersion **APIVERSION**buildToolsVersion '**BUILDTOOLS**'defaultConfig {minSdkVersion **MINSDKVERSION**targetSdkVersion **TARGETSDKVERSION**applicationId '**APPLICATIONID**'ndk {abiFilters **ABIFILTERS**}versionCode **VERSIONCODE**versionName '**VERSIONNAME**'}lintOptions {abortOnError false}aaptOptions {noCompress '.unity3d', '.ress', '.resource', '.obb'}buildTypes {debug {minifyEnabled **MINIFY_DEBUG**useProguard **PROGUARD_DEBUG**proguardFiles getDefaultProguardFile('proguard-android.txt')**SIGNCONFIG**jniDebuggable true}release {minifyEnabled **MINIFY_RELEASE**useProguard **PROGUARD_RELEASE**proguardFiles getDefaultProguardFile('proguard-android.txt')**SIGNCONFIG**}}**PACKAGING_OPTIONS****SPLITS**packagingOptions {doNotStrip '*/armeabi-v7a/*.so'}}// 下面是mob的配置apply plugin: 'com.mob.sdk'MobSDK {appKey "moba0b0c0d0"//这里改为自己的appKeyappSecret "5713f0d88511f9f4cf100cade0610a34"//这里改为自己的appSecretShareSDK {loopShare truedevInfo {SinaWeibo {appKey "568898243"appSecret "38a4f8204cc784f81f9f0daaf31e02e3"callbackUri "http://www.sharesdk.cn"}Wechat {appId "wx4868b35061f87885"appSecret "64020361b8ec4c99936c0e3999a9f249"withShareTicket truebypassApproval false}}}}// mob的配置结束
三、修改unity的配置
按图设置
如果只有一个Custom Gradle Template,就只勾选Custom Gradle Template就可以了



附1
gradle版本和插件版本要对应,具体可以查阅谷歌官方文档,下面附上截止至2021年01月23日的截图

下面讲解如何配置对应的版本
打开unity的设置如下位置

打开您unity如图所示的路径,如下图:

打开lib文件夹,找到gradle开头的jar,如下图;

可以看到这个是6.1.1的版本,这时我们去刚刚的那个谷歌官方文档找对应的版本应该是哪个,可以看到gradle6.1.1版本对应的插件版本是4.0.0+,所以这里写4.0.0或者写4.0.1就可以了。
例:如果您本地的gradle.jar是5.4.1,那么您baseProjectTemplate.gradle文件中gradle的插件版本就填写3.5.0到3.5.3中的值,比如添加3.5.1
