flutter / flutter

Flutter makes it easy and fast to build beautiful apps for mobile and beyond
https://flutter.dev
BSD 3-Clause "New" or "Revised" License
164.97k stars 27.18k forks source link

build apk ignores --target-platform if --debug is set #153359

Open thgoebel opened 1 month ago

thgoebel commented 1 month ago

Steps to reproduce

  1. flutter create testproject
  2. cd testproject
  3. flutter build apk --target-platform=android-arm64 --debug

Expected results

The resulting app-debug.apk only contains code for android-arm64.

Actual results

The resulting app-debug.apk contains code for android-arm, android-arm64, android-x86, android-x64.

When running without --debug, i.e. flutter build apk --target-platform=android-arm64 then the resulting app-release.apk correctly contains only code for android-arm64.

Why this is relevant

I am using https://github.com/cunarist/rinf. Sometimes you have to do a flutter clean. And (re)compiling Rust code for 4 target archs takes a loooong time. But I only need and only want to compile for one arch. I expect --target-platform to work with --debug.

Alternatively (but not ideal), the output of flutter build apk --help should indicate that these two options are incompatible.

Code sample

No need for a code sample. Just run flutter create testproject and use that.

Screenshots or Video

n/a

Logs

n/a

Flutter Doctor output

Doctor output ```console Doctor summary (to see all details, run flutter doctor -v): [✓] Flutter (Channel stable, 3.24.0, on macOS 14.5 23F79 darwin-arm64, locale en-CH) [✓] Android toolchain - develop for Android devices (Android SDK version 35.0.0) [✓] Xcode - develop for iOS and macOS (Xcode 15.4) [✗] Chrome - develop for the web (Cannot find Chrome executable at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome) ! Cannot find Chrome. Try setting CHROME_EXECUTABLE to a Chrome executable. [✓] Android Studio (version 2024.1) [✓] VS Code (version 1.92.0) [✓] Connected device (3 available) [✓] Network resources ! Doctor found issues in 1 category ```
huycozy commented 1 month ago

I can reproduce the issue on the latest Flutter channels.

Debug

➜  flutter-apk unzip -l app-debug.apk
Archive:  app-debug.apk
  Length      Date    Time    Name
---------  ---------- -----   ----
...
 13203632  01-01-1981 01:01   lib/arm64-v8a/libVkLayer_khronos_validation.so
 39755544  01-01-1981 01:01   lib/arm64-v8a/libflutter.so
 40100568  01-01-1981 01:01   lib/x86/libflutter.so
 40800744  01-01-1981 01:01   lib/x86_64/libflutter.so
...

Release

➜  flutter-apk unzip -l app-release.apk                                          
Archive:  app-release.apk
  Length      Date    Time    Name
---------  ---------- -----   ----
...
  2950048  01-01-1981 01:01   lib/arm64-v8a/libapp.so
 10811088  01-01-1981 01:01   lib/arm64-v8a/libflutter.so
