我正在尝试为qthxswpoi编写stetho插件。
它需要在自定义应用程序的onCreate方法中进行一些初始化。
these steps
并在AndroidManifest.xml中为同一个应用程序创建一个条目。
public class MyApplication extends Application {
public void onCreate() {
super.onCreate();
Stetho.initializeWithDefaults(this);
}
}
但是我在尝试使用<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
...>
<application
android:name="MyApplication"
...>
</application>
</manifest>
来获取依赖于此插件的扑腾应用程序时出错 -
flutter run
将此行添加到清单中
D:\Dev\Repo\flutter_test\myapp\android\app\src\main\AndroidManifest.xml:16:9-57 Error:
Attribute application@name value=(io.flutter.app.FlutterApplication) from AndroidManifest.xml:16:9-57
is also present at [:stetho] AndroidManifest.xml:7:18-76 value=(com.vilokanlabs.stetho.stetho.MyApplication).
Suggestion: add 'tools:replace="android:name"' to <application> element at AndroidManifest.xml:15:5-38:19 to override.
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:processDebugManifest'.
> Manifest merger failed : Attribute application@name value=(io.flutter.app.FlutterApplication) from AndroidManifest.xml:16:9-57
is also present at [:stetho] AndroidManifest.xml:7:18-76 value=(com.vilokanlabs.stetho.stetho.MyApplication).
Suggestion: add 'tools:replace="android:name"' to <application> element at AndroidManifest.xml:15:5-38:19 to override.
似乎Android中只允许一个应用程序节点。正如建议<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
**xmlns:tools="http://schemas.android.com/tools"**
>
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme"
**tools:replace="android:icon,android:theme,android:name"**
>
和记录here。
here也可以是@ sagar-chavada建议的解决方案,但它不起作用。不知何故,应用程序的清单被认为/解析的时间晚于插件的清单,因此工具:如果在应用程序的清单中使用,则替换有效(这是没有用的),但如果在插件的清单中使用(并且抛出错误)则没有效果。
到目前为止,唯一对我有用的解决方案是插件中的tool:replace -
extending the Flutter's application class
并更新应用程序的清单文件以使用这个新的子类 -
public class MyApplication extends FlutterApplication {
public void onCreate() {
super.onCreate();
Stetho.initializeWithDefaults(this);
}
事实证明,这里的评论表明相同。也许这不是一个非常好的插件解决方案(一旦有两个竞争插件就会失败)但是它有效!