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
f172c827
Unverified
Commit
f172c827
authored
Dec 09, 2020
by
Emmanuel Garcia
Committed by
GitHub
Dec 09, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Ensure apps can build while using AGP 3.3.0 (#71964)
parent
8cd03a2e
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
108 additions
and
12 deletions
+108
-12
android_plugin_example_app_build_test.dart
...elab/bin/tasks/android_plugin_example_app_build_test.dart
+79
-6
flutter.gradle
packages/flutter_tools/gradle/flutter.gradle
+29
-6
No files found.
dev/devicelab/bin/tasks/android_plugin_example_app_build_test.dart
View file @
f172c827
...
@@ -15,7 +15,6 @@ final String gradlewExecutable = Platform.isWindows ? '.\\$gradlew' : './$gradle
...
@@ -15,7 +15,6 @@ final String gradlewExecutable = Platform.isWindows ? '.\\$gradlew' : './$gradle
/// Tests that a plugin example app can be built using the current Flutter Gradle plugin.
/// Tests that a plugin example app can be built using the current Flutter Gradle plugin.
Future
<
void
>
main
()
async
{
Future
<
void
>
main
()
async
{
await
task
(()
async
{
await
task
(()
async
{
section
(
'Find Java'
);
section
(
'Find Java'
);
final
String
javaHome
=
await
findJavaHome
();
final
String
javaHome
=
await
findJavaHome
();
...
@@ -32,22 +31,47 @@ Future<void> main() async {
...
@@ -32,22 +31,47 @@ Future<void> main() async {
options:
<
String
>[
'--android'
,
'--no-ios'
],
options:
<
String
>[
'--android'
,
'--no-ios'
],
);
);
final
Directory
tempDir
=
Directory
.
systemTemp
.
createTempSync
(
'flutter_plugin_test.'
);
final
Directory
tempDir
=
final
Directory
projectDir
=
Directory
(
path
.
join
(
tempDir
.
path
,
'plugin_test'
));
Directory
.
systemTemp
.
createTempSync
(
'flutter_plugin_test.'
);
final
Directory
projectDir
=
Directory
(
path
.
join
(
tempDir
.
path
,
'plugin_test'
));
try
{
try
{
await
inDirectory
(
tempDir
,
()
async
{
await
inDirectory
(
tempDir
,
()
async
{
await
flutter
(
await
flutter
(
'create'
,
'create'
,
options:
<
String
>[
'--template=plugin'
,
'--platforms=android'
,
'plugin_test'
],
options:
<
String
>[
'--template=plugin'
,
'--platforms=android'
,
'plugin_test'
,
],
);
);
});
});
final
Directory
exampleAppDir
=
Directory
(
path
.
join
(
projectDir
.
path
,
'example'
));
final
Directory
exampleAppDir
=
Directory
(
path
.
join
(
projectDir
.
path
,
'example'
));
if
(!
exists
(
exampleAppDir
))
{
if
(!
exists
(
exampleAppDir
))
{
return
TaskResult
.
failure
(
'Example app directory doesn
\'
t exist'
);
return
TaskResult
.
failure
(
'Example app directory doesn
\'
t exist'
);
}
}
section
(
'Run flutter build apk'
);
final
File
buildGradleFile
=
File
(
path
.
join
(
exampleAppDir
.
path
,
'android'
,
'build.gradle'
));
if
(!
exists
(
buildGradleFile
))
{
return
TaskResult
.
failure
(
'
$buildGradleFile
doesn
\'
t exist'
);
}
final
String
buildGradle
=
buildGradleFile
.
readAsStringSync
();
final
RegExp
androidPluginRegExp
=
RegExp
(
r'com\.android\.tools\.build:gradle:(\d+\.\d+\.\d+)'
);
section
(
'Use AGP 4.1.0'
);
String
newBuildGradle
=
buildGradle
.
replaceAll
(
androidPluginRegExp
,
'com.android.tools.build:gradle:4.1.0'
);
print
(
newBuildGradle
);
buildGradleFile
.
writeAsString
(
newBuildGradle
);
section
(
'Run flutter build apk using AGP 4.1.0'
);
await
inDirectory
(
exampleAppDir
,
()
async
{
await
inDirectory
(
exampleAppDir
,
()
async
{
await
flutter
(
await
flutter
(
...
@@ -72,6 +96,55 @@ Future<void> main() async {
...
@@ -72,6 +96,55 @@ Future<void> main() async {
return
TaskResult
.
failure
(
'Failed to build app-release.apk'
);
return
TaskResult
.
failure
(
'Failed to build app-release.apk'
);
}
}
section
(
'Clean'
);
await
inDirectory
(
exampleAppDir
,
()
async
{
await
flutter
(
'clean'
);
});
section
(
'Remove Gradle wrapper'
);
Directory
(
path
.
join
(
exampleAppDir
.
path
,
'android'
,
'gradle'
,
'wrapper'
))
.
deleteSync
(
recursive:
true
);
section
(
'Use AGP 3.3.0'
);
newBuildGradle
=
buildGradle
.
replaceAll
(
androidPluginRegExp
,
'com.android.tools.build:gradle:3.3.0'
);
print
(
newBuildGradle
);
buildGradleFile
.
writeAsString
(
newBuildGradle
);
section
(
'Enable R8 in gradle.properties'
);
final
File
gradleProperties
=
File
(
path
.
join
(
exampleAppDir
.
path
,
'android'
,
'gradle.properties'
));
if
(!
exists
(
gradleProperties
))
{
return
TaskResult
.
failure
(
'
$gradleProperties
doesn
\'
t exist'
);
}
gradleProperties
.
writeAsString
(
'''
org.gradle.jvmargs=-Xmx1536M
android.useAndroidX=true
android.enableJetifier=true
android.enableR8=true'''
);
section
(
'Run flutter build apk using AGP 3.3.0'
);
await
inDirectory
(
exampleAppDir
,
()
async
{
await
flutter
(
'build'
,
options:
<
String
>[
'apk'
,
'--target-platform=android-arm'
,
],
);
});
if
(!
exists
(
File
(
exampleApk
)))
{
return
TaskResult
.
failure
(
'Failed to build app-release.apk'
);
}
return
TaskResult
.
success
(
null
);
return
TaskResult
.
success
(
null
);
}
on
TaskResult
catch
(
taskResult
)
{
}
on
TaskResult
catch
(
taskResult
)
{
return
taskResult
;
return
taskResult
;
...
...
packages/flutter_tools/gradle/flutter.gradle
View file @
f172c827
...
@@ -20,6 +20,7 @@ import org.gradle.api.tasks.InputFiles
...
@@ -20,6 +20,7 @@ import org.gradle.api.tasks.InputFiles
import
org.gradle.api.tasks.OutputDirectory
import
org.gradle.api.tasks.OutputDirectory
import
org.gradle.api.tasks.TaskAction
import
org.gradle.api.tasks.TaskAction
import
org.gradle.api.tasks.bundling.Jar
import
org.gradle.api.tasks.bundling.Jar
import
org.gradle.util.VersionNumber
buildscript
{
buildscript
{
repositories
{
repositories
{
...
@@ -304,7 +305,7 @@ class FlutterPlugin implements Plugin<Project> {
...
@@ -304,7 +305,7 @@ class FlutterPlugin implements Plugin<Project> {
project
.
dependencies
{
project
.
dependencies
{
implementation
pluginProject
implementation
pluginProject
}
}
Closure
addEmbedding
CompileOnlyDependency
=
{
buildType
->
Closure
addEmbedding
DependencyToPlugin
=
{
buildType
->
String
flutterBuildMode
=
buildModeFor
(
buildType
)
String
flutterBuildMode
=
buildModeFor
(
buildType
)
// In AGP 3.5, the embedding must be added as an API implementation,
// In AGP 3.5, the embedding must be added as an API implementation,
// so java8 features are desugared against the runtime classpath.
// so java8 features are desugared against the runtime classpath.
...
@@ -317,17 +318,39 @@ class FlutterPlugin implements Plugin<Project> {
...
@@ -317,17 +318,39 @@ class FlutterPlugin implements Plugin<Project> {
pluginProject
.
android
.
buildTypes
{
pluginProject
.
android
.
buildTypes
{
"${buildType.name}"
{}
"${buildType.name}"
{}
}
}
pluginProject
.
dependencies
.
add
(
// The embedding is a compileOnly dependency of a Flutter plugin,
"${buildType.name}CompileOnly"
,
// however prior to Gradle 6.0.0, it must be an API dependency.
"io.flutter:flutter_embedding_$flutterBuildMode:$engineVersion"
)
//
// Not doing so, causes transitive dependency resolution conflicts.
// That is, the embedding dependencies resolved in the plugin are
// different than the ones resolved in the app.
if
(
isGradleVersionGraterOrEqualThan
(
'6.0.0'
))
{
addCompileOnlyDependency
(
pluginProject
,
buildType
.
name
,
"io.flutter:flutter_embedding_$flutterBuildMode:$engineVersion"
)
}
else
{
addApiDependencies
(
pluginProject
,
buildType
.
name
,
"io.flutter:flutter_embedding_$flutterBuildMode:$engineVersion"
)
}
}
}
// Wait until the Android plugin loaded.
// Wait until the Android plugin loaded.
pluginProject
.
afterEvaluate
{
pluginProject
.
afterEvaluate
{
project
.
android
.
buildTypes
.
each
addEmbedding
CompileOnlyDependency
project
.
android
.
buildTypes
.
each
addEmbedding
DependencyToPlugin
project
.
android
.
buildTypes
.
whenObjectAdded
addEmbedding
CompileOnlyDependency
project
.
android
.
buildTypes
.
whenObjectAdded
addEmbedding
DependencyToPlugin
}
}
}
}
// Returns `true` if the current Gradle version is greater or equal to the given version.
private
isGradleVersionGraterOrEqualThan
(
String
version
)
{
return
VersionNumber
.
parse
(
project
.
gradle
.
gradleVersion
)
.
compareTo
(
VersionNumber
.
parse
(
version
))
>=
0
}
// Returns `true` if the given path contains an `android/build.gradle` file.
// Returns `true` if the given path contains an `android/build.gradle` file.
//
//
// TODO(egarciad): Fix https://github.com/flutter/flutter/issues/39657.
// TODO(egarciad): Fix https://github.com/flutter/flutter/issues/39657.
...
...
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