如何在我的应用中添加Admob(找不到方法实现)

时间:2018-08-26 14:03:07

标签: android admob

这是我的应用Gradle

buildscript {
ext.kotlin_version = '1.2.60'
repositories {
    maven { url 'https://maven.fabric.io/public' }
    mavenCentral()
}

dependencies {
    classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    classpath 'io.fabric.tools:gradle:1.25.4'
    implementation 'com.google.android.gms:play-services-ads:15.0.0'
}
}
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'io.fabric'

repositories {
    maven { url 'https://maven.fabric.io/public' }
}

android {
    compileSdkVersion 28
    buildToolsVersion '27.0.3'
    defaultConfig {
        applicationId "knf.kuma"
        minSdkVersion 21
        targetSdkVersion 28
        versionCode 59
        versionName "1.9.2"
        multiDexEnabled true
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        javaCompileOptions {
            annotationProcessorOptions {
                arguments = ["room.schemaLocation":
                                     "$projectDir/schemas".toString()]
            }
        }
    }
    buildTypes {
        release {
            minifyEnabled true
            shrinkResources true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro', 'proguard-android.txt'
        }
    }
    sourceSets {
        androidTest.assets.srcDirs +=
                files("$projectDir/schemas".toString())
    }
    compileOptions {
        sourceCompatibility = '1.8'
        targetCompatibility = '1.8'
    }
}

configurations.all {
    resolutionStrategy {
        force 'org.jsoup:jsoup:1.10.3'
    }
}

allprojects {
    repositories {
        maven { url "https://jitpack.io" }
        maven { url 'https://oss.sonatype.org/content/repositories/snapshots/' }
        maven { url "https://s3.amazonaws.com/repo.commonsware.com" }
    }
}