...
flutter doctor -v (stable and master) ```console [✓] Flutter (Channel stable, 3.24.0, on macOS 14.6 23G80 darwin-x64, locale en-VN) • Flutter version 3.24.0 on channel stable at /Users/huynq/Documents/GitHub/flutter • Upstream repository https://github.com/flutter/flutter.git • Framework revision 80c2e84975 (7 days ago), 2024-07-30 23:06:49 +0700 • Engine revision b8800d88be • Dart version 3.5.0 • DevTools version 2.37.2 [✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0) • Android SDK at /Users/huynq/Library/Android/sdk • Platform android-34, build-tools 34.0.0 • ANDROID_HOME = /Users/huynq/Library/Android/sdk • Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java • Java version OpenJDK Runtime Environment (build 17.0.10+0-17.0.10b1087.21-11572160) • All Android licenses accepted. [✓] Xcode - develop for iOS and macOS (Xcode 15.4) • Xcode at /Applications/Xcode15.4.app/Contents/Developer • Build 15F31d • CocoaPods version 1.15.2 [✓] Chrome - develop for the web • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome [✓] Android Studio (version 2023.3) • Android Studio at /Applications/Android Studio.app/Contents • Flutter plugin can be installed from: 🔨 https://plugins.jetbrains.com/plugin/9212-flutter • Dart plugin can be installed from: 🔨 https://plugins.jetbrains.com/plugin/6351-dart • android-studio-dir = /Applications/Android Studio.app/ • Java version OpenJDK Runtime Environment (build 17.0.10+0-17.0.10b1087.21-11572160) [✓] VS Code (version 1.91.1) • VS Code at /Applications/Visual Studio Code.app/Contents • Flutter extension version 3.94.0 [✓] Connected device (2 available) • macOS (desktop) • macos • darwin-x64 • macOS 14.6 23G80 darwin-x64 • Chrome (web) • chrome • web-javascript • Google Chrome 127.0.6533.89 [✓] Network resources • All expected network resources are available. • No issues found! ``` ```console [!] Flutter (Channel master, 3.24.0-1.0.pre.575, on macOS 14.6 23G80 darwin-x64, locale en-VN) • Flutter version 3.24.0-1.0.pre.575 on channel master at /Users/huynq/Documents/GitHub/flutter_master ! Warning: `flutter` on your path resolves to /Users/huynq/Documents/GitHub/flutter/bin/flutter, which is not inside your current Flutter SDK checkout at /Users/huynq/Documents/GitHub/flutter_master. Consider adding /Users/huynq/Documents/GitHub/flutter_master/bin to the front of your path. ! Warning: `dart` on your path resolves to /Users/huynq/Documents/GitHub/flutter/bin/dart, which is not inside your current Flutter SDK checkout at /Users/huynq/Documents/GitHub/flutter_master. Consider adding /Users/huynq/Documents/GitHub/flutter_master/bin to the front of your path. • Upstream repository https://github.com/flutter/flutter.git • Framework revision 593729165d (86 minutes ago), 2024-08-14 09:13:34 +0800 • Engine revision 019f9e3f07 • Dart version 3.6.0 (build 3.6.0-146.0.dev) • DevTools version 2.38.0 • If those were intentional, you can disregard the above warnings; however it is recommended to use "git" directly to perform update checks and upgrades. [✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0) • Android SDK at /Users/huynq/Library/Android/sdk • Platform android-34, build-tools 34.0.0 • ANDROID_HOME = /Users/huynq/Library/Android/sdk • Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java • Java version OpenJDK Runtime Environment (build 17.0.10+0-17.0.10b1087.21-11572160) • All Android licenses accepted. [✓] Xcode - develop for iOS and macOS (Xcode 15.4) • Xcode at /Applications/Xcode15.4.app/Contents/Developer • Build 15F31d • CocoaPods version 1.15.2 [✓] Chrome - develop for the web • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome [✓] Android Studio (version 2024.1) • Android Studio at /Applications/Android Studio Koala.app/Contents • Flutter plugin can be installed from: 🔨 https://plugins.jetbrains.com/plugin/9212-flutter • Dart plugin can be installed from: 🔨 https://plugins.jetbrains.com/plugin/6351-dart • Java version OpenJDK Runtime Environment (build 17.0.11+0-17.0.11b1207.24-11852314) [✓] Android Studio (version 2023.3) • Android Studio at /Applications/Android Studio.app/Contents • Flutter plugin can be installed from: 🔨 https://plugins.jetbrains.com/plugin/9212-flutter • Dart plugin can be installed from: 🔨 https://plugins.jetbrains.com/plugin/6351-dart • android-studio-dir = /Applications/Android Studio.app/ • Java version OpenJDK Runtime Environment (build 17.0.10+0-17.0.10b1087.21-11572160) [✓] VS Code (version 1.92.1) • VS Code at /Applications/Visual Studio Code.app/Contents • Flutter extension version 3.94.0 [✓] Connected device (4 available) • Pixel 7 (mobile) • 2B171FDH20084L • android-arm64 • Android 14 (API 34) • iPhone (mobile) • d9a94afe2b649fef56ba0bfeb052f0f2a7dae95e • ios • iOS 15.8 19H370 • macOS (desktop) • macos • darwin-x64 • macOS 14.6 23G80 darwin-x64 • Chrome (web) • chrome • web-javascript • Google Chrome 127.0.6533.100 [✓] Network resources • All expected network resources are available. ! Doctor found issues in 1 category. ```
reidbaker commented 1 month ago

@thgoebel is this a regression from a previous version of the flutter tool?

thgoebel commented 1 month ago

I don't know if it is a regression. I just started working on this Flutter app now. I was coming from the Rust sharedlib side, wanting to help our Flutter app team integrate it. So I downloaded Flutter just now. I don't now if this was working in the past or not. And none of my team mates wanted to use this up to now, because only with Rust's long build times it started to matter.

Anyway, I checked out 3.0.1, and the same behaviour (target platform is ignored) is present there as well. So it is not a recent regression, if it is one at all.

reidbaker commented 1 month ago

This seems like a reasonable request both the feature to make --debug work with --target-platform and if not then to update the documentation to make that clear.

andrewkolos commented 1 month ago

This seems reasonable and is something i'd be willing to review a PR for.

reidbaker commented 3 weeks ago

For future readers gradle.dart needs to be modified to look at target architectures when building in debug mode.

reidbaker commented 3 weeks ago

@thgoebel as a work around try setting --split-per-abi in addition to your target flag. Based on reading this code you might get what you are looking for.

reidbaker commented 3 weeks ago

@thgoebel confirmed with a sample app that you can use flutter build apk --target-platform=android-arm64 --debug --split-per-abi and you will only get the arm so files.

thgoebel commented 3 weeks ago

Good find! I can confirm that with --split-per-abi the resulting APK only contains arm64 code.

However, it still compiles for (arm64, i686/x86_32, x86_64). So for my use case (quicker builds because Rust is slow), this doesn't quite solve it since it still compiles for three target platforms. However, I am not sure if this is due to Flutter's code or due to Rinf's code. So I filed an issue with rinf as well: https://github.com/cunarist/rinf/issues/413

reidbaker commented 3 weeks ago

It is more likely an issue with flutter code. I linked the file but this is not likely to get more of my attention anytime soon.
Pull requests are welcome however.