繁体   English   中英

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

[英]Getting error in my first flutter app while trying to run

I just tried to run my first hello world app with flutter. But its showing error when emulator selected and run clicked.

这是我的代码:

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

怎么了? 我该如何解决?

根据这个github问题 ,你只需要将它添加到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'
 }

我跟踪并测试了您的代码,我发现没有问题应用程序完全正常,没有任何错误 这是输出 码:

import "package:flutter/material.dart";

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

您可以尝试对您的sdk / app进行故障排除

尝试运行命令flutter clean

扑医生

希望这可行,添加您的日志,以便我们可以在运行此命令后查看问题

像这样更改您的代码

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) ,);
  }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM