Skip to content

Commit

Permalink
Merge pull request mmcc007#89 from mmcc007/#55_flavor_support
Browse files Browse the repository at this point in the history
Added flavor support
  • Loading branch information
mmcc007 authored Jul 23, 2019
2 parents 68758d1 + 4a2b810 commit 1aff4e3
Show file tree
Hide file tree
Showing 41 changed files with 1,513 additions and 18 deletions.
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,17 +89,19 @@ $ screenshots -c <path to config file>
Other options:
```
$ screenshots -h
usage: screenshots [-h] [-c <config file>] [-m <normal|recording|comparison|archive>]
usage: screenshots [-h] [-c <config file>] [-m <normal|recording|comparison|archive>] [-f <flavor>]
sample usage: screenshots
-c, --config=<screenshots.yaml> Path to config file.
(defaults to "screenshots.yaml")
-m, --mode=<normal|recording|comparison|archive> If mode is recording, screenshots will be saved for later comparison.
If mode is archive, screenshots will be archived and cannot be uploaded via fastlane.
If mode is comparison, screenshots will be compared with recorded.
If mode is archive, screenshots will be archived (and cannot be uploaded via fastlane).
[normal (default), recording, comparison, archive]
-f, --flavor=<flavor name> Flavor name.
-h, --help Display this help information.
```

Expand Down Expand Up @@ -134,7 +136,7 @@ Note: to turn off the debug banner on your screens, in your integration test's m
````

## Modifying tests based on screenshots environment
In some cases it is useful to know what device, device type, screen size and locale you are currently testing with. To obtain this information in your test use:
In some cases it is useful to know what device, device type, screen size, screen orientation and locale you are currently testing with. To obtain this information in your test use:
```
final screenshotsEnv = config.screenshotsEnv;
```
Expand Down
9 changes: 6 additions & 3 deletions bin/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@ import 'package:screenshots/screenshots.dart';
import 'package:path/path.dart' as path;

const usage =
'usage: screenshots [-h] [-c <config file>] [-m <normal|recording|comparison|archive>]';
'usage: screenshots [-h] [-c <config file>] [-m <normal|recording|comparison|archive>] [-f <flavor>]';
const sampleUsage = 'sample usage: screenshots';

void main(List<String> arguments) async {
ArgResults argResults;

final configArg = 'config';
final modeArg = 'mode';
final flavorArg = 'flavor';
final helpArg = 'help';
final ArgParser argParser = ArgParser(allowTrailingOptions: false)
..addOption(configArg,
Expand All @@ -24,9 +25,11 @@ void main(List<String> arguments) async {
abbr: 'm',
defaultsTo: 'normal',
help:
'If mode is recording, screenshots will be saved for later comparison. \nIf mode is archive, screenshots will be archived and cannot be uploaded via fastlane.',
'If mode is recording, screenshots will be saved for later comparison. \nIf mode is comparison, screenshots will be compared with recorded.\nIf mode is archive, screenshots will be archived (and cannot be uploaded via fastlane).',
allowed: ['normal', 'recording', 'comparison', 'archive'],
valueHelp: 'normal|recording|comparison|archive')
..addOption(flavorArg,
abbr: 'f', help: 'Flavor name.', valueHelp: 'flavor name')
..addFlag(helpArg,
abbr: 'h', help: 'Display this help information.', negatable: false);
try {
Expand Down Expand Up @@ -79,7 +82,7 @@ void main(List<String> arguments) async {
_handleError(argParser, "File not found: ${argResults[configArg]}");
}

await run(argResults[configArg], argResults[modeArg]);
await run(argResults[configArg], argResults[modeArg], argResults[flavorArg]);
}

void _handleError(ArgParser argParser, String msg) {
Expand Down
71 changes: 71 additions & 0 deletions flavors/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# Miscellaneous
*.class
*.lock
*.log
*.pyc
*.swp
.DS_Store
.atom/
.buildlog/
.history
.svn/

# IntelliJ related
*.iml
*.ipr
*.iws
.idea/

# Visual Studio Code related
.vscode/

# Flutter/Dart/Pub related
**/doc/api/
.dart_tool/
.flutter-plugins
.packages
.pub-cache/
.pub/
build/

# Android related
**/android/**/gradle-wrapper.jar
**/android/.gradle
**/android/captures/
**/android/gradlew
**/android/gradlew.bat
**/android/local.properties
**/android/**/GeneratedPluginRegistrant.java

# iOS/XCode related
**/ios/**/*.mode1v3
**/ios/**/*.mode2v3
**/ios/**/*.moved-aside
**/ios/**/*.pbxuser
**/ios/**/*.perspectivev3
**/ios/**/*sync/
**/ios/**/.sconsign.dblite
**/ios/**/.tags*
**/ios/**/.vagrant/
**/ios/**/DerivedData/
**/ios/**/Icon?
**/ios/**/Pods/
**/ios/**/.symlinks/
**/ios/**/profile
**/ios/**/xcuserdata
**/ios/.generated/
**/ios/Flutter/App.framework
**/ios/Flutter/Flutter.framework
**/ios/Flutter/Generated.xcconfig
**/ios/Flutter/app.flx
**/ios/Flutter/app.zip
**/ios/Flutter/flutter_assets/
**/ios/ServiceDefinitions.json
**/ios/Runner/GeneratedPluginRegistrant.*

# Exceptions to above rules.
!**/ios/**/default.mode1v3
!**/ios/**/default.mode2v3
!**/ios/**/default.pbxuser
!**/ios/**/default.perspectivev3
!/packages/flutter_tools/test/data/dart_dependencies_test/**/.packages
3 changes: 3 additions & 0 deletions flavors/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# flavors

Integration test of build flavors (Android product flavors, Xcode schemes).
63 changes: 63 additions & 0 deletions flavors/android/app/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
localPropertiesFile.withInputStream { stream ->
localProperties.load(stream)
}
}

def flutterRoot = localProperties.getProperty('flutter.sdk')
if (flutterRoot == null) {
throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
}

apply plugin: 'com.android.application'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

android {
compileSdkVersion 28

lintOptions {
disable 'InvalidPackage'
}

defaultConfig {
applicationId "com.yourcompany.flavors"
minSdkVersion 16
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}

buildTypes {
release {
signingConfig signingConfigs.debug
}
}

aaptOptions {
// TODO(goderbauer): remove when https://github.com/flutter/flutter/issues/8986 is resolved.
if(System.getenv("FLUTTER_CI_WIN")) {
println "AAPT cruncher disabled when running on Win CI."
cruncherEnabled false
}
}

flavorDimensions "mode"

productFlavors {
free {}
paid {}
}
}

flutter {
source '../..'
}

dependencies {
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'
}
21 changes: 21 additions & 0 deletions flavors/android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.yourcompany.flavors">

<uses-permission android:name="android.permission.INTERNET"/>

<application
android:name="io.flutter.app.FlutterApplication"
android:label="flavors">
<activity
android:name=".MainActivity"
android:launchMode="singleTop"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
android:hardwareAccelerated="true"
android:windowSoftInputMode="adjustResize">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>
</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.yourcompany.flavors;

import android.os.Bundle;

import io.flutter.app.FlutterActivity;
import io.flutter.plugin.common.MethodCall;
import io.flutter.plugin.common.MethodChannel;
import io.flutter.plugins.GeneratedPluginRegistrant;

public class MainActivity extends FlutterActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
GeneratedPluginRegistrant.registerWith(this);
new MethodChannel(getFlutterView(), "flavor").setMethodCallHandler(new MethodChannel.MethodCallHandler() {
@Override
public void onMethodCall(MethodCall methodCall, MethodChannel.Result result) {
result.success(BuildConfig.FLAVOR);
}
});
}
}
29 changes: 29 additions & 0 deletions flavors/android/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
buildscript {
repositories {
google()
jcenter()
}

dependencies {
classpath 'com.android.tools.build:gradle:3.2.1'
}
}

allprojects {
repositories {
google()
jcenter()
}
}

rootProject.buildDir = '../build'
subprojects {
project.buildDir = "${rootProject.buildDir}/${project.name}"
}
subprojects {
project.evaluationDependsOn(':app')
}

task clean(type: Delete) {
delete rootProject.buildDir
}
1 change: 1 addition & 0 deletions flavors/android/gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
org.gradle.jvmargs=-Xmx1536M
6 changes: 6 additions & 0 deletions flavors/android/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#Fri Jun 23 08:50:38 CEST 2017
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.2-all.zip
15 changes: 15 additions & 0 deletions flavors/android/settings.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
include ':app'

def flutterProjectRoot = rootProject.projectDir.parentFile.toPath()

def plugins = new Properties()
def pluginsFile = new File(flutterProjectRoot.toFile(), '.flutter-plugins')
if (pluginsFile.exists()) {
pluginsFile.withInputStream { stream -> plugins.load(stream) }
}

plugins.each { name, path ->
def pluginDirectory = flutterProjectRoot.resolve(path).resolve('android').toFile()
include ":$name"
project(":$name").projectDir = pluginDirectory
}
26 changes: 26 additions & 0 deletions flavors/ios/Flutter/AppFrameworkInfo.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>$(DEVELOPMENT_LANGUAGE)</string>
<key>CFBundleExecutable</key>
<string>App</string>
<key>CFBundleIdentifier</key>
<string>io.flutter.flutter.app</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>App</string>
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>1.0</string>
<key>MinimumOSVersion</key>
<string>8.0</string>
</dict>
</plist>
1 change: 1 addition & 0 deletions flavors/ios/Flutter/Debug.xcconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#include "Generated.xcconfig"
1 change: 1 addition & 0 deletions flavors/ios/Flutter/Release.xcconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#include "Generated.xcconfig"
Loading

0 comments on commit 1aff4e3

Please sign in to comment.