java - 问题:一些消息已被简化;使用 -Xdiags:verbose 重新编译以获得完整输出
问题描述
package com.example.flutter_app;
import android.os.Bundle;
import io.flutter.app.FlutterActivity;
import io.flutter.plugins.GeneratedPluginRegistrant;
import io.flutter.plugin.common.MethodCall;
import io.flutter.plugin.common.MethodChannel;
import io.flutter.plugin.common.MethodChannel.Result;
import io.flutter.plugin.common.MethodChannel.MethodCallHandler;
import android.content.ContextWrapper;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.BatteryManager;
import android.os.Build.VERSION;
import android.os.Build.VERSION_CODES;
import android.os.Bundle;
public class MainActivity extends FlutterActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
GeneratedPluginRegistrant.registerWith(this);
new MethodChannel(getFlutterView(), "course.flutter.dev/battery").setMethodCallHandler(
new MethodCallHandler() {
@Override
public void onMethodCall(MethodCall call, Result result) {
if (call.method.equals("getBatteryLevel")) {
int batteryLevel = getBatteryLevel();
if (batteryLevel != -1) {
result.success(batteryLevel);
} else {
result.error("UNAVAILABLE", "Could not fetch battery level.", null);
}
} else {
result.notImplemented();
}
}
}
);
}
private int getBatteryLevel() {
int batteryLevel = -1;
if (VERSION.SDK_INT >= VERSION_CODES.LOLLIPOP) {
BatteryManager batteryManager = (BatteryManager) getSystemService(BATTERY_SERVICE);
batteryLevel = batteryManager.getIntProperty(BatteryManager.BATTERY_PROPERTY_CAPACITY);
} else {
Intent intent = new ContextWrapper(getApplicationContext()).registerReceiver(null, new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
batteryLevel = (intent.getIntExtra(BatteryManager.EXTRA_LEVEL, -1) * 100) / intent.getIntExtra(BatteryManager.EXTRA_SCALE, -1);
}
return batteryLevel;
}
}
我的java代码在上面给出。我正在学习编写本机 Java 代码的教程,以获取我的颤振应用程序中的电池电量。
但它给了我下面给出的错误:(调试控制台输出)
Launching lib\main.dart on LDN L21 in debug mode...
lib\main.dart:1
C:\Users\ARPC\flutter_app\android\app\src\main\java\com\example\flutter_app\MainActivity.java:22: error: incompatible types: MainActivity cannot be converted to FlutterEngine
GeneratedPluginRegistrant.registerWith(this);
^
Note: Some messages have been simplified; recompile with -Xdiags:verbose to get full output
1 error
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:compileDebugJavaWithJavac'.
> Compilation failed; see the compiler error output for details.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 3s
Exception: Gradle task assembleDebug failed with exit code 1
Exited (sigterm)
请告诉我我做错了什么我认为我必须将详细信息变为真实但如果有人知道解决方案我不知道该怎么做请告诉我。
解决方案
删除清单文件中的以下代码
meta-data
android:name="flutterEmbedding"
android:value="2"
并运行它会工作的项目
推荐阅读
- r - 安装 rsparkling - 苏打水 Nightly Bleeding Edge
- three.js - 在 A-Frame 和 Three.js 中使用多平面绘制曲线
- sql-server - 如何将变量数据包含到 SQL 语句中
- log4net - 带有 asp.net 核心 2 的 log4net
- vb.net - 如何过滤我的 Datagriview?
- javascript - 从选择中加载选项仅适用于具有类的第一项
- javascript - 重定向到另一个页面会阻止函数返回它们的值
- sql - SQL Server 2012 存储过程:带有编号列的 Where 子句
- zabbix - 如何使用 item.create 创建计算项?
- owin - Nancy/Owin 无法在同一服务器上使用 DNS 浏览到 URL