当前位置: 首页 > 知识库问答 >
问题:

无法用flutter项目在测试设备(仿真器)上加载测试ads

赫连照
2023-03-14

输出控制台

Launching lib\main.dart on Android SDK built for x86 in debug mode...
Initializing gradle...
Resolving dependencies...
Running Gradle task 'assembleDebug'...
registerResGeneratingTask is deprecated, use registerGeneratedResFolders(FileCollection)
registerResGeneratingTask is deprecated, use registerGeneratedResFolders(FileCollection)
registerResGeneratingTask is deprecated, use registerGeneratedResFolders(FileCollection)
registerResGeneratingTask is deprecated, use registerGeneratedResFolders(FileCollection)
registerResGeneratingTask is deprecated, use registerGeneratedResFolders(FileCollection)
Built build\app\outputs\apk\debug\app-debug.apk.
D/NetworkSecurityConfig(17748): No Network Security Config specified, using platform default
I/WebViewFactory(17748): Loading com.android.chrome version 69.0.3497.100 (code 349710017)
I/jokes.jokespun(17748): The ClassLoaderContext is a special shared library.
I/jokes.jokespun(17748): The ClassLoaderContext is a special shared library.
Syncing files to device Android SDK built for x86...
I/jokes.jokespun(17748): Background concurrent copying GC freed 14545(2MB) AllocSpace objects, 9(176KB) LOS objects, 50% free, 1808KB/3MB, paused 5.468ms total 87.502ms
I/cr_LibraryLoader(17748): Time to load native libraries: 19 ms (timestamps 870-889)
I/chromium(17748): [INFO:library_loader_hooks.cc(36)] Chromium logging enabled: level = 0, default verbosity = 0
I/cr_LibraryLoader(17748): Expected native library version number "69.0.3497.100", actual native library version number "69.0.3497.100"
W/cr_ChildProcLH(17748): Create a new ChildConnectionAllocator with package name = com.android.chrome, sandboxed = true
I/cr_BrowserStartup(17748): Initializing chromium process, singleProcess=false
I/chromium(17748): [INFO:aw_field_trial_creator.cc(54)] First-WebView-Experiment not found
I/FA      (17748): Tag Manager is not found and thus will not be used
I/OpenGLRenderer(17748): Initialized EGL, version 1.4
D/OpenGLRenderer(17748): Swap behavior 1
D/        (17748): HostConnection::get() New Host Connection established 0xc27781c0, tid 17839
W/OpenGLRenderer(17748): Failed to choose config with EGL_SWAP_BEHAVIOR_PRESERVED, retrying without...
D/OpenGLRenderer(17748): Swap behavior 0
D/EGL_emulation(17748): eglCreateContext: 0xe06ee060: maj 3 min 0 rcv 3
W/jokes.jokespun(17748): Accessing hidden field Ljava/nio/Buffer;->address:J (light greylist, reflection)
D/EGL_emulation(17748): eglMakeCurrent: 0xe06ee060: ver 3 0 (tinfo 0xc2737970)
D/EGL_emulation(17748): eglCreateContext: 0xe06eed20: maj 3 min 0 rcv 3
D/EGL_emulation(17748): eglMakeCurrent: 0xe06eed20: ver 3 0 (tinfo 0xe076e4e0)
V/FA      (17748): Deferring to Google Analytics for Firebase for event data collection.
D/DynamitePackage(17748): Instantiating com.google.android.gms.ads.ChimeraMobileAdsSettingManagerCreatorImpl
I/DynamiteModule(17748): Considering local module com.google.android.gms.ads.dynamite:0 and remote module com.google.android.gms.ads.dynamite:11140
I/DynamiteModule(17748): Selected remote version of com.google.android.gms.ads.dynamite, version >= 11140
V/DynamiteModule(17748): Dynamite loader version >= 2, using loadModule2NoCrashUtils
D/DynamitePackage(17748): Instantiating com.google.android.gms.ads.ChimeraAdManagerCreatorImpl
I/Ads     (17748): Starting ad request.
I/Ads     (17748): SDK version: afma-sdk-a-v15090040.14300000.1
I/Ads     (17748): This request is sent from a test device.
W/Ads     (17748): Could not find com.google.android.gms.ads.AdActivity, please make sure it is declared in AndroidManifest.xml.
I/Choreographer(17748): Skipped 39 frames!  The application may be doing too much work on its main thread.
D/EGL_emulation(17748): eglMakeCurrent: 0xe06ee060: ver 3 0 (tinfo 0xc2737970)
I/OpenGLRenderer(17748): Davey! duration=826ms; Flags=1, IntendedVsync=15091144858940, Vsync=15091794858914, OldestInputEvent=9223372036854775807, NewestInputEvent=0, HandleInputStart=15091808987960, AnimationStart=15091809076260, PerformTraversalsStart=15091809263460, DrawStart=15091820381260, SyncQueued=15091822369660, SyncStart=15091827238560, IssueDrawCommandsStart=15091833671660, SwapBuffers=15091871677860, FrameCompleted=15091976321160, DequeueBufferDuration=59743000, QueueBufferDuration=370000, 
W/cr_CrashFileManager(17748): /data/user/0/puns.jokes.jokespuns/cache/WebView/Crash Reports does not exist or is not a directory
D/        (17748): HostConnection::get() New Host Connection established 0xdf4d9a00, tid 17773
D/EGL_emulation(17748): eglMakeCurrent: 0xe06eed20: ver 3 0 (tinfo 0xe076e710)
D/skia    (17748): Program linking failed.
I/chatty  (17748): uid=10086(puns.jokes.jokespuns) 1.gpu identical 7 lines
D/skia    (17748): Program linking failed.
D/skia    (17748): Program linking failed.

