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
40c5cc97
Unverified
Commit
40c5cc97
authored
Aug 02, 2019
by
Emmanuel Garcia
Committed by
GitHub
Aug 02, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Find the app bundle when the flavor contains underscores (#37457)
parent
80ee3dd0
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
266 additions
and
46 deletions
+266
-46
gradle_plugin_bundle_test.dart
dev/devicelab/bin/tasks/gradle_plugin_bundle_test.dart
+100
-30
gradle.dart
packages/flutter_tools/lib/src/android/gradle.dart
+22
-16
gradle_test.dart
...flutter_tools/test/general.shard/android/gradle_test.dart
+144
-0
No files found.
dev/devicelab/bin/tasks/gradle_plugin_bundle_test.dart
View file @
40c5cc97
...
...
@@ -17,17 +17,14 @@ Future<void> main() async {
await
project
.
runGradleTask
(
'bundleRelease'
);
final
String
releaseBundle
=
path
.
join
(
project
.
rootPath
,
'build'
,
'app'
,
'outputs'
,
'bundle'
,
'release'
,
'app.aab'
,
);
final
Iterable
<
String
>
bundleFiles
=
await
getFilesInAppBundle
(
releaseBundle
);
project
.
rootPath
,
'build'
,
'app'
,
'outputs'
,
'bundle'
,
'release'
,
'app.aab'
,
);
checkItContains
<
String
>(<
String
>[
'base/manifest/AndroidManifest.xml'
,
'base/dex/classes.dex'
,
...
...
@@ -35,28 +32,66 @@ Future<void> main() async {
'base/lib/arm64-v8a/libflutter.so'
,
'base/lib/armeabi-v7a/libapp.so'
,
'base/lib/armeabi-v7a/libflutter.so'
,
],
bundleFiles
);
],
await
getFilesInAppBundle
(
releaseBundle
)
);
});
await
runProjectTest
((
FlutterProject
project
)
async
{
section
(
'App bundle content using flavors without explicit target platform'
);
// Add a few flavors.
await
project
.
addProductFlavors
(<
String
>
[
'production'
,
'staging'
,
'development'
]);
await
project
.
addProductFlavors
(<
String
>
[
'production'
,
'staging'
,
'development'
,
'flavor_underscore'
,
// https://github.com/flutter/flutter/issues/36067
]);
// Build the production flavor in release mode.
await
project
.
runGradleTask
(
'bundleProductionRelease'
);
final
String
bundlePath
=
path
.
join
(
project
.
rootPath
,
final
String
bundleFromGradlePath
=
path
.
join
(
project
.
rootPath
,
'build'
,
'app'
,
'outputs'
,
'bundle'
,
'productionRelease'
,
'app.aab'
,
);
checkItContains
<
String
>(<
String
>[
'base/manifest/AndroidManifest.xml'
,
'base/dex/classes.dex'
,
'base/lib/arm64-v8a/libapp.so'
,
'base/lib/arm64-v8a/libflutter.so'
,
'base/lib/armeabi-v7a/libapp.so'
,
'base/lib/armeabi-v7a/libflutter.so'
,
],
await
getFilesInAppBundle
(
bundleFromGradlePath
));
section
(
'Build app bundle using the flutter tool - flavor: flavor_underscore'
);
int
exitCode
;
await
inDirectory
(
project
.
rootPath
,
()
async
{
exitCode
=
await
flutter
(
'build'
,
'app'
,
'outputs
'
,
'bundl
e'
,
'productionRelea
se'
,
'app.aab'
,
options:
<
String
>[
'appbundle
'
,
'--flavor=flavor_underscor
e'
,
'--verbo
se'
,
]
,
);
});
final
Iterable
<
String
>
bundleFiles
=
await
getFilesInAppBundle
(
bundlePath
);
if
(
exitCode
!=
0
)
{
throw
TaskResult
.
failure
(
'flutter build appbundle command exited with code:
$exitCode
'
);
}
final
String
flavorUnderscoreBundlePath
=
path
.
join
(
project
.
rootPath
,
'build'
,
'app'
,
'outputs'
,
'bundle'
,
'flavor_underscoreRelease'
,
'app.aab'
,
);
checkItContains
<
String
>(<
String
>[
'base/manifest/AndroidManifest.xml'
,
'base/dex/classes.dex'
,
...
...
@@ -64,7 +99,42 @@ Future<void> main() async {
'base/lib/arm64-v8a/libflutter.so'
,
'base/lib/armeabi-v7a/libapp.so'
,
'base/lib/armeabi-v7a/libflutter.so'
,
],
bundleFiles
);
],
await
getFilesInAppBundle
(
flavorUnderscoreBundlePath
));
section
(
'Build app bundle using the flutter tool - flavor: production'
);
await
inDirectory
(
project
.
rootPath
,
()
async
{
exitCode
=
await
flutter
(
'build'
,
options:
<
String
>[
'appbundle'
,
'--flavor=production'
,
'--verbose'
,
],
);
});
if
(
exitCode
!=
0
)
{
throw
TaskResult
.
failure
(
'flutter build appbundle command exited with code:
$exitCode
'
);
}
final
String
productionBundlePath
=
path
.
join
(
project
.
rootPath
,
'build'
,
'app'
,
'outputs'
,
'bundle'
,
'productionRelease'
,
'app.aab'
,
);
checkItContains
<
String
>(<
String
>[
'base/manifest/AndroidManifest.xml'
,
'base/dex/classes.dex'
,
'base/lib/arm64-v8a/libapp.so'
,
'base/lib/arm64-v8a/libflutter.so'
,
'base/lib/armeabi-v7a/libapp.so'
,
'base/lib/armeabi-v7a/libflutter.so'
,
],
await
getFilesInAppBundle
(
productionBundlePath
));
});
await
runProjectTest
((
FlutterProject
project
)
async
{
...
...
@@ -73,14 +143,14 @@ Future<void> main() async {
options:
<
String
>[
'-Ptarget-platform=android-arm'
]);
final
String
releaseBundle
=
path
.
join
(
project
.
rootPath
,
'build'
,
'app'
,
'outputs'
,
'bundle'
,
'release'
,
'app.aab'
,
);
project
.
rootPath
,
'build'
,
'app'
,
'outputs'
,
'bundle'
,
'release'
,
'app.aab'
,
);
final
Iterable
<
String
>
bundleFiles
=
await
getFilesInAppBundle
(
releaseBundle
);
...
...
packages/flutter_tools/lib/src/android/gradle.dart
View file @
40c5cc97
...
...
@@ -775,7 +775,7 @@ Future<void> _buildGradleProjectV2(
color:
TerminalColor
.
green
);
}
}
else
{
final
File
bundleFile
=
_
findBundleFile
(
project
,
buildInfo
);
final
File
bundleFile
=
findBundleFile
(
project
,
buildInfo
);
if
(
bundleFile
==
null
)
throwToolExit
(
'Gradle build failed to produce an Android bundle package.'
);
...
...
@@ -820,24 +820,30 @@ Iterable<File> findApkFiles(GradleProject project, AndroidBuildInfo androidBuild
});
}
File
_findBundleFile
(
GradleProject
project
,
BuildInfo
buildInfo
)
{
@visibleForTesting
File
findBundleFile
(
GradleProject
project
,
BuildInfo
buildInfo
)
{
final
String
bundleFileName
=
project
.
bundleFileFor
(
buildInfo
);
if
(
bundleFileName
==
null
)
if
(
bundleFileName
==
null
)
{
return
null
;
final
String
modeName
=
camelCase
(
buildInfo
.
modeName
);
File
bundleFile
=
project
.
bundleDirectory
.
childDirectory
(
modeName
).
childFile
(
bundleFileName
);
if
(
bundleFile
.
existsSync
())
}
File
bundleFile
=
project
.
bundleDirectory
.
childDirectory
(
camelCase
(
buildInfo
.
modeName
))
.
childFile
(
bundleFileName
);
if
(
bundleFile
.
existsSync
())
{
return
bundleFile
;
}
if
(
buildInfo
.
flavor
==
null
)
{
return
null
;
}
// Android Studio Gradle plugin v3 adds the flavor to the path. For the bundle the
// folder name is the flavor plus the mode name. On Windows, filenames aren't case sensitive.
// For example: foo_barRelease where `foo_bar` is the flavor and `Release` the mode name.
final
String
childDirName
=
'
${buildInfo.flavor}${camelCase('_' + buildInfo.modeName)}
'
;
bundleFile
=
project
.
bundleDirectory
.
childDirectory
(
childDirName
)
.
childFile
(
bundleFileName
);
if
(
bundleFile
.
existsSync
())
{
return
bundleFile
;
if
(
buildInfo
.
flavor
!=
null
)
{
// Android Studio Gradle plugin v3 adds the flavor to the path. For the bundle the folder name is the flavor plus the mode name.
// On linux, filenames are case sensitive.
bundleFile
=
project
.
bundleDirectory
.
childDirectory
(
camelCase
(
'
${buildInfo.flavor}
_
$modeName
'
))
.
childFile
(
bundleFileName
);
if
(
bundleFile
.
existsSync
())
return
bundleFile
;
}
return
null
;
}
...
...
packages/flutter_tools/test/general.shard/android/gradle_test.dart
View file @
40c5cc97
...
...
@@ -117,6 +117,150 @@ void main() {
expect
(
ndkMessageFilter
.
hasMatch
(
m
),
isTrue
);
}
});
testUsingContext
(
'Finds app bundle when flavor contains underscores in release mode'
,
()
{
final
GradleProject
gradleProject
=
MockGradleProject
();
when
(
gradleProject
.
bundleDirectory
).
thenReturn
(
fs
.
currentDirectory
);
when
(
gradleProject
.
bundleFileFor
(
any
)).
thenReturn
(
'app.aab'
);
final
Directory
aabDirectory
=
gradleProject
.
bundleDirectory
.
childDirectory
(
'foo_barRelease'
);
fs
.
directory
(
aabDirectory
).
createSync
(
recursive:
true
);
fs
.
file
(
fs
.
path
.
join
(
aabDirectory
.
path
,
'app.aab'
)).
writeAsStringSync
(
'irrelevant'
);
final
File
bundle
=
findBundleFile
(
gradleProject
,
const
BuildInfo
(
BuildMode
.
release
,
'foo_bar'
));
expect
(
bundle
,
isNotNull
);
expect
(
bundle
.
path
,
'/foo_barRelease/app.aab'
);
},
overrides:
<
Type
,
Generator
>{
FileSystem:
()
=>
MemoryFileSystem
(),
});
testUsingContext
(
'Finds app bundle when flavor doesn
\'
t contain underscores in release mode'
,
()
{
final
GradleProject
gradleProject
=
MockGradleProject
();
when
(
gradleProject
.
bundleDirectory
).
thenReturn
(
fs
.
currentDirectory
);
when
(
gradleProject
.
bundleFileFor
(
any
)).
thenReturn
(
'app.aab'
);
final
Directory
aabDirectory
=
gradleProject
.
bundleDirectory
.
childDirectory
(
'fooRelease'
);
fs
.
directory
(
aabDirectory
).
createSync
(
recursive:
true
);
fs
.
file
(
fs
.
path
.
join
(
aabDirectory
.
path
,
'app.aab'
)).
writeAsStringSync
(
'irrelevant'
);
final
File
bundle
=
findBundleFile
(
gradleProject
,
const
BuildInfo
(
BuildMode
.
release
,
'foo'
));
expect
(
bundle
,
isNotNull
);
expect
(
bundle
.
path
,
'/fooRelease/app.aab'
);
},
overrides:
<
Type
,
Generator
>{
FileSystem:
()
=>
MemoryFileSystem
(),
});
testUsingContext
(
'Finds app bundle when no flavor is used in release mode'
,
()
{
final
GradleProject
gradleProject
=
MockGradleProject
();
when
(
gradleProject
.
bundleDirectory
).
thenReturn
(
fs
.
currentDirectory
);
when
(
gradleProject
.
bundleFileFor
(
any
)).
thenReturn
(
'app.aab'
);
final
Directory
aabDirectory
=
gradleProject
.
bundleDirectory
.
childDirectory
(
'release'
);
fs
.
directory
(
aabDirectory
).
createSync
(
recursive:
true
);
fs
.
file
(
fs
.
path
.
join
(
aabDirectory
.
path
,
'app.aab'
)).
writeAsStringSync
(
'irrelevant'
);
final
File
bundle
=
findBundleFile
(
gradleProject
,
const
BuildInfo
(
BuildMode
.
release
,
null
));
expect
(
bundle
,
isNotNull
);
expect
(
bundle
.
path
,
'/release/app.aab'
);
},
overrides:
<
Type
,
Generator
>{
FileSystem:
()
=>
MemoryFileSystem
(),
});
testUsingContext
(
'Finds app bundle when flavor contains underscores in debug mode'
,
()
{
final
GradleProject
gradleProject
=
MockGradleProject
();
when
(
gradleProject
.
bundleDirectory
).
thenReturn
(
fs
.
currentDirectory
);
when
(
gradleProject
.
bundleFileFor
(
any
)).
thenReturn
(
'app.aab'
);
final
Directory
aabDirectory
=
gradleProject
.
bundleDirectory
.
childDirectory
(
'foo_barDebug'
);
fs
.
directory
(
aabDirectory
).
createSync
(
recursive:
true
);
fs
.
file
(
fs
.
path
.
join
(
aabDirectory
.
path
,
'app.aab'
)).
writeAsStringSync
(
'irrelevant'
);
final
File
bundle
=
findBundleFile
(
gradleProject
,
const
BuildInfo
(
BuildMode
.
debug
,
'foo_bar'
));
expect
(
bundle
,
isNotNull
);
expect
(
bundle
.
path
,
'/foo_barDebug/app.aab'
);
},
overrides:
<
Type
,
Generator
>{
FileSystem:
()
=>
MemoryFileSystem
(),
});
testUsingContext
(
'Finds app bundle when flavor doesn
\'
t contain underscores in debug mode'
,
()
{
final
GradleProject
gradleProject
=
MockGradleProject
();
when
(
gradleProject
.
bundleDirectory
).
thenReturn
(
fs
.
currentDirectory
);
when
(
gradleProject
.
bundleFileFor
(
any
)).
thenReturn
(
'app.aab'
);
final
Directory
aabDirectory
=
gradleProject
.
bundleDirectory
.
childDirectory
(
'fooDebug'
);
fs
.
directory
(
aabDirectory
).
createSync
(
recursive:
true
);
fs
.
file
(
fs
.
path
.
join
(
aabDirectory
.
path
,
'app.aab'
)).
writeAsStringSync
(
'irrelevant'
);
final
File
bundle
=
findBundleFile
(
gradleProject
,
const
BuildInfo
(
BuildMode
.
debug
,
'foo'
));
expect
(
bundle
,
isNotNull
);
expect
(
bundle
.
path
,
'/fooDebug/app.aab'
);
},
overrides:
<
Type
,
Generator
>{
FileSystem:
()
=>
MemoryFileSystem
(),
});
testUsingContext
(
'Finds app bundle when no flavor is used in debug mode'
,
()
{
final
GradleProject
gradleProject
=
MockGradleProject
();
when
(
gradleProject
.
bundleDirectory
).
thenReturn
(
fs
.
currentDirectory
);
when
(
gradleProject
.
bundleFileFor
(
any
)).
thenReturn
(
'app.aab'
);
final
Directory
aabDirectory
=
gradleProject
.
bundleDirectory
.
childDirectory
(
'debug'
);
fs
.
directory
(
aabDirectory
).
createSync
(
recursive:
true
);
fs
.
file
(
fs
.
path
.
join
(
aabDirectory
.
path
,
'app.aab'
)).
writeAsStringSync
(
'irrelevant'
);
final
File
bundle
=
findBundleFile
(
gradleProject
,
const
BuildInfo
(
BuildMode
.
debug
,
null
));
expect
(
bundle
,
isNotNull
);
expect
(
bundle
.
path
,
'/debug/app.aab'
);
},
overrides:
<
Type
,
Generator
>{
FileSystem:
()
=>
MemoryFileSystem
(),
});
testUsingContext
(
'Finds app bundle when flavor contains underscores in profile mode'
,
()
{
final
GradleProject
gradleProject
=
MockGradleProject
();
when
(
gradleProject
.
bundleDirectory
).
thenReturn
(
fs
.
currentDirectory
);
when
(
gradleProject
.
bundleFileFor
(
any
)).
thenReturn
(
'app.aab'
);
final
Directory
aabDirectory
=
gradleProject
.
bundleDirectory
.
childDirectory
(
'foo_barProfile'
);
fs
.
directory
(
aabDirectory
).
createSync
(
recursive:
true
);
fs
.
file
(
fs
.
path
.
join
(
aabDirectory
.
path
,
'app.aab'
)).
writeAsStringSync
(
'irrelevant'
);
final
File
bundle
=
findBundleFile
(
gradleProject
,
const
BuildInfo
(
BuildMode
.
profile
,
'foo_bar'
));
expect
(
bundle
,
isNotNull
);
expect
(
bundle
.
path
,
'/foo_barProfile/app.aab'
);
},
overrides:
<
Type
,
Generator
>{
FileSystem:
()
=>
MemoryFileSystem
(),
});
testUsingContext
(
'Finds app bundle when flavor doesn
\'
t contain underscores in profile mode'
,
()
{
final
GradleProject
gradleProject
=
MockGradleProject
();
when
(
gradleProject
.
bundleDirectory
).
thenReturn
(
fs
.
currentDirectory
);
when
(
gradleProject
.
bundleFileFor
(
any
)).
thenReturn
(
'app.aab'
);
final
Directory
aabDirectory
=
gradleProject
.
bundleDirectory
.
childDirectory
(
'fooProfile'
);
fs
.
directory
(
aabDirectory
).
createSync
(
recursive:
true
);
fs
.
file
(
fs
.
path
.
join
(
aabDirectory
.
path
,
'app.aab'
)).
writeAsStringSync
(
'irrelevant'
);
final
File
bundle
=
findBundleFile
(
gradleProject
,
const
BuildInfo
(
BuildMode
.
profile
,
'foo'
));
expect
(
bundle
,
isNotNull
);
expect
(
bundle
.
path
,
'/fooProfile/app.aab'
);
},
overrides:
<
Type
,
Generator
>{
FileSystem:
()
=>
MemoryFileSystem
(),
});
testUsingContext
(
'Finds app bundle when no flavor is used in profile mode'
,
()
{
final
GradleProject
gradleProject
=
MockGradleProject
();
when
(
gradleProject
.
bundleDirectory
).
thenReturn
(
fs
.
currentDirectory
);
when
(
gradleProject
.
bundleFileFor
(
any
)).
thenReturn
(
'app.aab'
);
final
Directory
aabDirectory
=
gradleProject
.
bundleDirectory
.
childDirectory
(
'profile'
);
fs
.
directory
(
aabDirectory
).
createSync
(
recursive:
true
);
fs
.
file
(
fs
.
path
.
join
(
aabDirectory
.
path
,
'app.aab'
)).
writeAsStringSync
(
'irrelevant'
);
final
File
bundle
=
findBundleFile
(
gradleProject
,
const
BuildInfo
(
BuildMode
.
profile
,
null
));
expect
(
bundle
,
isNotNull
);
expect
(
bundle
.
path
,
'/profile/app.aab'
);
},
overrides:
<
Type
,
Generator
>{
FileSystem:
()
=>
MemoryFileSystem
(),
});
});
group
(
'gradle project'
,
()
{
...
...
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