我想尝试这里提到的解决方案,但我不知道如何
当应用程序登录调试时,它会显示广告,但不会在发布模式下
在发布版本上展示广告需要几个小时。因此,如果它正在调试 apk 上运行,那么您无需添加任何代码,只需在 AdMob 上更新您的帐户详细信息并等待帐户确认,几个小时后您就会看到发布的广告。
在您的android/app目录中创建一个名为 proguard-rules.pro 的文件。
将这行代码添加到其中:
-keep class io.flutter.app.** { *; }
-keep class io.flutter.plugin.** { *; }
-keep class io.flutter.util.** { *; }
-keep class io.flutter.view.** { *; }
-keep class io.flutter.** { *; }
-keep class io.flutter.plugins.** { *; }
-keep class com.google.firebase.** { *; }
-keep class com.shatsy.** { *; }
最重要的是:-keep class com.google.firebase.** { *; }
和-keep class com.shatsy.** { *; }
现在在您的应用级别 build.gradle 文件中,将其添加到您的 buildType:
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
所以你的 buildType 文件夹看起来像这样:
buildTypes {
release {
minifyEnabled true
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.debug
}
}
然后运行flutter build apk -- buildTypeName
例子:
flutter build apk --release
更快的解决方案是minifyEnabled false
在您的应用程序级别 build.gradle 中添加到您的发布 buildType
说明:Proguard 可能会阻止您的应用使用 firebase_ads 库。这可能就是您的应用程序在调试模式下运行的原因,而不是在构建 apk 之后。
试试看,看看它是否有效。
我有同样的问题,那是我的错误,我没有添加互联网权限。如果您的应用程序代码需要访问 Internet,请添加 android.permission.INTERNET 权限。标准模板不包含此标签,但允许在开发期间访问 Internet,以实现 Flutter 工具和正在运行的应用程序之间的通信。
第 1 步:转到 android\app\src\main\AndroidManifest.xml
第2步:复制下面的这一行:
<uses-permission android:name="android.permission.INTERNET" />
第 3 步:将其放入 AndroidManifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.java2blog.helloworldapp">
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".HelloWorldActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
第 4 步:重建 .apk 并在移动设备上尝试它应该可以工作。