我正试图将AdMob纳入我的Android flutter项目。

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="puns.jokes.package.unique">

<!-- io.flutter.app.FlutterApplication is an android.app.Application that
     calls FlutterMain.startInitialization(this); in its onCreate method.
     In most cases you can leave this as-is, but you if you want to provide
     additional functionality it is fine to subclass or reimplement
     FlutterApplication and put your custom class here. -->
<application
    android:name="io.flutter.app.FlutterApplication"
    android:label="Jokes and Puns"
    android:icon="@mipmap/ic_launcher">

    <activity
        android:name=".MainActivity"
        android:launchMode="singleTop"
        android:theme="@style/LaunchTheme"
        android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
        android:hardwareAccelerated="true"
        android:windowSoftInputMode="adjustResize">
        <!-- This keeps the window background of the activity showing
             until Flutter renders its first frame. It can be removed if
             there is no splash screen (such as the default splash screen
             defined in @style/LaunchTheme). -->
        <meta-data
            android:name="com.google.android.gms.ads.APPLICATION_ID"
            android:value="ca-app-pub-<appid>"/>
        <meta-data
            android:name="io.flutter.app.android.SplashScreenUntilFirstFrame"
            android:value="true" />
        <intent-filter>
            <action android:name="android.intent.action.MAIN"/>
            <category android:name="android.intent.category.LAUNCHER"/>
        </intent-filter>
    </activity>
</application>

Build.Gradle

buildscript {
ext.kotlin_version = '1.3.20'
repositories {
    google()
    jcenter()
}
dependencies {
    classpath 'com.android.tools.build:gradle:3.3.1'
    classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    classpath 'com.google.gms:google-services:4.2.0'
}
}allprojects {
repositories {
    google()
    jcenter()
}
}rootProject.buildDir = '../build'
subprojects {
project.buildDir = "${rootProject.buildDir}/${project.name}"
}subprojects {
project.evaluationDependsOn(':app')
}task clean(type: Delete) {
delete rootProject.buildDir}

app/build.gradle

def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
    localPropertiesFile.withReader('UTF-8') { reader ->
        localProperties.load(reader)
    }
}

def flutterRoot = localProperties.getProperty('flutter.sdk')
if (flutterRoot == null) {
    throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
}

def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
    flutterVersionCode = '2.0.0'
}

def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) {
    flutterVersionName = '2.0.0'
}

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

def keystoreProperties = new Properties()
def keystorePropertiesFile = rootProject.file('key.properties')
if (keystorePropertiesFile.exists()) {
    keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
}

android {
    compileSdkVersion 28

    sourceSets {
        main.java.srcDirs += 'src/main/kotlin'
    }

    lintOptions {
        disable 'InvalidPackage'
    }

    defaultConfig {
        // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
        applicationId "puns.jokes.jokespuns"
        minSdkVersion 16
        targetSdkVersion 28
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }

    signingConfigs {
        release {
            keyAlias keystoreProperties['keyAlias']
            keyPassword keystoreProperties['keyPassword']
            storeFile file(keystoreProperties['storeFile'])
            storePassword keystoreProperties['storePassword']
        }
    }

    buildTypes {
        release {
            // TODO: Add your own signing config for the release build.
            // Signing with the debug keys for now, so `flutter run --release` works.
            signingConfig signingConfigs.release
        }
    }
}