dependencies {
    //implementation project(path:':multidisplaycast', configuration:'default')
    implementation fileTree(include: ['*.jar', '*.aar'], dir: 'libs')
    implementation 'androidx.appcompat:appcompat:1.0.0-rc01'
    implementation 'androidx.preference:preference:1.0.0-rc01'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.2'
    implementation 'androidx.legacy:legacy-support-v4:1.0.0-rc01'
    implementation 'com.google.android.material:material:1.0.0-rc01'
    implementation 'androidx.vectordrawable:vectordrawable-animated:1.0.0-rc01'
    implementation 'androidx.cardview:cardview:1.0.0-rc01'
    implementation 'androidx.mediarouter:mediarouter:1.0.0-beta01'
    implementation 'androidx.recyclerview:recyclerview:1.0.0-rc01'
    implementation 'androidx.leanback:leanback:1.0.0-rc01'
    implementation 'androidx.palette:palette:1.0.0-rc01'
    implementation 'com.google.android.gms:play-services-cast:16.0.1'
    implementation 'com.google.android.gms:play-services-drive:15.0.1'
    implementation 'com.google.android.gms:play-services-auth:16.0.0'
    implementation 'com.google.firebase:firebase-core:16.0.1'
    implementation 'androidx.lifecycle:lifecycle-extensions:2.0.0-rc01'
    implementation 'androidx.lifecycle:lifecycle-runtime:2.0.0-rc01'
    implementation 'com.google.android.gms:play-services-maps:15.0.1'
    implementation 'androidx.annotation:annotation:1.0.0-rc01'
    implementation 'androidx.slice:slice-builders:1.0.0-rc01'
    implementation 'com.google.android.gms:play-services-ads:12.0.1'
    annotationProcessor 'androidx.lifecycle:lifecycle-compiler:2.0.0-rc01'
    implementation 'androidx.room:room-runtime:2.0.0-rc01'
    annotationProcessor 'androidx.room:room-compiler:2.0.0-rc01'
    androidTestImplementation 'androidx.room:room-testing:2.0.0-rc01'
    implementation 'com.google.dagger:dagger-android-support:2.16'
    annotationProcessor 'com.google.dagger:dagger-android-processor:2.16'
    implementation 'androidx.paging:paging-runtime:2.0.0-rc01'
    implementation 'com.jakewharton:butterknife:9.0.0-SNAPSHOT'
    annotationProcessor 'com.jakewharton:butterknife-compiler:9.0.0-SNAPSHOT'
    implementation 'pl.droidsonroids:jspoon:1.2.2'
    implementation 'pl.droidsonroids.retrofit2:converter-jspoon:1.2.2'
    implementation 'org.jsoup:jsoup:1.10.3'
    implementation 'com.squareup.retrofit2:adapter-rxjava2:2.3.0'
    implementation 'com.squareup.picasso:picasso:2.5.2'
    implementation 'com.jakewharton.picasso:picasso2-okhttp3-downloader:1.1.0'
    implementation 'com.beloo.widget:ChipsLayoutManager:0.3.7@aar'
    implementation 'com.google.code.gson:gson:2.8.5'
    implementation 'me.zhanghai.android.materialratingbar:library:1.1.1'
    implementation 'at.blogc:expandabletextview:1.0.5'
    implementation 'com.evernote:android-job:1.2.1'
    implementation 'com.pavelsikun:material-seekbar-preference:2.3.0'
    implementation 'org.cryse.widget:persistentsearchview:1.0.4@aar'
    implementation 'com.google.android.exoplayer:exoplayer-core:2.7.0'
    implementation 'com.google.android.exoplayer:exoplayer-ui:2.7.0'
    implementation "com.google.android.exoplayer:extension-mediasession:2.7.0"
    implementation 'com.afollestad.material-dialogs:core:0.9.6.0'
    implementation 'com.shamanland:xdroid-toaster:0.3.0'
    implementation 'com.github.MFlisar:DragSelectRecyclerView:0.3'
    implementation 'com.mani:ThinDownloadManager:1.4.0'
    implementation 'com.github.StephenVinouze:MaterialNumberPicker:1.0.5'
    implementation 'org.nanohttpd:nanohttpd:2.3.1'
    implementation 'com.dropbox.core:dropbox-core-sdk:3.0.8'
    implementation 'com.github.daniel-stoneuk:material-about-library:2.2.5'
    implementation 'io.github.luizgrp.sectionedrecyclerviewadapter:sectionedrecyclerviewadapter:1.2.0'
    implementation 'nl.dionsegijn:konfetti:1.1.2'
    implementation 'me.zhanghai.android.materialprogressbar:library:1.4.2'
    implementation 'com.github.bumptech.glide:glide:4.7.1'
    implementation 'com.tonyodev.fetch2:fetch2:2.2.0-RC3'
    implementation 'com.tonyodev.fetch2okhttp:fetch2okhttp:2.2.0-RC3'
    implementation 'q.rorbin:badgeview:1.1.3'
    implementation 'com.jaredrummler:android-device-names:1.1.7'
    annotationProcessor 'com.github.bumptech.glide:compiler:4.7.1'
    testImplementation 'junit:junit:4.12'
    implementation 'org.jetbrains.kotlin:kotlin-stdlib:1.2.60'
    androidTestImplementation 'androidx.test:runner:1.1.0-alpha4'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0-alpha4'
    debugImplementation 'com.amitshekhar.android:debug-db:1.0.4'
    implementation('com.crashlytics.sdk.android:crashlytics:2.9.4@aar') {
        transitive = true
    }
    implementation('com.crashlytics.sdk.android:answers:1.4.1@aar') {
        transitive = true
    }
    implementation('io.branch.sdk.android:library:2.17.1@aar') {
        transitive = true
    }
}
apply plugin: 'com.google.gms.google-services'

这是我的Gradle项目

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        google()
        jcenter()
        maven {
            url "https://maven.google.com"
        }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.3.0-alpha06'
        classpath 'com.google.gms:google-services:4.0.1'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

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

task clean(type: Delete) {
    delete rootProject.buildDir
}

这是我的AndroidManifest

<?xml version="1.0" encoding="utf-8"?>

<uses-feature
    android:name="android.software.leanback"
    android:required="false"/>
<uses-feature
    android:name="android.hardware.touchscreen"
    android:required="false"/>
<uses-feature
    android:name="android.hardware.microphone"
    android:required="false"/>

<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES"/>
<uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>

