Build was MobSDK2 com.mob.sdk 接入ShareSDK报错解决

阅读 1

最近在接入ShareSDK时遇到一些问题,按照官方文档配置一番后,提示错误:

> Failed to apply plugin ’com.mob.sdk’.
   > Build was configured to prefer settings repositories over project repositories but repository ’MobSDK2’ was added by plugin ’com.mob.sdk’

解决步骤

1. 在项目Gradle文件中注册MobSDK

buildscript {
    repositories {
        google()
        mavenCentral()
        maven { url "https://jitpack.io" }
        // 1.添加MobSDK Maven地址
        maven { url "https://mvn.mob.com/android"}
    }
    dependencies {
        classpath ’com.android.tools.build:gradle:7.0.3’
        classpath ’org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.31’
        // 2.注册MobSDK
        classpath "com.mob.sdk:MobSDK:2018.0319.1724"
 
    }
}

2.在项目App Module的Gradle文件中添加插件和扩展

plugins {
    id ’com.android.application’
    id ’kotlin-android’
    id ’kotlin-kapt’
    id ’com.mob.sdk’
}
 
android {...}
 
dependencies {...}
 
MobSDK {
    appKey "YouAppKey"
    appSecret "YouAppSecret"
    ShareSDK {
        loopShare true
        devInfo {
            Wechat {
                appId "WxAppId"
                appSecret "WxAppSecret"
                bypassApproval false
                shortLinkConversationEnable true
                enable true
            }
        }
    }
}

3.在gradle.properties中添加代码

MobSDK.spEdition=FP

4.在settings.gradle中把

repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)

替换成

repositoriesMode.set(RepositoriesMode.PREFER_SETTINGS)

dependencyResolutionManagement {
    // repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
    // 替换成
    repositoriesMode.set(RepositoriesMode.PREFER_SETTINGS)
    repositories {
        google()
        mavenCentral()
        maven { url "https://jitpack.io" }
        // 注意这里一定要加仓库地址,不然会报 Failed to resolve: 
        // 添加MobSDK Maven地址
        maven { url "https://mvn.mob.com/android"}
    }
}
rootProject.name = "Demo"
include ’:app’

重新执行一下Sync Now即可

各位看官,如果你觉得本文不错,请支持一下~