Skip to content

Commit 4049889

Browse files
author
Emmanuel Garcia
authored
Make --androidx flag a noop in flutter create (flutter#52340)
1 parent 5bb5522 commit 4049889

File tree

17 files changed

+24
-119
lines changed

17 files changed

+24
-119
lines changed

dev/devicelab/bin/tasks/gradle_jetifier_test.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ Future<void> main() async {
3434
'create',
3535
options: <String>[
3636
'--org', 'io.flutter.devicelab',
37-
'--androidx',
3837
'hello',
3938
],
4039
);

dev/devicelab/bin/tasks/gradle_plugin_dependencies_test.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ Future<void> main() async {
3535
'create',
3636
options: <String>[
3737
'--org', 'io.flutter.devicelab',
38-
'--androidx',
3938
'hello',
4039
],
4140
);

packages/flutter_tools/lib/src/commands/create.dart

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -139,11 +139,12 @@ class CreateCommand extends FlutterCommand {
139139
defaultsTo: 'kotlin',
140140
allowed: <String>['java', 'kotlin'],
141141
);
142+
// TODO(egarciad): Remove this flag. https://github.com/flutter/flutter/issues/52363
142143
argParser.addFlag(
143144
'androidx',
145+
hide: true,
144146
negatable: true,
145-
defaultsTo: true,
146-
help: 'Generate a project using the AndroidX support libraries',
147+
help: 'Deprecated. Setting this flag has no effect.',
147148
);
148149
}
149150

