我正在尝试在我的 flutter 项目中使用 "google_mobile_ads" 但我正在将其迁移到 Android 嵌入 v2
I am trying to use "google_mobile_ads" in my flutter project but I am getting this migrated to the Android embedding v2
插件 google_mobile_ads
要求您的应用迁移到 Android 嵌入 v2。按照 https://flutter.dev/go/android-project-migration 上的步骤操作并重新 运行 此命令。
所以我尝试按照这些步骤操作,但我无法在我的项目中的任何地方找到“MainActivity.java”,因此无法继续
MyProject tree
migration error
https://flutter.dev/go/android-project-migration
这是 Link 建议遵循的
只需在您的项目中打开此文件并复制 >> 粘贴此代码行即可.......确保删除此文件中的所有代码行并将其替换为这个新的一个。
1: MainActivity.java
package co.appbrewery.flash_chat;
import io.flutter.embedding.android.FlutterActivity;
public class MainActivity extends FlutterActivity {
}
2: styles.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="LaunchTheme" parent="@android:style/Theme.Black.NoTitleBar">
<item name="android:windowBackground">@drawable/launch_background</item>
</style>
</resources>
3: AndroidManifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="co.appbrewery.flash_chat">
<!-- 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:label="flash_chat" 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="io.flutter.embedding.android.SplashScreenDrawable" android:resource="@drawable/launch_background" />
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<meta-data android:name="flutterEmbedding" android:value="2" />
</application>
</manifest>
插件 google_mobile_ads
要求您的应用迁移到 Android 嵌入 v2。按照 https://flutter.dev/go/android-project-migration 上的步骤操作并重新 运行 此命令。
所以我尝试按照这些步骤操作,但我无法在我的项目中的任何地方找到“MainActivity.java”,因此无法继续
MyProject tree
migration error
https://flutter.dev/go/android-project-migration 这是 Link 建议遵循的
只需在您的项目中打开此文件并复制 >> 粘贴此代码行即可.......确保删除此文件中的所有代码行并将其替换为这个新的一个。
1: MainActivity.java
package co.appbrewery.flash_chat;
import io.flutter.embedding.android.FlutterActivity;
public class MainActivity extends FlutterActivity {
}
2: styles.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="LaunchTheme" parent="@android:style/Theme.Black.NoTitleBar">
<item name="android:windowBackground">@drawable/launch_background</item>
</style>
</resources>
3: AndroidManifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="co.appbrewery.flash_chat">
<!-- 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:label="flash_chat" 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="io.flutter.embedding.android.SplashScreenDrawable" android:resource="@drawable/launch_background" />
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<meta-data android:name="flutterEmbedding" android:value="2" />
</application>
</manifest>