<application
    android:name=".App"
    android:allowBackup="true"
    android:banner="@drawable/tv_banner"
    android:fullBackupContent="@xml/backup_descriptor"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:resizeableActivity="true"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">
    <activity
        android:name=".Main"
        android:label="@string/title_activity_main"
        android:theme="@style/AppTheme.NoActionBar">
        <intent-filter>
            <action android:name="android.intent.action.MAIN"/>

            <category android:name="android.intent.category.LAUNCHER"/>
        </intent-filter>
        <intent-filter android:label="@string/app_name">
            <action android:name="android.intent.action.VIEW"/>

            <category android:name="android.intent.category.BROWSABLE"/>
            <category android:name="android.intent.category.DEFAULT"/>

            <data
                android:host="ukiku.ga"
                android:pathPrefix="/*"
                android:scheme="http"/>
            <data
                android:host="ukiku.ga"
                android:pathPrefix="/*"
                android:scheme="https"/>
            <data
                android:host="ukiku.ga"
                android:pathPrefix="/get.php"
                android:scheme="http"/>
            <data
                android:host="ukiku.ga"
                android:pathPrefix="/get.php"
                android:scheme="https"/>
        </intent-filter>
        <intent-filter>
            <data
                android:host="open"
                android:scheme="ukiku"/>

            <action android:name="android.intent.action.VIEW"/>

            <category android:name="android.intent.category.DEFAULT"/>
            <category android:name="android.intent.category.BROWSABLE"/>
        </intent-filter>

        <meta-data
            android:name="android.app.shortcuts"
            android:resource="@xml/shortcuts"/>
    </activity>
    <activity
        android:name=".tv.ui.TVMain"
        android:banner="@drawable/tv_banner"
        android:screenOrientation="landscape"
        android:theme="@style/AppTheme.TV.Browser">
        <intent-filter>
            <action android:name="android.intent.action.MAIN"/>

            <category android:name="android.intent.category.LEANBACK_LAUNCHER"/>
        </intent-filter>
    </activity>
    <activity
        android:name=".animeinfo.ActivityAnime"
        android:theme="@style/AppTheme.NoActionBar"
        android:windowSoftInputMode="stateHidden">
        <intent-filter android:label="@string/app_name">
            <action android:name="android.intent.action.VIEW"/>

            <category android:name="android.intent.category.BROWSABLE"/>
            <category android:name="android.intent.category.DEFAULT"/>

            <data
                android:host="animeflv.net"
                android:pathPrefix="/anime/"
                android:scheme="https"/>
        </intent-filter>
    </activity>
    <activity
        android:name=".player.CustomExoPlayer"
        android:configChanges="screenSize|smallestScreenSize|screenLayout|orientation"
        android:immersive="true"
        android:launchMode="singleTask"
        android:resizeableActivity="true"
        android:screenOrientation="sensorLandscape"
        android:supportsPictureInPicture="true"/>
    <activity
        android:name=".animeinfo.ActivityImgFull"
        android:theme="@style/AppTheme.FullScreen"/>
    <activity android:name=".record.RecordActivity"/>
    <activity android:name=".seeing.SeeingActivity"/>
    <activity android:name=".emision.EmisionActivity"/>
    <activity android:name=".explorer.ExplorerActivity"/>
    <activity
        android:name=".updater.UpdateActivity"
        android:excludeFromRecents="true"/>
    <activity android:name=".random.RandomActivity"/>
    <activity android:name=".changelog.ChangelogActivity"/>
    <activity
        android:name=".backup.BackUpActivity"
        android:screenOrientation="portrait"
        android:theme="@style/AppTheme.Translucent"/>
    <activity
        android:name="com.dropbox.core.android.AuthActivity"
        android:configChanges="orientation|keyboard"
        android:launchMode="singleTask">
        <intent-filter>
            <data android:scheme="db-qtjow4hsk06vt19"/>

            <action android:name="android.intent.action.VIEW"/>

            <category android:name="android.intent.category.BROWSABLE"/>
            <category android:name="android.intent.category.DEFAULT"/>
        </intent-filter>
    </activity>
    <activity
        android:name=".backup.MigrationActivity"
        android:theme="@style/AppTheme.Translucent"/>
    <activity
        android:name=".AppInfo"
        android:theme="@style/AppTheme.AppInfo"/>
    <activity android:name=".recommended.RecommendActivity"/>
    <activity android:name=".recommended.RankingActivity"/>
    <activity android:name=".search.GenreActivity"/>

    <service android:name=".directory.DirectoryService"/>
    <service android:name=".directory.DirectoryUpdateService"/>
    <service android:name=".download.DownloadService"/>
    <service
        android:name=".widgets.emision.WEmisionService"
        android:permission="android.permission.BIND_REMOTEVIEWS"/>
    <service android:name=".download.DownloadManager"/>

    <receiver
        android:name=".widgets.emision.WEmisionProvider"
        android:label="Emisión">
        <intent-filter>
            <action android:name="android.appwidget.action.APPWIDGET_UPDATE"/>
        </intent-filter>

        <meta-data
            android:name="android.appwidget.provider"
            android:resource="@xml/widget_emision"/>
    </receiver>
    <receiver android:name=".download.DownloadReceiver"/>
    <receiver android:name=".recents.RecentsNotReceiver"/>
    <receiver android:name=".slices.AnimeLoad"/>

    <provider
        android:name="androidx.core.content.FileProvider"
        android:authorities="knf.kuma.fileprovider"
        android:exported="false"
        android:grantUriPermissions="true">
        <meta-data
            android:name="android.support.FILE_PROVIDER_PATHS"
            android:resource="@xml/path_providers"/>
    </provider>

    <meta-data
        android:name="io.fabric.ApiKey"
        android:value="8971b3733a2fd699ebd101e18ce228d80baeab92"/>
    <meta-data
        android:name="com.google.android.geo.API_KEY"
        android:value="@string/google_maps_key"/>

    <activity
        android:name=".commons.EAMActivity"
        android:label="@string/title_activity_eam">
    </activity>
    <activity android:name=".queue.QueueActivity"/>
    <activity
        android:name=".tv.streaming.TVServerSelection"
        android:theme="@style/AppTheme.TV.Guided"/>
    <activity
        android:name=".tv.exoplayer.TVPlayer"
        android:theme="@style/AppTheme.TV.Base"/>
    <activity
        android:name=".tv.details.TVAnimesDetails"
        android:theme="@style/AppTheme.TV.Details"/>
    <activity
        android:name=".tv.search.TVSearch"
        android:theme="@style/AppTheme.TV.Base"/>
    <activity android:name=".commons.BypassUtil"/>
    <activity
        android:name=".download.DownloadDialogActivity"
        android:excludeFromRecents="true"
        android:theme="@style/Theme.AppCompat.DayNight.Dialog">
        <intent-filter android:label="@string/app_name">
            <action android:name="android.intent.action.VIEW"/>

            <category android:name="android.intent.category.BROWSABLE"/>
            <category android:name="android.intent.category.DEFAULT"/>

            <data
                android:host="animeflv.net"
                android:pathPrefix="/ver/"
                android:scheme="https"/>
            <data
                android:host="animeflv.net"
                android:pathPrefix="/ver/"
                android:scheme="http"/>
        </intent-filter>
    </activity>
    <activity
        android:name=".player.VideoActivity"
        android:configChanges="screenSize|smallestScreenSize|screenLayout|orientation"
        android:immersive="true"
        android:launchMode="singleTask"
        android:resizeableActivity="true"
        android:screenOrientation="sensorLandscape"
        android:supportsPictureInPicture="true"/>

    <provider
        android:name=".slices.AnimeSlice"
        android:authorities="knf.kuma.slices"
        android:exported="true">
        <intent-filter>
            <action android:name="android.intent.action.VIEW"/>

            <category android:name="android.app.slice.category.SLICE"/>

            <data
                android:host="knf"
                android:pathPrefix="/"
                android:scheme="http"/>
        </intent-filter>
    </provider>

    <uses-library
        android:name="org.apache.http.legacy"
        android:required="false"/>
