BillingClient和PurchasesUpdateListener类不可用

问题描述

我正在尝试按以下说明添加应用内结算: https://developer.android.com/google/play/billing/integrate 并认为我已经按照说明设置了依赖项,但是仍然无法使用页面上的代码示例中的BillingClient和PurchasesUpdateListener类。

我的项目的build.gradle:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 28
    buildToolsversion '29.0.2'

    defaultConfig {
        applicationId "com.myproject"
        minSdkVersion 17
        targetSdkVersion 26
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'),'proguard-rules.txt'
        }
    }
}
android {
    useLibrary 'org.apache.http.legacy'
}
dependencies {   
    implementation 'com.google.android.gms:play-services-ads:19.5.0'
    implementation 'com.android.billingclient:billing:3.0.1'
}

我的顶级build.gradle:

buildscript {
    repositories {
        jcenter()
        google()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:4.1.0'
    }
}

allprojects {
    repositories {
        jcenter()
        google()
    }
}

该如何解决

解决方法

按如下所示更改全局build.gradle可以帮助我解决缺少的依赖项:

buildscript {
    repositories {
        jcenter()
        google()

    mavenLocal()
    mavenCentral()
    maven { url "http://oss.sonatype.org/content/repositories/snapshots/" }
    maven { url "http://oss.sonatype.org/content/repositories/releases/" }
    maven { url "https://maven.springframework.org/release" }
    maven { url "https://maven.restlet.com" }
    maven { url "https://jcenter.bintray.com" }
    jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:4.1.0'


    }
}

allprojects {
    repositories {
        jcenter()
        google()
    }
}

希望这对某人有帮助。