-
Notifications
You must be signed in to change notification settings - Fork 28.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adds support for generating projects that use AndroidX support libraries #31028
Conversation
87a0556
to
31cd632
Compare
Why haven't merged yet? |
@dnfield I've seen you comment about AndroidX support a few other places. Is it possible this PR may be merged or is there other internal work happening around it? |
Why should this PR not be merged? |
@matthew-carroll would you be the right person to review this? |
@xster you're probably in the best position to make a call on this particular solution. |
Thanks for the contribution! We've had a number of issues with jetifier not working with our current gradle setup. I'm a bit curious about how this impacts that - are you able to consume a plugin that uses the support libraries with this project structure successfully? My main concern here is that it's not clear what benefit this really offers to someone developing a Flutter app at this point - unless it's helping with that issue. |
Hey Dan, With this setup, a project will work with both AndroidX and Support dependencies. Without this, I believe Flutter projects that use plugins with AndroidX dependencies need to be upgraded to AndroidX. I'm using this branch in a Flutter project using Jetifier and all is working well. So the benefit is that new Flutter projects using AndroidX should just work with any plugin. Do you have any more information about the issues with Jetifier that you've had? I'd like to test this branch to make sure it solves those issues. |
@athornz |
Since support library is deprecated I think AndroidX should be the default. If a Flutter project with AndroidX works with Jetifier then there is no reason to use the support libraries. We should be making use of Jetifier as Google implemented as a good way to update to AndroidX and be compatible with support libraries. |
Thanks for the contribution! @athornz I agree, AndroidX with Jetifier should ideally be our default to get rid of any support issues. The problem we've run into so far is that Jetifier doesn't work with how we build Flutter apps and include plugins: #32714. You can see this by making a new template with this PR or by migrating an app manually, then depending on a an older plugin (like Even with Jetifier being broken for us @dnfield I think this is probably an improvement. At least all of |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the contribution @athornz - this is great!
@dnfield having just spent 5 hours wrestling with AndroidX issues in my project, I think this change will help enable new projects to be built.
packages/flutter_tools/templates/app/android.tmpl/gradle.properties.tmpl
Outdated
Show resolved
Hide resolved
packages/flutter_tools/templates/module/android/gradle/gradle.properties.tmpl
Outdated
Show resolved
Hide resolved
packages/flutter_tools/templates/plugin/android.tmpl/gradle.properties.tmpl
Outdated
Show resolved
Hide resolved
packages/flutter_tools/templates/module/android/gradle/gradle.properties.copy.tmpl
Show resolved
Hide resolved
...plates/module/android/library/Flutter.tmpl/src/main/java/io/flutter/facade/Flutter.java.tmpl
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM modulo one small nit.
LGTM. Will land on green. Thanks again! |
@jonahwilliams I've rebased on master now. |
CLAs look good, thanks! ℹ️ Googlers: Go here for more info. |
flutter#34066) This is a small follow up to the previous AndroidX PR: flutter#31028 This fixes an issue mentioned [here](flutter#28805) where the androidX flag for a module is not set when creating a new project: `flutter create --androidx -t module my_flutter`
Flutter.jar is not compatible with androidX |
Currently I have a the app crashed:
is it related to flutter.jar? cc @athornz @dnfield @tvolkert |
That is because we are missing AndroidX transitive dependencies from the engine. We have a fix in progress. cc @matthew-carroll |
In the meanwhile, you can the dependencies manually to |
The crash still happens even after I added the following snippet to // known issue https://github.com/flutter/flutter/pull/31028#issuecomment-516902006
def lifecycle_version = "2.0.0"
// ViewModel and LiveData
implementation "androidx.lifecycle:lifecycle-extensions:$lifecycle_version"
// alternatively - just ViewModel
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycle_version"
// alternatively - just LiveData
implementation "androidx.lifecycle:lifecycle-livedata:$lifecycle_version"
implementation "androidx.lifecycle:lifecycle-runtime:$lifecycle_version"
kapt "androidx.lifecycle:lifecycle-compiler:$lifecycle_version"
// optional - ReactiveStreams support for LiveData
implementation "androidx.lifecycle:lifecycle-reactivestreams-ktx:$lifecycle_version"
// optional - Test helpers for LiveData
testImplementation "androidx.arch.core:core-testing:$lifecycle_version" |
@truongsinh would you mind creating an issue with a repro test case? Thanks! |
I might take a while, but sure. |
Actually, trying to reproduce the error on a sample, I encoutered a different problem (here's the code https://github.com/truongsinh/android_flutter_host/tree/built-in-androidx)
|
@athornz @blasten any update? |
update from my side,
is solved by work around, I have to
|
Figured out, with performance degradation:
def lifecycle_version = "1.1.1"
implementation "android.arch.lifecycle:common-java8:$lifecycle_version"
override fun retainFlutterEngineAfterHostDestruction(): Boolean {
return true
} One problem though, it seems the performance of transitioning between Kotlin activity and Flutter activity is much worse than before. Previously, with cached engine, it was really smooth. Even though low performance happens on debug mode only (not profile nor release), it might still be a performance degradation from previous version (1.5.4-hotfix) |
It's hard for us to make sure we follow up on comments on previously merged PRs. If there are still remaining issues or inconveniences with the flows, please file a new issue with repro steps. |
@truongsinh Btw, we will start shipping Maven artifacts. As a result, these artifacts will become the source of truth for the engine dependencies such as |
Do we have a github issue or PR to track this? |
There's #11439 |
Description
This PR modifies the Flutter tool with support for generating projects that use AndroidX support libraries rather than the legacy support library.
This is a source of pain in Flutter development and now that AndroidX is 1.0 all new Flutter projects should be using it.
Projects generated with AndroidX libraries also use Jetifier which allows any dependencies (e.g. plugins) that still use the legacy support libraries to be upgrade to use AndroidX.
With this change, the flutter tool has the following changes:
--androidx
flag when creating flutter projects. This is disabled by default, and can be enabled via--androidx
androidX
property under the module section of a pubspec.yaml file. This is to control whether the generated module project uses AndroidX.e.g.
Related Issues
Tests
Checklist
///
).flutter analyze --flutter-repo
) does not report any problems on my PR.Breaking Change
Does your PR require Flutter developers to manually update their apps to accommodate your change?