</application>

这是活动

   package knf.kuma.recents;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.lifecycle.ViewModelProviders;
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
import knf.kuma.BottomFragment;
import knf.kuma.R;
import knf.kuma.commons.EAHelper;
import knf.kuma.commons.Network;
import knf.kuma.recents.viewholders.RecyclerRefreshHolder;
import com.google.android.gms.ads.MobileAds;
import com.google.android.gms.ads.MobileAds;
import com.google.android.gms.ads.MobileAds;

public class RecentFragment extends BottomFragment implements SwipeRefreshLayout.OnRefreshListener {
    private RecentsViewModel viewModel;
    private RecyclerRefreshHolder holder;
    private RecentsAdapter adapter;

    @NonNull
    public static RecentFragment get() {
        return new RecentFragment();
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        viewModel = ViewModelProviders.of(this).get(RecentsViewModel.class);
        viewModel.getDBLiveData().observe(this, objects -> {
            if (objects != null) {
                holder.setError(objects.size() == 0);
                holder.setRefreshing(false);
                adapter.updateList(objects);
            }
        });
        updateList();
    }

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.recycler_refresh_fragment, container, false);
        holder = new RecyclerRefreshHolder(view);
        holder.refreshLayout.setOnRefreshListener(this);
        adapter = new RecentsAdapter(this, holder.recyclerView);
        holder.recyclerView.setAdapter(adapter);
        holder.setRefreshing(true);
        EAHelper.enter1("R");
        return view;
    }

    @Override
    public void onRefresh() {
        updateList();
    }

    private void updateList() {
        if (!Network.isConnected()) {
            holder.setRefreshing(false);
        } else {
            viewModel.reload(getContext());
        }
    }

    @Override
    public void onReselect() {
        EAHelper.enter1("R");
        if (holder != null) holder.scrollToTop();
    }
}

在放置implementation 'com.google.android.gms:play-services-ads:15.0.0'之后发生异常时,出现此错误消息“对象上的参数[com.google.android.gms:play-services-ads:15.0.0]找不到方法Implementation()类型为org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler。” 为什么?预先,非常感谢您的帮助。

0 个答案:

没有答案