@@ -401,7 +402,6 @@ class CreateCommand extends FlutterCommand {
401402
flutterRoot: flutterRoot,
402403
renderDriverTest: boolArg('with-driver-test'),
403404
withPluginHook: generatePlugin,
404-
androidX: boolArg('androidx'),
405405
androidLanguage: stringArg('android-language'),
406406
iosLanguage: stringArg('ios-language'),
407407
web: featureFlags.isWebEnabled,
@@ -411,7 +411,7 @@ class CreateCommand extends FlutterCommand {
411411

412412
final String relativeDirPath = globals.fs.path.relative(projectDirPath);
413413
if (!projectDir.existsSync() || projectDir.listSync().isEmpty) {
414-
globals.printStatus('Creating project $relativeDirPath... androidx: ${boolArg('androidx')}');
414+
globals.printStatus('Creating project $relativeDirPath...');
415415
} else {
416416
if (sampleCode != null && !overwrite) {
417417
throwToolExit('Will not overwrite existing project in $relativeDirPath: '
@@ -619,7 +619,6 @@ To edit platform code in an IDE see https://flutter.dev/developing-packages/#edi
619619
String projectName,
620620
String projectDescription,
621621
String androidLanguage,
622-
bool androidX,
623622
String iosLanguage,
624623
String flutterRoot,
625624
bool renderDriverTest = false,
@@ -644,7 +643,6 @@ To edit platform code in an IDE see https://flutter.dev/developing-packages/#edi
644643
'macosIdentifier': appleIdentifier,
645644
'description': projectDescription,
646645
'dartSdk': '$flutterRoot/bin/cache/dart-sdk',
647-
'androidX': androidX,
648646
'useAndroidEmbeddingV2': featureFlags.isAndroidEmbeddingV2Enabled,
649647
'androidMinApiLevel': android.minApiLevel,
650648
'androidSdkVersion': android_sdk.minimumAndroidSdkVersion,

packages/flutter_tools/lib/src/plugins.dart

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -527,14 +527,9 @@ public final class GeneratedPluginRegistrant {
527527
const String _androidPluginRegistryTemplateNewEmbedding = '''
528528
package io.flutter.plugins;
529529
530-
{{#androidX}}
531530
import androidx.annotation.Keep;
532531
import androidx.annotation.NonNull;
533-
{{/androidX}}
534-
{{^androidX}}
535-
import android.support.annotation.Keep;
536-
import android.support.annotation.NonNull;
537-
{{/androidX}}
532+
538533
import io.flutter.embedding.engine.FlutterEngine;
539534
{{#needsShim}}
540535
import io.flutter.embedding.engine.plugins.shim.ShimPluginRegistry;
Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
org.gradle.jvmargs=-Xmx1536M
22
android.enableR8=true
3-
{{#androidX}}
43
android.useAndroidX=true
54
android.enableJetifier=true
6-
{{/androidX}}
Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
org.gradle.jvmargs=-Xmx1536M
22
android.enableR8=true
3-
{{#androidX}}
43
android.useAndroidX=true
54
android.enableJetifier=true
6-
{{/androidX}}

packages/flutter_tools/templates/module/android/host_app_common/app.tmpl/build.gradle.tmpl

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,6 @@ buildDir = new File(rootProject.projectDir, "../build/host")
3434
dependencies {
3535
implementation project(':flutter')
3636
implementation fileTree(dir: 'libs', include: ['*.jar'])
37-
{{#androidX}}
3837
implementation 'androidx.appcompat:appcompat:1.0.2'
3938
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
40-
{{/androidX}}
41-
{{^androidX}}
42-
implementation 'com.android.support:appcompat-v7:28.0.0'
43-
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
44-
implementation 'com.android.support:design:28.0.0'
45-
{{/androidX}}
4639
}

packages/flutter_tools/templates/module/android/library/Flutter.tmpl/build.gradle.tmpl

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,5 @@ flutter {
4545
}
4646

4747
dependencies {
48-
{{#androidX}}
4948
implementation 'androidx.appcompat:appcompat:1.0.2'
50-
{{/androidX}}
51-
{{^androidX}}
52-
implementation 'com.android.support:support-v13:27.1.1'
53-
implementation 'com.android.support:support-annotations:27.1.1'
54-
{{/androidX}}
5549
}

packages/flutter_tools/templates/module/android/library/Flutter.tmpl/src/main/java/io/flutter/facade/Flutter.java.tmpl

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,11 @@ import android.app.Activity;
44
import android.content.Context;
55
import android.os.Bundle;
66

7-
{{#androidX}}
87
import androidx.annotation.NonNull;
98
import androidx.lifecycle.Lifecycle;
109
import androidx.lifecycle.LifecycleObserver;
1110
import androidx.lifecycle.OnLifecycleEvent;
12-
{{/androidX}}
13-
{{^androidX}}
14-
import android.arch.lifecycle.Lifecycle;
15-
import android.arch.lifecycle.LifecycleObserver;
16-
import android.arch.lifecycle.OnLifecycleEvent;
17-
import android.support.annotation.NonNull;
18-
{{/androidX}}
11+
1912
import io.flutter.plugin.common.BasicMessageChannel;
2013
import io.flutter.plugin.common.StringCodec;
2114
import io.flutter.plugins.GeneratedPluginRegistrant;

packages/flutter_tools/templates/module/android/library/Flutter.tmpl/src/main/java/io/flutter/facade/FlutterFragment.java.tmpl

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,9 @@ import android.util.AttributeSet;
66
import android.view.LayoutInflater;
77
import android.view.ViewGroup;
88

9-
{{#androidX}}
109
import androidx.annotation.NonNull;
1110
import androidx.fragment.app.Fragment;
12-
{{/androidX}}
13-
{{^androidX}}
14-
import android.support.annotation.NonNull;
15-
import android.support.v4.app.Fragment;
16-
{{/androidX}}
11+
1712
import io.flutter.view.FlutterView;
1813

1914
/**

packages/flutter_tools/templates/module/common/pubspec.yaml.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,6 @@ flutter:
8585
# They also do not have any bearing on your native host application's
8686
# identifiers, which may be completely independent or the same as these.
8787
module:
88-
androidX: {{androidX}}
88+
androidX: true
8989
androidPackage: {{androidIdentifier}}
9090
iosBundleIdentifier: {{iosIdentifier}}

packages/flutter_tools/templates/plugin/android-java.tmpl/src/main/java/androidIdentifier/pluginClass.java.tmpl

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
11
package {{androidIdentifier}};
22

33
{{#useAndroidEmbeddingV2}}
4-
{{#androidX}}
54
import androidx.annotation.NonNull;
6-
{{/androidX}}
7-
{{^androidX}}
8-
import android.support.annotation.NonNull;
9-
{{/androidX}}
5+
106
import io.flutter.embedding.engine.plugins.FlutterPlugin;
117
import io.flutter.plugin.common.MethodCall;
128
import io.flutter.plugin.common.MethodChannel;

packages/flutter_tools/templates/plugin/android-kotlin.tmpl/src/main/kotlin/androidIdentifier/pluginClass.kt.tmpl

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
11
package {{androidIdentifier}}
22

33
{{#useAndroidEmbeddingV2}}
4-
{{#androidX}}
54
import androidx.annotation.NonNull;
6-
{{/androidX}}
7-
{{^androidX}}
8-
import android.support.annotation.NonNull;
9-
{{/androidX}}
5+
106
import io.flutter.embedding.engine.plugins.FlutterPlugin
117
import io.flutter.plugin.common.MethodCall
128
import io.flutter.plugin.common.MethodChannel
Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
org.gradle.jvmargs=-Xmx1536M
22
android.enableR8=true
3-
{{#androidX}}
43
android.useAndroidX=true
54
android.enableJetifier=true
6-
{{/androidX}}

packages/flutter_tools/test/commands.shard/permeable/create_test.dart

Lines changed: 0 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -488,27 +488,6 @@ void main() {
488488
expect(actualContents.contains('useAndroidX'), true);
489489
});
490490

491-
testUsingContext('non androidx app project', () async {
492-
Cache.flutterRoot = '../..';
493-
when(mockFlutterVersion.frameworkRevision).thenReturn(frameworkRevision);
494-
when(mockFlutterVersion.channel).thenReturn(frameworkChannel);
495-
496-
final CreateCommand command = CreateCommand();
497-
final CommandRunner<void> runner = createTestCommandRunner(command);
498-
499-
await runner.run(<String>['create', '--no-pub', '--no-androidx', projectDir.path]);
500-
501-
void expectExists(String relPath) {
502-
expect(globals.fs.isFileSync('${projectDir.path}/$relPath'), true);
503-
}
504-
505-
expectExists('android/gradle.properties');
506-
507-
final String actualContents = await globals.fs.file(projectDir.path + '/android/gradle.properties').readAsString();
508-
509-
expect(actualContents.contains('useAndroidX'), false);
510-
});
511-
512491
testUsingContext('androidx is used by default in a module project', () async {
513492
Cache.flutterRoot = '../..';
514493
when(mockFlutterVersion.frameworkRevision).thenReturn(frameworkRevision);
@@ -526,23 +505,6 @@ void main() {
526505
);
527506
});
528507

529-
testUsingContext('non androidx module', () async {
530-
Cache.flutterRoot = '../..';
531-
when(mockFlutterVersion.frameworkRevision).thenReturn(frameworkRevision);
532-
when(mockFlutterVersion.channel).thenReturn(frameworkChannel);
533-
534-
final CreateCommand command = CreateCommand();
535-
final CommandRunner<void> runner = createTestCommandRunner(command);
536-
537-
await runner.run(<String>['create', '--template=module', '--no-pub', '--no-androidx', projectDir.path]);
538-
539-
final FlutterProject project = FlutterProject.fromDirectory(projectDir);
540-
expect(
541-
project.usesAndroidX,
542-
false,
543-
);
544-
});
545-
546508
testUsingContext('androidx is used by default in a plugin project', () async {
547509
Cache.flutterRoot = '../..';
548510
when(mockFlutterVersion.frameworkRevision).thenReturn(frameworkRevision);
@@ -564,27 +526,6 @@ void main() {
564526
expect(actualContents.contains('useAndroidX'), true);
565527
});
566528

567-
testUsingContext('non androidx plugin project', () async {
568-
Cache.flutterRoot = '../..';
569-
when(mockFlutterVersion.frameworkRevision).thenReturn(frameworkRevision);
570-
when(mockFlutterVersion.channel).thenReturn(frameworkChannel);
571-
572-
final CreateCommand command = CreateCommand();
573-
final CommandRunner<void> runner = createTestCommandRunner(command);
574-
575-
await runner.run(<String>['create', '--no-pub', '--template=plugin', '--no-androidx', projectDir.path]);
576-
577-
void expectExists(String relPath) {
578-
expect(globals.fs.isFileSync('${projectDir.path}/$relPath'), true);
579-
}
580-
581-
expectExists('android/gradle.properties');
582-
583-
final String actualContents = await globals.fs.file(projectDir.path + '/android/gradle.properties').readAsString();
584-
585-
expect(actualContents.contains('useAndroidX'), false);
586-
});
587-
588529
testUsingContext('app supports Linux if requested', () async {
589530
Cache.flutterRoot = '../..';
590531
when(mockFlutterVersion.frameworkRevision).thenReturn(frameworkRevision);

packages/flutter_tools/test/general.shard/commands/build_apk_test.dart

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,13 @@ void main() {
366366

367367
testUsingContext("reports when the app isn't using AndroidX", () async {
368368
final String projectPath = await createProject(tempDir,
369-
arguments: <String>['--no-pub', '--no-androidx', '--template=app']);
369+
arguments: <String>['--no-pub', '--template=app']);
370+
// Simulate a non-androidx project.
371+
tempDir
372+
.childDirectory('flutter_project')
373+
.childDirectory('android')
374+
.childFile('gradle.properties')
375+
.writeAsStringSync('android.useAndroidX=false');
370376

371377
when(mockProcessManager.start(
372378
<String>[

packages/flutter_tools/test/general.shard/commands/build_appbundle_test.dart

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,13 @@ void main() {
324324

325325
testUsingContext("reports when the app isn't using AndroidX", () async {
326326
final String projectPath = await createProject(tempDir,
327-
arguments: <String>['--no-pub', '--no-androidx', '--template=app']);
327+
arguments: <String>['--no-pub', '--template=app']);
328+
// Simulate a non-androidx project.
329+
tempDir
330+
.childDirectory('flutter_project')
331+
.childDirectory('android')
332+
.childFile('gradle.properties')
333+
.writeAsStringSync('android.useAndroidX=false');
328334

329335
when(mockProcessManager.start(
330336
<String>[

0 commit comments

Comments
 (0)