我尝试使用'App-id'和'添加单位ID'以及签名APK上的实际ID进行测试。 添加不会同时出现。 我在logcat中发出警告:
10-10 15:17:53.308 6601-7082/com.babygameseeepe.shreyak.babygames W/Ads: Invoke Firebase method getInstance error.
java.lang.ClassNotFoundException: Didn't find class "com.google.android.gms.measurement.AppMeasurement" on path: DexPathList[[zip file "/data/app/com.babygameseeepe.shreyak.babygames-1/base.apk"],nativeLibraryDirectories=[/data/app/com.babygameseeepe.shreyak.babygames-1/lib/arm, /vendor/lib, /system/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
at com.google.android.gms.ads.internal.scionintegration.b.a(:com.google.android.gms.DynamiteModulesA@11518438:167)
... 13 more
这是我的实施:
protected void onCreate(Bundle savedInstanceState) {
--
--
MobileAds.initialize(this, "~My-App-Id~");
mAdView = (AdView) findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder().build();
mAdView.loadAd(adRequest);
}
在xml中:
<com.google.android.gms.ads.AdView
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:id="@+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true"
ads:adSize="BANNER"
ads:adUnitId="~My-add-unit-id~">
</com.google.android.gms.ads.AdView>
权限:
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
Gradle(项目级别):
allprojects {
repositories {
jcenter()
maven {
url "https://maven.google.com"
}
}
}
Gradle(应用级别):
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion "26.0.2"
defaultConfig {
applicationId "com.babygameseeepe.shreyak.babygames"
minSdkVersion 15
targetSdkVersion 25
versionCode 5
versionName "1.4.2"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
compile 'com.google.android.gms:play-services-ads:11.4.0'
testCompile 'junit:junit:4.12'
}
我已按照this链接实现了添加(没有firebase)。请帮忙。
答案 0 :(得分:0)
在 App Gradle
中添加此代码
defaultConfig {
...
// Enabling multidex support.
multiDexEnabled true
}
转到Build
选项
Clean Project
Rebuild Project
。 这样可行。
如果它不起作用。在 App Gradle
的末尾添加这些代码
dependencies {
//All your dependencies
}
configurations.all {
resolutionStrategy.eachDependency { DependencyResolveDetails details ->
def requested = details.requested
if (requested.group == 'com.android.support') {
if (!requested.name.startsWith("multidex")) {
details.useVersion '26.+'
}
}
}
}
答案 1 :(得分:-1)
我认为错误不在您的代码中,而是在您的xml文件中,