android 尝试运行时,我的第一个Flutter应用程序出错

iyfamqjs  于 2022-12-09  发布在  Android
关注(0)|答案(3)|浏览(160)

我刚试着用flutter运行我的第一个hello world应用程序。但是当选择模拟器并点击运行时,它显示错误。
下面是我的代码:

import "package:flutter/material.dart";

void main()
{
  runApp(

      Center(child:Text("Hello world!", textDirection: TextDirection.ltr) ,)
  );
}

我得到的错误是:

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:transformNativeLibsWithMergeJniLibsForDebug'.
> org/apache/commons/codec/binary/Base64

* 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 13s
Finished with error: Gradle task assembleDebug failed with exit code 1

怎么了?我该怎么解决?

kq4fsx7k

kq4fsx7k1#

根据这个github issue,你只需要把这个添加到你的build.gradle文件中:

packagingOptions {
     pickFirst 'lib/x86/libc++_shared.so'
     pickFirst 'lib/arm64-v8a/libc++_shared.so'
     pickFirst 'lib/x86_64/libc++_shared.so'
     pickFirst 'lib/armeabi-v7a/libc++_shared.so'
 }
gk7wooem

gk7wooem2#

我遵循并测试了您的代码,我发现没有问题应用程序工作完全正常,没有错误在所有x1c 0d1x代码:

import "package:flutter/material.dart";

void main() {
  runApp(Center(
    child: Text("Hello world!", textDirection: TextDirection.ltr),
  ));
}

您可以尝试排除sdk/app的故障
尝试运行flutter clean命令
Flutter 刮刀
希望此操作有效,请添加您的日志,以便我们可以在运行此命令后查看问题

toe95027

toe950273#

像这样更改代码

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'YOUR_APP_NAME',
      debugShowCheckedModeBanner: false,
      home: Home(),
    );
  }
}

class Home extends StatefulWidget {
  const Home({Key? key}) : super(key: key);

  @override
  State<Home> createState() => _HomeState();
}

class _HomeState extends State<Home> {
  @override
  Widget build(BuildContext context) {
    return Center(child:Text("Hello world!", textDirection: TextDirection.ltr) ,);
  }
}

相关问题