Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 3 additions & 10 deletions testing/scenario_app/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,19 +60,12 @@ Compiling to JIT mode is similar, using the `compile_ios_jit.sh` script.

## Building for Android

In this folder, after building the `host_profile` and `android_profile_arm64`
engine targets, run:

In this directory, run:
```bash
./compile_android_aot.sh ../../../out/host_profile ../../../out/android_profile_arm64/clang_x64/
./run_android_tests.sh <local-engine>
```

This will produce a suitable `libapp.so` for building with an Android app and
copy it (along with flutter.jar) to where Gradle will expect to find it to build
the app in the `android/` folder. The app can be run by opening it in Android
Studio and running it, or by running `./gradlew assemble` in the `android/`
folder and installing the APK from the correct folder in
`android/app/build/outputs/apk`.
The `local-engine` flag is similar to the flag you would pass to the `flutter` CLI.

## Changing dart:ui code

Expand Down
29 changes: 20 additions & 9 deletions testing/scenario_app/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,33 @@ android {
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'com.google.android.material:material:1.0.0'
implementation 'androidx.lifecycle:lifecycle-common-java8:2.2.0-alpha01'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test:rules:1.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
}

def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
localPropertiesFile.withReader('UTF-8') { reader ->
localProperties.load(reader)
}
}

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.")
}

// Load the Flutter Gradle plugin.
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

flutter {
source '../..'
}
21 changes: 0 additions & 21 deletions testing/scenario_app/android/app/proguard-rules.pro

This file was deleted.

15 changes: 1 addition & 14 deletions testing/scenario_app/android/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,15 +1,2 @@
# Project-wide Gradle settings.
# IDE (e.g. Android Studio) users:
# Gradle settings configured through the IDE *will override*
# any settings specified in this file.
# For more details on how to configure your build environment visit
# http://www.gradle.org/docs/current/userguide/build_environment.html
# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
org.gradle.jvmargs=-Xmx1536m
# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true


android.enableR8=true
121 changes: 114 additions & 7 deletions testing/scenario_app/run_android_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,127 @@

# Runs the Android scenario tests on a connected device.

if [ -z $ENGINE_PATH ]
then
echo "Please set ENGINE_PATH environment variable. e.g. \`export ENGINE_PATH='<engine-path>'\`"
exit 1
fi

if [ -z $ANDROID_SDK_ROOT ]
then
echo "Please set ANDROID_SDK_ROOT environment variable. e.g. \`export ANDROID_SDK_ROOT='<sdk-path>'\`"
exit 1
fi

LOCAL_ENGINE=$1

if [ -z "$LOCAL_ENGINE" ]
then
echo "Must specify a local engine. e.g. \`./run_android_tests.sh android_debug_unopt_x64\`"
exit 1
fi

CLONE_FLUTTER=$ENGINE_PATH/src/flutter/tools/clone_flutter.sh
DART_TOOL_DIR=$ENGINE_PATH/src/flutter/.dart_tool

echo "$(date) START:CLONE_FLUTTER ------------------------------------------"
"$CLONE_FLUTTER" "$DART_TOOL_DIR"
echo "$(date) END:CLONE_FLUTTER ------------------------------------------"

set -e

FLUTTER_ENGINE=android_profile_unopt_arm64
FLUTTER_REPO=$ENGINE_PATH/src/flutter/.dart_tool/flutter
FLUTTER_TOOL=$FLUTTER_REPO/bin/flutter
SCENARIO_APP=$ENGINE_PATH/src/flutter/testing/scenario_app

if [ -z "$FLUTTER_TOOL" ]
then
echo "Flutter tool not found. Try to look for $FLUTTER_TOOL."
exit 1
fi

echo "Using Flutter tool: $FLUTTER_TOOL."

pushd "${BASH_SOURCE%/*}"
echo "$(date) START:PUB_GET ------------------------------------------"
"$FLUTTER_TOOL" pub get --offline --local-engine-src-path "$ENGINE_PATH/src" --local-engine="$LOCAL_ENGINE"
echo "$(date) END:PUB_GET ------------------------------------------"
popd

echo "$(date) START:WRITE_LOCAL_PROPERTIES ------------------------------------------"
cat > $SCENARIO_APP/android/local.properties << EOF
flutter.sdk=$FLUTTER_REPO
sdk.dir=$ANDROID_SDK_ROOT
EOF
echo "$(date) END:WRITE_LOCAL_PROPERTIES ------------------------------------------"

if [[ "$LOCAL_ENGINE" =~ debug ]]
then
BUILD_MODE="debug"
elif [[ "$LOCAL_ENGINE" =~ profile ]]
then
BUILD_MODE="profile"
elif [[ "$LOCAL_ENGINE" =~ release ]]
then
BUILD_MODE="relase"
else
echo "Couldn't determinate build mode from: $LOCAL_ENGINE"
exit 1
fi

EMBEDDING_ARTIFACT_ID="flutter_embedding_$BUILD_MODE"

if [ $# -eq 1 ]; then
FLUTTER_ENGINE=$1
if [[ "$LOCAL_ENGINE" =~ x64 ]]
then
LIB_FLUTTER_ARTIFACT_ID="x86_64_$BUILD_MODE"
TARGET_PLATFORM="android-x64"
elif [[ "$LOCAL_ENGINE" =~ x86 ]]
then
LIB_FLUTTER_ARTIFACT_ID="x86_$BUILD_MODE"
TARGET_PLATFORM="android-x86"
elif [[ "$LOCAL_ENGINE" =~ arm64 ]]
then
LIB_FLUTTER_ARTIFACT_ID="arm64_$BUILD_MODE"
TARGET_PLATFORM="android-arm64"
elif [[ "$LOCAL_ENGINE" =~ arm ]]
then
LIB_FLUTTER_ARTIFACT_ID="arm_$BUILD_MODE"
TARGET_PLATFORM="android-arm"
else
echo "Couldn't determinate arch from: $LOCAL_ENGINE"
exit 1
fi

cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd
# This is `1.0.0-<engine-hash>`
FLUTTER_POM_VERSION=`sed -n -e 's/.*<version>\(.*\)<\/version>.*/\1/p' "$ENGINE_PATH/src/out/$LOCAL_ENGINE/$LIB_FLUTTER_ARTIFACT_ID.pom"`

./compile_android_aot.sh ../../../out/host_profile_unopt_arm64 ../../../out/$FLUTTER_ENGINE/clang_x64
# Delete the maven repo before exiting.
reboot() {
echo "$(date) START:REMOVE_MAVEN_REPO ------------------------------------------"
rm -rf "$SCENARIO_APP/.repo"
echo "$(date) END:REMOVE_MAVEN_REPO --------------------------------------------"
}
trap reboot EXIT

pushd android
# Create Maven repo, which is just symlinks to the files in the `out` directory.
echo "$(date) START:LOCAL_MAVEN_REPO ------------------------------------------"
mkdir -p "$SCENARIO_APP/.repo/io/flutter/$LIB_FLUTTER_ARTIFACT_ID/$FLUTTER_POM_VERSION/"
ln -s "$ENGINE_PATH/src/out/$LOCAL_ENGINE/$LIB_FLUTTER_ARTIFACT_ID.pom" "$SCENARIO_APP/.repo/io/flutter/$LIB_FLUTTER_ARTIFACT_ID/$FLUTTER_POM_VERSION/$LIB_FLUTTER_ARTIFACT_ID-$FLUTTER_POM_VERSION.pom"
ln -s "$ENGINE_PATH/src/out/$LOCAL_ENGINE/$LIB_FLUTTER_ARTIFACT_ID.jar" "$SCENARIO_APP/.repo/io/flutter/$LIB_FLUTTER_ARTIFACT_ID/$FLUTTER_POM_VERSION/$LIB_FLUTTER_ARTIFACT_ID-$FLUTTER_POM_VERSION.jar"

set -o pipefail && ./gradlew assembleAndroidTest && ./gradlew connectedAndroidTest
mkdir -p "$SCENARIO_APP/.repo/io/flutter/$EMBEDDING_ARTIFACT_ID/$FLUTTER_POM_VERSION/"
ln -s "$ENGINE_PATH/src/out/$LOCAL_ENGINE/$EMBEDDING_ARTIFACT_ID.pom" "$SCENARIO_APP/.repo/io/flutter/$EMBEDDING_ARTIFACT_ID/$FLUTTER_POM_VERSION/$EMBEDDING_ARTIFACT_ID-$FLUTTER_POM_VERSION.pom"
ln -s "$ENGINE_PATH/src/out/$LOCAL_ENGINE/$EMBEDDING_ARTIFACT_ID.jar" "$SCENARIO_APP/.repo/io/flutter/$EMBEDDING_ARTIFACT_ID/$FLUTTER_POM_VERSION/$EMBEDDING_ARTIFACT_ID-$FLUTTER_POM_VERSION.jar"
echo "$(date) END:LOCAL_MAVEN_REPO ------------------------------------------"

echo "$(date) START:TESTING ------------------------------------------"
pushd "${BASH_SOURCE%/*}/android"
./gradlew \
assembleAndroidTest \
connectedAndroidTest \
-Plocal-engine-out="$ENGINE_PATH/src/out/$LOCAL_ENGINE" \
-Plocal-engine-repo="$SCENARIO_APP/.repo" \
-Plocal-engine-build-mode="$BUILD_MODE" \
-Ptarget-platform="$TARGET_PLATFORM"
popd
echo "$(date) END:TESTING ------------------------------------------"