ilkecan / flutter-nix

Build Flutter apps with Nix and create a development environment for them
7 stars 1 forks source link

Lack of android support #1

Open Kranzes opened 2 years ago

Kranzes commented 2 years ago

Does this support building an android-based flutter app? By looking at the platforms folder, there seems to be an android.nix file. When using buildFlutterApp with platforms = "android" I get an error which says that only linux and web are supported.

ilkecan commented 2 years ago

Hi, sorry for the lack of documentation.

Currently buildFlutterApp doesn't support android because I wasn't able to generate the list of gradle dependencies fully. The ones listed in the lock files generated with gradle was not enough. I tried using gradle2nix but it didn't work; either because of flutter or my lack of understanding of gradle. I have an idea to create a proxy server to track the requests to all gradle dependencies but I am not sure whether that would work.

So, currently it is only possible to create a development environment for android.

Kranzes commented 2 years ago

From the development environment I wasn't able to flutter build apk it, it complained about a read only SDK (/nix/store.).

ilkecan commented 2 years ago

Did you use the flutter-nix.mkShell function and defined enableAll or enableAndroid as true? I was using the "friendly_chat" project to try this on and flutter build apk works on that. Can you provide the full output of the error?

Kranzes commented 2 years ago

I did use enableAndroid in flutter-nix.mkshell. I am trying to building https://github.com/UnicornsOnLSD/finamp

This is the output:

``` Running "flutter pub get" in finamp... 809ms 💪 Building with sound null safety 💪 Running Gradle task 'assembleRelease'... Warning: Mapping new ns http://schemas.android.com/repository/android/common/02 to old ns http://schemas.android.com/repository/android/common/01 Warning: Mapping new ns http://schemas.android.com/repository/android/generic/02 to old ns http://schemas.android.com/repository/android/generic/01 Warning: Mapping new ns http://schemas.android.com/sdk/android/repo/addon2/02 to old ns http://schemas.android.com/sdk/android/repo/addon2/01 Warning: Mapping new ns http://schemas.android.com/sdk/android/repo/repository2/02 to old ns http://schemas.android.com/sdk/android/repo/repository2/01 Warning: Mapping new ns http://schemas.android.com/sdk/android/repo/sys-img2/02 to old ns http://schemas.android.com/sdk/android/repo/sys-img2/01 Warning: Mapping new ns http://schemas.android.com/repository/android/common/02 to old ns http://schemas.android.com/repository/android/common/01 Warning: Mapping new ns http://schemas.android.com/repository/android/generic/02 to old ns http://schemas.android.com/repository/android/generic/01 Warning: Mapping new ns http://schemas.android.com/sdk/android/repo/addon2/02 to old ns http://schemas.android.com/sdk/android/repo/addon2/01 Warning: Mapping new ns http://schemas.android.com/sdk/android/repo/repository2/02 to old ns http://schemas.android.com/sdk/android/repo/repository2/01 Warning: Mapping new ns http://schemas.android.com/sdk/android/repo/sys-img2/02 to old ns http://schemas.android.com/sdk/android/repo/sys-img2/01 Checking the license for package Android SDK Platform 31 in /nix/store/jak8fh19yya73fzlrhkdsn8fl156f4as-android-sdk-env/share/android-sdk/licenses License for package Android SDK Platform 31 accepted. Preparing "Install Android SDK Platform 31 (revision: 1)". Warning: Failed to read or create install properties file. FAILURE: Build failed with an exception. * What went wrong: Could not determine the dependencies of task ':flutter_downloader:compileReleaseAidl'. > Failed to install the following SDK components: platforms;android-31 Android SDK Platform 31 The SDK directory is not writable (/nix/store/jak8fh19yya73fzlrhkdsn8fl156f4as-android-sdk-env/share/android-sdk) * 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 1s Running Gradle task 'assembleRelease'... 1,801ms Gradle task assembleRelease failed with exit code 1 ```

ilkecan commented 2 years ago

I confirmed that simply copying the flake.nix from the "friendly_chat" example produces the above error for finamp.

This is the file that creates the SDK derivation from the given arguments. Note that SDK platforms 30 is hardcoded in there. I don't have any android development experience, so the reason I hardcoded that value was I thought the SDK version must be related to the flutter version. But I can see how that is not the case now.

After adding platforms-android-31 to the list it complained about SDK version 29 this time. So I had to specify three SDK versions like this:

androidSdk (sdkPkgs: with sdkPkgs; [
  build-tools-29-0-2
  cmdline-tools-latest
  platform-tools
  platforms-android-29
  platforms-android-30
  platforms-android-31
])

I have no idea how to query which SDK versions are required so that we can remove the hardcoded value of platforms-android-30. We can probably parameterize the mkShell function to specify the required SDKs by the user but I would prefer to determine those if possible.