flutter {
    source '../..'
}

dependencies {
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation 'com.google.firebase:firebase-core:16.0.7'
    implementation 'com.google.firebase:firebase-ads:17.1.3'
    implementation 'com.google.android.gms:play-services-ads:17.1.3'
//    testImplementation 'junit:junit:4.12'
//    androidTestImplementation 'com.android.support.test:runner:1.0.2'
//    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}

apply plugin: 'com.google.gms.google-services'

main_screen.dart

@override
  void initState() {
    super.initState();
    FirebaseAdMob.instance.initialize(appId: FirebaseAdMob.testAppId);
  }
  @override
  Widget build(BuildContext context) {
    MobileAdTargetingInfo targetingInfo = MobileAdTargetingInfo(
      keywords: <String>['flutterio', 'beautiful apps'],
      testDevices: <String>[], // Android emulators are considered test devices
    );

    myInterstitial = InterstitialAd(
      // Replace the testAdUnitId with an ad unit id from the AdMob dash.
      // https://developers.google.com/admob/android/test-ads
      // https://developers.google.com/admob/ios/test-ads
      adUnitId: InterstitialAd.testAdUnitId,
      targetingInfo: targetingInfo,
      listener: (MobileAdEvent event) {
        print("InterstitialAd event is $event");
      },
    );
    myInterstitial..load()..show();
}

.....
.....
.....
.....
.....
@override
  void dispose() {
    myInterstitial.dispose();
    super.dispose();
  }

没有任何错误或警告的广告。

共有1个答案

宓毅庵
2023-03-14

将此部件移至活动之外

<meta-data
    android:name="com.google.android.gms.ads.APPLICATION_ID"
    android:value="ca-app-pub-<appid>"/>
 类似资料:
  • 我想在开发过程中在真正的iPhone和Android手机上运行/测试(而不是自动测试)我的颤振应用程序。然而,Flutter文档似乎只记录了如何使用iOS模拟器或Android模拟器。 我认为这对于iOS / Android开发人员来说已经是一个明智的选择,但我都不是,Flutter是我第一次涉足移动开发。 有没有关于如何在真实设备上运行时开发的初学者指南的链接? 附加上下文 < li >我是一名

  • 我有这个问题,知道吗?我正在添加洞迹 我的代码如下所示: 我的文件夹目录如下所示: 堆栈跟踪:

  • 测试 Android Library 项目类似于测试应用项目。唯一的不同点在于整个库(包括它的依赖)都是自动作为依赖库被添加到测试应用中。结果就是测试 APK 不单只包含自身的代码,还包含了 Library 项目以及它依赖的代码。Library 的 manifest 被组合到测试应用的 manifest 中(引用这个 Library 的项目作为容器)。androidTest task 变为只执行安

  • 我们在我的JIRA软件中添加了一个Zephyr测试用例管理插件。我们在一个JIRA项目(Master\u项目)中创建了一些“测试”,并在该项目中创建了一个搜索过滤器。现在,我们正在尝试使用搜索过滤器将Master\u项目的“测试”访问/添加到另一个JIRA项目的测试周期中。 将测试周期中的“测试”添加到“测试周期”时,我们遇到了一个问题。我们收到以下错误消息: 有人面临这样的问题吗?请您提出建议,

  • 我有基本的appium自动化测试,只是在移动设备上启动应用程序,并执行一些操作。同样的代码在其他机器上运行,而我在运行它时面临问题。 我得到这个错误: org.openqa.selenium.会话:无法创建新的远程会话。有关更多详细信息,请检查服务器日志。原始错误:处理命令时发生未知服务器端错误。原始错误:执行adbExec时出错。原始错误:命令/用户/xyz/库/Android/sdk/平台工具

  • 问题内容: 我正在尝试为我的项目编写一个单元测试,但是它不允许我使用配置管理器。现在我的项目像 ASP.Net应用程序(所有aspx页) ProjectCore(所有C#文件-模型) ProjectTest(所有测试) 在我的ProjectCore中,我可以从System.Configuration访问ConfigurationManager对象,并将信息传递到项目中。但是,当我运行涉及Confi