[英]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'
}
像这样更改您的代码
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.