在您的 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 之后。
试一试,看看是否有效。