简体   繁体   English

使用Main.Dart与.java的Flutter示例入门代码

[英]Flutter Example Starter code with Main.Dart vs. .java

If an example app has both a main.dart file and .java & build.gradle files does that mean that there are two redundant ways for the example app to be run on an emulated Android device? 如果示例应用程序同时具有main.dart文件和.java和build.gradle文件,这是否意味着该示例应用程序有两种冗余方式可在模拟的Android设备上运行?

I can currently run the main.dart file on an emulated device in Android Studio, but when I try running the .java file it give me the error "Error: Gradle project sync failed. Please fix your project and try again." 我目前可以在Android Studio中的模拟设备上运行main.dart文件,但是当我尝试运行.java文件时,出现错误“错误:Gradle项目同步失败。请修复您的项目,然后重试。”

It seems like the .java and gradle files directly compile to an Android .apk program when run, but my intuition was that the Dart code could also be compiled to an apk or ipa program. 看起来.java和gradle文件在运行时直接编译为Android .apk程序,但我的直觉是Dart代码也可以编译为apk或ipa程序。

When you make a new Flutter project it generate dart, android and iOS (if on a mac) code. 当您创建新的Flutter项目时,它会生成dart,Android和iOS(如果在Mac上)代码。 For the most part we dont have to touch the underlying Java code. 在大多数情况下,我们不必接触底层的Java代码。

But if you must you can open just the android folder in android studio and let gradle sync and build the project. 但是,如果必须,您可以只在android studio中打开android文件夹,并让gradle同步并构建项目。 You may also want to write platform specific code for either android or iOS. 您可能还想为android或iOS编写平台特定的代码。

Here is a guide on how you can do that https://flutter.dev/docs/development/platform-integration/platform-channels 这是有关如何执行此操作的指南https://flutter.dev/docs/development/platform-integration/platform-channels

tl;dr; tl; dr;

flutter generates native code for your dart code. flutter为您的Dart代码生成本机代码。 You can also access native hardware by writing platform specific code. 您还可以通过编写平台特定的代码来访问本机硬件。

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

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