简体   繁体   English

在模拟器上测试时应用程序崩溃

[英]App is crashing when testing it on an emulator

I'm building an app and when I try to test it on an emulator its says unfortunately app has stopped so when I run it I get this errors from the logcat section,the app is static and contain contents without firebase or onesignal, and I run it on DroidX(Android 4.4.4,API 17)我正在构建一个应用程序,当我尝试在模拟器上测试它时,它说不幸的是应用程序已停止,所以当我运行它时,我从 logcat 部分收到此错误,该应用程序是静态的并且包含没有 firebase 或 onesignal 的内容,我在 DroidX(Android 4.4.4,API 17)上运行

Here is the error I get:这是我得到的错误:

07-29 05:28:00.753 2648-2648/com.tools.med E/Trace: error opening trace 
file: No such file or directory (2)
07-29 05:28:01.709 2648-2648/com.tools.med E/dalvikvm: Could not find 
class 'android.app.AppOpsManager', referenced from method 
com.google.android.gms.common.wrappers.PackageManagerWrapper.zzb
07-29 05:28:01.809 2648-2648/com.tools.med E/AndroidRuntime: FATAL 
  EXCEPTION: main
 java.lang.RuntimeException: Unable to get provider com.google.android.gms.ads.MobileAdsInitProvider: java.lang.IllegalStateException: 

******************************************************************************
* The Google Mobile Ads SDK was initialized incorrectly. AdMob publishers    *
* should follow the instructions here:                                       *
* https://googlemobileadssdk.page.link/admob-android-update-manifest         *
* to add a valid App ID inside the AndroidManifest.                          *
* Google Ad Manager publishers should follow instructions here:              *
* https://googlemobileadssdk.page.link/ad-manager-android-update-manifest.   *
******************************************************************************


    at android.app.ActivityThread.installProvider(ActivityThread.java:4850)
    at android.app.ActivityThread.installContentProviders(ActivityThread.java:4460)
    at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4400)
    at android.app.ActivityThread.access$1300(ActivityThread.java:141)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1294)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:137)
    at android.app.ActivityThread.main(ActivityThread.java:5069)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:511)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
    at dalvik.system.NativeStart.main(Native Method)
 Caused by: java.lang.IllegalStateException: 

******************************************************************************
* The Google Mobile Ads SDK was initialized incorrectly. AdMob publishers    *
* should follow the instructions here:                                       *
* https://googlemobileadssdk.page.link/admob-android-update-manifest         *
* to add a valid App ID inside the AndroidManifest.                          *
* Google Ad Manager publishers should follow instructions here:              *
* https://googlemobileadssdk.page.link/ad-manager-android-update-manifest.   *
******************************************************************************


    at com.google.android.gms.internal.ads.zzxb.attachInfo(com.google.android.gms:play-services-ads-lite@@18.1.1:27)
    at com.google.android.gms.ads.MobileAdsInitProvider.attachInfo(com.google.android.gms:play-services-ads-lite@@18.1.1:3)
    at android.app.ActivityThread.installProvider(ActivityThread.java:4847)
        ... 12 more

AndroidManifest安卓清单

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

<uses-permission android:name="android.permission.INTERNET"></uses-permission>
<application
    android:allowBackup="true"
    android:icon="@drawable/icon"
    android:label="@string/app_name"
    android:largeHeap="true"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">
    <activity android:name="com.tools.med.Splash">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity android:name="com.mkm.med.MainActivity"></activity>
    meta-data
    android:name="com.google.android.gms.ads.APPLICATION_ID"
    android:value="ca-app-pub-"/>
</application>

   apply plugin: 'com.android.application'

android {
   compileSdkVersion 28
    defaultConfig {
    applicationId "com.tools.med"
    minSdkVersion 16
    targetSdkVersion 28
    versionCode 1
    versionName "1.0"
    testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}

} }

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.1.0-rc01'
implementation 'androidx.constraintlayout:constraintlayout:2.0.0-beta2'
implementation 'com.google.android.ads.consent:consent-library:1.0.7'
testImplementation 'junit:junit:4.13-beta-3'
androidTestImplementation 'androidx.test:runner:1.3.0-alpha02'
implementation 'com.google.android.gms:play-services-ads:18.1.1'

androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0-alpha02'

} }

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

buildscript {构建脚本{

repositories {
    google()
    jcenter()
}
dependencies {
    classpath 'com.android.tools.build:gradle:3.4.2'
    classpath 'com.google.gms:google-services:4.2.0'


    // NOTE: Do not place your application dependencies here; they belong
    // in the individual module build.gradle files
}

} }

allprojects {
repositories {
    google()
    jcenter()
    maven {
        url "https://maven.google.com"
    }

}

} }

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

} }

Taken from the Link you got in the error Message ( googlemobileadssdk.page.link/admob-android-update-manifest) :取自错误消息中的链接(googlemobileadssdk.page.link/admob-android-update-manifest):

Update your AndroidManifest.xml Add your AdMob App ID to your app's AndroidManifest.xml file by adding the tag shown below.更新您的 AndroidManifest.xml 通过添加如下所示的标记,将您的 AdMob 应用 ID 添加到您应用的 AndroidManifest.xml 文件中。 You can find your App ID in the AdMob UI.您可以在 AdMob 用户界面中找到您的应用 ID。 For android:value insert your own AdMob App ID in quotes, as shown below.对于 android:value,请在引号中插入您自己的 AdMob 应用 ID,如下所示。

<manifest>
    <application>
        <!-- Sample AdMob App ID: ca-app-pub-3940256099942544~3347511713 -->
        <meta-data
            android:name="com.google.android.gms.ads.APPLICATION_ID"
            android:value="YOUR_ADMOB_APP_ID"/>
    </application>
</manifest>

Important: This step is required as of Google Mobile Ads SDK version 17.0.0.重要提示:从 Google 移动广告 SDK 17.0.0 版开始,此步骤是必需的。 Failure to add this tag results in a crash with the message: "The Google Mobile Ads SDK was initialized incorrectly."未能添加此标签会导致崩溃并显示以下消息:“Google 移动广告 SDK 初始化不正确。”

You miss the "<" before your meta-data Tag so These meta-data aren't recognized by your application.您错过了元数据标签之前的“<”,因此您的应用程序无法识别这些元数据。 I Guess you got an AdMob App ID but didn't post it, otherwise you Need an AdMob App ID.我猜你有一个 AdMob 应用 ID 但没有发布它,否则你需要一个 AdMob 应用 ID。

From the same link:从同一个链接:

Recommended: Create a Google AdMob account and register an app.

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM