简体   繁体   中英

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?

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."

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.

When you make a new Flutter project it generate dart, android and iOS (if on a mac) code. For the most part we dont have to touch the underlying Java code.

But if you must you can open just the android folder in android studio and let gradle sync and build the project. You may also want to write platform specific code for either android or iOS.

Here is a guide on how you can do that https://flutter.dev/docs/development/platform-integration/platform-channels

tl;dr;

flutter generates native code for your dart code. You can also access native hardware by writing platform specific code.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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