Skip to content

Add Flutter to Existing App Fails, Flutter Tools Generates Incorrect Files #22090

Closed

Description

@rayliverified

The generated files created by Flutter Tooling do not work.

https://github.com/flutter/flutter/wiki/Add-Flutter-to-existing-apps

View sample project here -> https://github.com/searchy2/FlutterAndroid

Steps to Reproduce

  1. Create new Android project using Kotlin and targeting SDK v28.
  2. Follow the steps at "Add Flutter to existing apps"
  3. Build project. Flutter tooling generates .android files.
  4. Generated files cannot find android packages.
    maxthonsnap20180920115050

I think the issue is the generated Flutter build.gradle doesn't match the packages used by the generated files.

Flutter.java and FlutterFragment.java use android.arch.lifecycle components and the android.support.annotation package.
maxthonsnap20180920115424
The generated build.gradle file does not import the correct packages.
maxthonsnap20180920115206

Activity

  1. rayliverified commented on Sep 20, 2018

    @rayliverified
    Author

    So the package imports aren't found because the Android project uses AndroidX.

  2. rayliverified commented on Sep 20, 2018

    @rayliverified
    Author

    Manually changing the imports to

    import androidx.annotation.NonNull;
    import androidx.fragment.app.Fragment;
    

    Let the project successfully compile.
    Is it safe to do this given the files say to not edit them?

  3. rayliverified commented on Sep 21, 2018

    @rayliverified
    Author

    Hmm, it seems that sometimes the files get regenerated and overwritten. The only way to continue working is to save a backup and apply the changes everytime the generated files get overwritten.

  4. rayliverified commented on Sep 21, 2018

    @rayliverified
    Author

    Closing to open a new ticket later requesting update to AndroidX or a way to match the generated files with the version the project is using or not overwrite generated files at all.

  5. github-actions commented on Sep 2, 2021

    @github-actions

    This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

  6. locked as resolved and limited conversation to collaborators on Sep 2, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions