Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
Front-End
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
abdullh.alsoleman
Front-End
Commits
d0e45a23
Commit
d0e45a23
authored
Jun 01, 2019
by
Josh Burton
Committed by
Emmanuel Garcia
Jun 01, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Adds support for generating projects that use AndroidX support libraries (#31028)
parent
16a23dd2
Changes
19
Show whitespace changes
Inline
Side-by-side
Showing
19 changed files
with
206 additions
and
10 deletions
+206
-10
create.dart
packages/flutter_tools/lib/src/commands/create.dart
+9
-0
flutter_manifest.dart
packages/flutter_tools/lib/src/flutter_manifest.dart
+10
-0
project.dart
packages/flutter_tools/lib/src/project.dart
+7
-0
pubspec_yaml.json
packages/flutter_tools/schema/pubspec_yaml.json
+1
-0
build.gradle.tmpl
...ols/templates/app/android-java.tmpl/app/build.gradle.tmpl
+11
-0
build.gradle.tmpl
...s/templates/app/android-kotlin.tmpl/app/build.gradle.tmpl
+11
-0
gradle.properties
...lutter_tools/templates/app/android.tmpl/gradle.properties
+0
-1
gradle.properties.tmpl
...r_tools/templates/app/android.tmpl/gradle.properties.tmpl
+6
-0
gradle.properties.copy.tmpl
...mplates/module/android/gradle/gradle.properties.copy.tmpl
+0
-1
gradle.properties.tmpl
...ls/templates/module/android/gradle/gradle.properties.tmpl
+6
-0
build.gradle.tmpl
...module/android/host_app_common/app.tmpl/build.gradle.tmpl
+14
-1
build.gradle.tmpl
...tes/module/android/library/Flutter.tmpl/build.gradle.tmpl
+10
-0
Flutter.java.tmpl
...er.tmpl/src/main/java/io/flutter/facade/Flutter.java.tmpl
+12
-4
FlutterFragment.java.tmpl
...src/main/java/io/flutter/facade/FlutterFragment.java.tmpl
+8
-2
build.gradle.tmpl
...ools/templates/plugin/android-java.tmpl/build.gradle.tmpl
+5
-0
build.gradle.tmpl
...ls/templates/plugin/android-kotlin.tmpl/build.gradle.tmpl
+5
-0
gradle.properties
...ter_tools/templates/plugin/android.tmpl/gradle.properties
+0
-1
gradle.properties.tmpl
...ools/templates/plugin/android.tmpl/gradle.properties.tmpl
+6
-0
create_test.dart
packages/flutter_tools/test/commands/create_test.dart
+85
-0
No files found.
packages/flutter_tools/lib/src/commands/create.dart
View file @
d0e45a23
...
...
@@ -137,6 +137,12 @@ class CreateCommand extends FlutterCommand {
defaultsTo:
'java'
,
allowed:
<
String
>[
'java'
,
'kotlin'
],
);
argParser
.
addFlag
(
'androidx'
,
negatable:
true
,
defaultsTo:
false
,
help:
'Generate a project using the AndroidX support libraries'
,
);
}
@override
...
...
@@ -358,6 +364,7 @@ class CreateCommand extends FlutterCommand {
flutterRoot:
flutterRoot
,
renderDriverTest:
argResults
[
'with-driver-test'
],
withPluginHook:
generatePlugin
,
androidX:
argResults
[
'androidx'
],
androidLanguage:
argResults
[
'android-language'
],
iosLanguage:
argResults
[
'ios-language'
],
);
...
...
@@ -564,6 +571,7 @@ To edit platform code in an IDE see https://flutter.dev/developing-packages/#edi
String
projectName
,
String
projectDescription
,
String
androidLanguage
,
bool
androidX
,
String
iosLanguage
,
String
flutterRoot
,
bool
renderDriverTest
=
false
,
...
...
@@ -583,6 +591,7 @@ To edit platform code in an IDE see https://flutter.dev/developing-packages/#edi
'iosIdentifier'
:
_createUTIIdentifier
(
organization
,
projectName
),
'description'
:
projectDescription
,
'dartSdk'
:
'
$flutterRoot
/bin/cache/dart-sdk'
,
'androidX'
:
androidX
,
'androidMinApiLevel'
:
android
.
minApiLevel
,
'androidSdkVersion'
:
android_sdk
.
minimumAndroidSdkVersion
,
'androidFlutterJar'
:
'
$flutterRoot
/bin/cache/artifacts/engine/android-arm/flutter.jar'
,
...
...
packages/flutter_tools/lib/src/flutter_manifest.dart
View file @
d0e45a23
...
...
@@ -119,6 +119,13 @@ class FlutterManifest {
return
_flutterDescriptor
[
'uses-material-design'
]
??
false
;
}
/// True if this Flutter module should use AndroidX dependencies.
///
/// If false the deprecated Android Support library will be used.
bool
get
usesAndroidX
{
return
_flutterDescriptor
[
'module'
][
'androidX'
]
??
false
;
}
/// True if this manifest declares a Flutter module project.
///
/// A Flutter project is considered a module when it has a `module:`
...
...
@@ -356,6 +363,9 @@ void _validateFlutter(YamlMap yaml, List<String> errors) {
errors
.
add
(
'Expected "
${kvp.key}
" to be an object, but got
${kvp.value}
(
${kvp.value.runtimeType}
).'
);
}
if
(
kvp
.
value
[
'androidX'
]
!=
null
&&
kvp
.
value
[
'androidX'
]
is
!
bool
)
{
errors
.
add
(
'The "androidX" value must be a bool if set.'
);
}
if
(
kvp
.
value
[
'androidPackage'
]
!=
null
&&
kvp
.
value
[
'androidPackage'
]
is
!
String
)
{
errors
.
add
(
'The "androidPackage" value must be a string if set.'
);
}
...
...
packages/flutter_tools/lib/src/project.dart
View file @
d0e45a23
...
...
@@ -149,6 +149,9 @@ class FlutterProject {
/// True if this project is a Flutter module project.
bool
get
isModule
=>
manifest
.
isModule
;
/// True if the Flutter project is using the AndroidX support library
bool
get
usesAndroidX
=>
manifest
.
usesAndroidX
;
/// True if this project has an example application.
bool
get
hasExampleApp
=>
_exampleDirectory
(
directory
).
existsSync
();
...
...
@@ -466,6 +469,9 @@ class AndroidProject {
/// True if the parent Flutter project is a module.
bool
get
isModule
=>
parent
.
isModule
;
/// True if the Flutter project is using the AndroidX support library
bool
get
usesAndroidX
=>
parent
.
usesAndroidX
;
/// True, if the app project is using Kotlin.
bool
get
isKotlin
{
final
File
gradleFile
=
hostAppGradleRoot
.
childDirectory
(
'app'
).
childFile
(
'build.gradle'
);
...
...
@@ -558,6 +564,7 @@ class AndroidProject {
<
String
,
dynamic
>{
'projectName'
:
parent
.
manifest
.
appName
,
'androidIdentifier'
:
parent
.
manifest
.
androidPackage
,
'androidX'
:
usesAndroidX
,
},
printStatusWhenWriting:
false
,
overwriteExisting:
true
,
...
...
packages/flutter_tools/schema/pubspec_yaml.json
View file @
d0e45a23
...
...
@@ -48,6 +48,7 @@
"type"
:
"object"
,
"additionalProperties"
:
false
,
"properties"
:
{
"androidX"
:
{
"type"
:
"boolean"
},
"androidPackage"
:
{
"type"
:
"string"
},
"iosBundleIdentifier"
:
{
"type"
:
"string"
}
}
...
...
packages/flutter_tools/templates/app/android-java.tmpl/app/build.gradle.tmpl
View file @
d0e45a23
...
...
@@ -38,7 +38,12 @@ android {
targetSdkVersion 28
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
{{#androidX}}
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
{{/androidX}}
{{^androidX}}
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
{{/androidX}}
}
buildTypes {
...
...
@@ -56,6 +61,12 @@ flutter {
dependencies {
testImplementation 'junit:junit:4.12'
{{#androidX}}
androidTestImplementation 'androidx.test:runner:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
{{/androidX}}
{{^androidX}}
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
{{/androidX}}
}
packages/flutter_tools/templates/app/android-kotlin.tmpl/app/build.gradle.tmpl
View file @
d0e45a23
...
...
@@ -43,7 +43,12 @@ android {
targetSdkVersion 28
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
{{#androidX}}
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
{{/androidX}}
{{^androidX}}
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
{{/androidX}}
}
buildTypes {
...
...
@@ -62,6 +67,12 @@ flutter {
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
testImplementation 'junit:junit:4.12'
{{#androidX}}
androidTestImplementation 'androidx.test:runner:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
{{/androidX}}
{{^androidX}}
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
{{/androidX}}
}
packages/flutter_tools/templates/app/android.tmpl/gradle.properties
deleted
100644 → 0
View file @
16a23dd2
org.gradle.jvmargs
=
-Xmx1536M
packages/flutter_tools/templates/app/android.tmpl/gradle.properties.tmpl
0 → 100644
View file @
d0e45a23
org.gradle.jvmargs=-Xmx1536M
{{#androidX}}
android.useAndroidX=true
android.enableJetifier=true
{{/androidX}}
packages/flutter_tools/templates/module/android/gradle/gradle.properties.copy.tmpl
deleted
100644 → 0
View file @
16a23dd2
org.gradle.jvmargs=-Xmx1536M
packages/flutter_tools/templates/module/android/gradle/gradle.properties.tmpl
0 → 100644
View file @
d0e45a23
org.gradle.jvmargs=-Xmx1536M
{{#androidX}}
android.useAndroidX=true
android.enableJetifier=true
{{/androidX}}
packages/flutter_tools/templates/module/android/host_app_common/app.tmpl/build.gradle.tmpl
View file @
d0e45a23
...
...
@@ -16,7 +16,12 @@ android {
targetSdkVersion 28
versionCode 1
versionName "1.0"
{{#androidX}}
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
{{/androidX}}
{{^androidX}}
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
{{/androidX}}
}
buildTypes {
...
...
@@ -35,10 +40,18 @@ buildDir = new File(rootProject.projectDir, "../build/host")
dependencies {
implementation project(':flutter')
implementation fileTree(dir: 'libs', include: ['*.jar'])
{{#androidX}}
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
androidTestImplementation 'androidx.test:runner:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
{{/androidX}}
{{^androidX}}
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
implementation 'com.android.support:design:27.1.1'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
{{/androidX}}
testImplementation 'junit:junit:4.12'
}
packages/flutter_tools/templates/module/android/library/Flutter.tmpl/build.gradle.tmpl
View file @
d0e45a23
...
...
@@ -34,7 +34,12 @@ android {
targetSdkVersion 28
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
{{#androidX}}
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
{{/androidX}}
{{^androidX}}
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
{{/androidX}}
}
}
...
...
@@ -44,6 +49,11 @@ flutter {
dependencies {
testImplementation 'junit:junit:4.12'
{{#androidX}}
implementation 'androidx.appcompat:appcompat:1.0.2'
{{/androidX}}
{{^androidX}}
implementation 'com.android.support:support-v13:27.1.1'
implementation 'com.android.support:support-annotations:27.1.1'
{{/androidX}}
}
packages/flutter_tools/templates/module/android/library/Flutter.tmpl/src/main/java/io/flutter/facade/Flutter.java
→
packages/flutter_tools/templates/module/android/library/Flutter.tmpl/src/main/java/io/flutter/facade/Flutter.java
.tmpl
View file @
d0e45a23
package
io
.
flutter
.
facade
;
import
android
.
app
.
Activity
;
import
android
.
content
.
Context
;
import
android
.
os
.
Bundle
;
{{#
androidX
}}
import
androidx
.
annotation
.
NonNull
;
import
androidx
.
lifecycle
.
Lifecycle
;
import
androidx
.
lifecycle
.
LifecycleObserver
;
import
androidx
.
lifecycle
.
OnLifecycleEvent
;
{{/
androidX
}}
{{^
androidX
}}
import
android
.
arch
.
lifecycle
.
Lifecycle
;
import
android
.
arch
.
lifecycle
.
LifecycleObserver
;
import
android
.
arch
.
lifecycle
.
OnLifecycleEvent
;
import
android.content.Context
;
import
android.os.Bundle
;
import
android
.
support
.
annotation
.
NonNull
;
{{/
androidX
}}
import
io
.
flutter
.
plugin
.
common
.
BasicMessageChannel
;
import
io
.
flutter
.
plugin
.
common
.
StringCodec
;
import
io
.
flutter
.
plugins
.
GeneratedPluginRegistrant
;
import
io
.
flutter
.
view
.
FlutterMain
;
import
io
.
flutter
.
view
.
FlutterNativeView
;
import
io
.
flutter
.
view
.
FlutterRunArguments
;
import
io
.
flutter
.
view
.
FlutterView
;
import
io.flutter.plugins.GeneratedPluginRegistrant
;
/**
*
Main
entry
point
for
using
Flutter
in
Android
applications
.
...
...
packages/flutter_tools/templates/module/android/library/Flutter.tmpl/src/main/java/io/flutter/facade/FlutterFragment.java
→
packages/flutter_tools/templates/module/android/library/Flutter.tmpl/src/main/java/io/flutter/facade/FlutterFragment.java
.tmpl
View file @
d0e45a23
...
...
@@ -2,12 +2,18 @@ package io.flutter.facade;
import
android
.
content
.
Context
;
import
android
.
os
.
Bundle
;
import
android.support.annotation.NonNull
;
import
android.support.v4.app.Fragment
;
import
android
.
util
.
AttributeSet
;
import
android
.
view
.
LayoutInflater
;
import
android
.
view
.
ViewGroup
;
{{#
androidX
}}
import
androidx
.
annotation
.
NonNull
;
import
androidx
.
fragment
.
app
.
Fragment
;
{{/
androidX
}}
{{^
androidX
}}
import
android
.
support
.
annotation
.
NonNull
;
import
android
.
support
.
v4
.
app
.
Fragment
;
{{/
androidX
}}
import
io
.
flutter
.
view
.
FlutterView
;
/**
...
...
packages/flutter_tools/templates/plugin/android-java.tmpl/build.gradle.tmpl
View file @
d0e45a23
...
...
@@ -26,7 +26,12 @@ android {
defaultConfig {
minSdkVersion 16
{{#androidX}}
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
{{/androidX}}
{{^androidX}}
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
{{/androidX}}
}
lintOptions {
disable 'InvalidPackage'
...
...
packages/flutter_tools/templates/plugin/android-kotlin.tmpl/build.gradle.tmpl
View file @
d0e45a23
...
...
@@ -32,7 +32,12 @@ android {
}
defaultConfig {
minSdkVersion 16
{{#androidX}}
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
{{/androidX}}
{{^androidX}}
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
{{/androidX}}
}
lintOptions {
disable 'InvalidPackage'
...
...
packages/flutter_tools/templates/plugin/android.tmpl/gradle.properties
deleted
100644 → 0
View file @
16a23dd2
org.gradle.jvmargs
=
-Xmx1536M
packages/flutter_tools/templates/plugin/android.tmpl/gradle.properties.tmpl
0 → 100644
View file @
d0e45a23
org.gradle.jvmargs=-Xmx1536M
{{#androidX}}
android.useAndroidX=true
android.enableJetifier=true
{{/androidX}}
packages/flutter_tools/test/commands/create_test.dart
View file @
d0e45a23
...
...
@@ -378,6 +378,91 @@ void main() {
]);
},
timeout:
allowForRemotePubInvocation
);
testUsingContext
(
'androidx app project'
,
()
async
{
Cache
.
flutterRoot
=
'../..'
;
when
(
mockFlutterVersion
.
frameworkRevision
).
thenReturn
(
frameworkRevision
);
when
(
mockFlutterVersion
.
channel
).
thenReturn
(
frameworkChannel
);
final
CreateCommand
command
=
CreateCommand
();
final
CommandRunner
<
void
>
runner
=
createTestCommandRunner
(
command
);
await
runner
.
run
(<
String
>[
'create'
,
'--no-pub'
,
'--androidx'
,
projectDir
.
path
]);
void
expectExists
(
String
relPath
)
{
expect
(
fs
.
isFileSync
(
'
${projectDir.path}
/
$relPath
'
),
true
);
}
expectExists
(
'android/gradle.properties'
);
final
String
actualContents
=
await
fs
.
file
(
projectDir
.
path
+
'/android/gradle.properties'
).
readAsString
();
expect
(
actualContents
.
contains
(
'useAndroidX'
),
true
);
},
timeout:
allowForCreateFlutterProject
);
testUsingContext
(
'non androidx app project'
,
()
async
{
Cache
.
flutterRoot
=
'../..'
;
when
(
mockFlutterVersion
.
frameworkRevision
).
thenReturn
(
frameworkRevision
);
when
(
mockFlutterVersion
.
channel
).
thenReturn
(
frameworkChannel
);
final
CreateCommand
command
=
CreateCommand
();
final
CommandRunner
<
void
>
runner
=
createTestCommandRunner
(
command
);
await
runner
.
run
(<
String
>[
'create'
,
'--no-pub'
,
'--no-androidx'
,
projectDir
.
path
]);
void
expectExists
(
String
relPath
)
{
expect
(
fs
.
isFileSync
(
'
${projectDir.path}
/
$relPath
'
),
true
);
}
expectExists
(
'android/gradle.properties'
);
final
String
actualContents
=
await
fs
.
file
(
projectDir
.
path
+
'/android/gradle.properties'
).
readAsString
();
expect
(
actualContents
.
contains
(
'useAndroidX'
),
false
);
},
timeout:
allowForCreateFlutterProject
);
testUsingContext
(
'androidx plugin project'
,
()
async
{
Cache
.
flutterRoot
=
'../..'
;
when
(
mockFlutterVersion
.
frameworkRevision
).
thenReturn
(
frameworkRevision
);
when
(
mockFlutterVersion
.
channel
).
thenReturn
(
frameworkChannel
);
final
CreateCommand
command
=
CreateCommand
();
final
CommandRunner
<
void
>
runner
=
createTestCommandRunner
(
command
);
await
runner
.
run
(<
String
>[
'create'
,
'--no-pub'
,
'--template=plugin'
,
'--androidx'
,
projectDir
.
path
]);
void
expectExists
(
String
relPath
)
{
expect
(
fs
.
isFileSync
(
'
${projectDir.path}
/
$relPath
'
),
true
);
}
expectExists
(
'android/gradle.properties'
);
final
String
actualContents
=
await
fs
.
file
(
projectDir
.
path
+
'/android/gradle.properties'
).
readAsString
();
expect
(
actualContents
.
contains
(
'useAndroidX'
),
true
);
},
timeout:
allowForCreateFlutterProject
);
testUsingContext
(
'non androidx plugin project'
,
()
async
{
Cache
.
flutterRoot
=
'../..'
;
when
(
mockFlutterVersion
.
frameworkRevision
).
thenReturn
(
frameworkRevision
);
when
(
mockFlutterVersion
.
channel
).
thenReturn
(
frameworkChannel
);
final
CreateCommand
command
=
CreateCommand
();
final
CommandRunner
<
void
>
runner
=
createTestCommandRunner
(
command
);
await
runner
.
run
(<
String
>[
'create'
,
'--no-pub'
,
'--template=plugin'
,
'--no-androidx'
,
projectDir
.
path
]);
void
expectExists
(
String
relPath
)
{
expect
(
fs
.
isFileSync
(
'
${projectDir.path}
/
$relPath
'
),
true
);
}
expectExists
(
'android/gradle.properties'
);
final
String
actualContents
=
await
fs
.
file
(
projectDir
.
path
+
'/android/gradle.properties'
).
readAsString
();
expect
(
actualContents
.
contains
(
'useAndroidX'
),
false
);
},
timeout:
allowForCreateFlutterProject
);
testUsingContext
(
'has correct content and formatting with module template'
,
()
async
{
Cache
.
flutterRoot
=
'../..'
;
when
(
mockFlutterVersion
.
frameworkRevision
).
thenReturn
(
frameworkRevision
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment