Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit cbc8713

Browse files
author
Emmanuel Garcia
authored
Define embedding dependencies in Gradle (#17116)
1 parent e623335 commit cbc8713

File tree

5 files changed

+164
-70
lines changed

5 files changed

+164
-70
lines changed
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# Updating the Embedding Dependencies
2+
3+
## Requirements
4+
5+
1. Gradle. If you don't have Gradle installed, you can get it on [https://gradle.org/install/#manually](https://gradle.org/install/#manually).
6+
2. [Depot tools](http://commondatastorage.googleapis.com/chrome-infra-docs/flat/depot_tools/docs/html/depot_tools_tutorial.html#_setting_up).
7+
8+
## Steps
9+
10+
To update the embedding dependencies, just `cd` into this directory,
11+
modify the dependencies in `build.gradle` and run `gradle updateDependencies`.
12+
13+
Once you have updated the dependencies, you can upload a new version by running
14+
`cipd create --pkg-def cipd.yaml`. For more, see the Chromium instructions on ["Updating a CIPD
15+
dependency"](https://chromium.googlesource.com/chromium/src/+/master/docs/cipd.md#Updating-a-CIPD-dependency) for how to upload a package update to CIPD.
16+
17+
Once you've uploaded the new version, also make sure to tag it with the updated
18+
timestamp and robolectric version (most likely still 3.8, unless you've migrated
19+
all the packages to 4+).
20+
21+
$ cipd set-tag flutter/android/embedding_bundle --version=<new_version_hash> -tag=last_updated:<timestamp>
22+
23+
Example of a last-updated timestamp: 2019-07-29T15:27:42-0700
24+
25+
You can generate the same date format with `date +%Y-%m-%dT%T%z`.
26+
27+
You can run `cipd describe flutter/android/embedding_bundle
28+
--version=<new_version_hash>` to verify. You should see:
29+
30+
```
31+
Package: flutter/android/embedding_bundle
32+
Instance ID: <new_version_hash>
33+
...
34+
Tags:
35+
last_updated:<timestamp>
36+
```
37+
38+
Then update the `DEPS` file (located at /src/flutter/DEPS) to use the new version by pointing to
39+
your new `last_updated_at` tag.
40+
41+
```
42+
'src/third_party/android_embedding_dependencies': {
43+
'packages': [
44+
{
45+
'package': 'flutter/android/embedding_bundle',
46+
'version': 'last_updated:<timestamp>'
47+
}
48+
],
49+
'condition': 'download_android_deps',
50+
'dep_type': 'cipd',
51+
},
52+
```
53+
54+
You can now re-run `gclient sync` to fetch the latest package version.
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
// Copyright 2013 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
// To use, run:
6+
// $ gradle updateDependencies
7+
//
8+
// This script downloads the embedding dependencies into a lib/ directory,
9+
// extract jar files from AARs, so they can be used in gn.
10+
def destinationDir = "lib"
11+
12+
buildscript {
13+
repositories {
14+
google()
15+
jcenter()
16+
}
17+
dependencies {
18+
classpath "com.android.tools.build:gradle:3.5.0"
19+
}
20+
}
21+
22+
allprojects {
23+
repositories {
24+
google()
25+
jcenter()
26+
}
27+
}
28+
29+
apply plugin: "com.android.application"
30+
31+
configurations {
32+
// Use this configuration for dependencies required by the embedding.
33+
embedding
34+
// Use any of these configurations for dependencies required for testing the embedding.
35+
embeddingTesting
36+
embeddingTesting_duplicated
37+
}
38+
39+
android {
40+
compileSdkVersion 28
41+
42+
dependencies {
43+
embedding "androidx.annotation:annotation:1.1.0"
44+
embedding "androidx.fragment:fragment:1.1.0"
45+
46+
def lifecycle_version = "2.2.0"
47+
embedding "androidx.lifecycle:lifecycle-viewmodel:$lifecycle_version"
48+
embedding "androidx.lifecycle:lifecycle-livedata:$lifecycle_version"
49+
embedding "androidx.lifecycle:lifecycle-runtime:$lifecycle_version"
50+
embedding "androidx.lifecycle:lifecycle-viewmodel-savedstate:$lifecycle_version"
51+
embedding "androidx.lifecycle:lifecycle-compiler:$lifecycle_version"
52+
embedding "androidx.lifecycle:lifecycle-common-java8:$lifecycle_version"
53+
embedding "androidx.lifecycle:lifecycle-service:$lifecycle_version"
54+
embedding "androidx.lifecycle:lifecycle-process:$lifecycle_version"
55+
embedding "androidx.lifecycle:lifecycle-reactivestreams:$lifecycle_version"
56+
57+
// Testing
58+
embeddingTesting "androidx.arch.core:core-testing:2.1.0"
59+
embeddingTesting "org.robolectric:android-all:8.1.0-robolectric-4611349"
60+
// This is required by the robolectric test.
61+
embeddingTesting_duplicated "org.robolectric:android-all:4.1.2_r1-robolectric-r1"
62+
embeddingTesting "org.robolectric:robolectric:3.8"
63+
embeddingTesting "org.robolectric:junit:3.8"
64+
embeddingTesting "org.robolectric:shadows-framework:3.8"
65+
embeddingTesting "org.robolectric:resources:3.8"
66+
embeddingTesting "org.mockito:mockito-all:1.10.19"
67+
embeddingTesting "junit:junit:4.13-beta-3"
68+
}
69+
}
70+
71+
task updateDependencies() {
72+
delete destinationDir
73+
// Copy the dependencies from the compileOnly configuration into
74+
// the destination directory.
75+
copy {
76+
from configurations.embedding
77+
from configurations.embeddingTesting
78+
from configurations.embeddingTesting_duplicated
79+
into destinationDir
80+
}
81+
doLast {
82+
// Extract classes.jar from aar and rename it as the dependency name .jar
83+
// since javac doesn't support AARs.
84+
fileTree(destinationDir)
85+
.filter { it.name.endsWith(".aar") }
86+
.collect { aarDependency ->
87+
def dependencyName = "${aarDependency.name.take(aarDependency.name.lastIndexOf('.'))}";
88+
copy {
89+
into destinationDir
90+
from(zipTree(aarDependency)) {
91+
include "classes.jar"
92+
}
93+
rename "classes.jar", "${dependencyName}.jar"
94+
}
95+
delete aarDependency
96+
}
97+
}
98+
doLast {
99+
fileTree(destinationDir)
100+
.collect { dependency ->
101+
println "\"//third_party/robolectric/lib/${dependency.name}\","
102+
}
103+
}
104+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
package: flutter/android/embedding_bundle
2+
description: Dependencies used by the Android embedding.
3+
data:
4+
- dir: lib

shell/platform/android/test/README.md

Lines changed: 2 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -32,72 +32,8 @@ the tests, but it would add an extra point of failure.
3232

3333
### My new test won't run. There's a "ClassNotFoundException".
3434

35-
Your test is probably using a dependency that we haven't needed yet. You
36-
probably need to find the dependency you need, add it to the
37-
`flutter/android/robolectric_bundle` CIPD package, and then re-run `gclient
38-
sync`. See ["Updating a CIPD dependency"](#Updating-a-CIPD-dependency) below.
35+
See [shell/platform/android/embedding_bundle](Updating Embedding Dependencies).
3936

4037
### My new test won't compile. It can't find one of my imports.
4138

42-
You could be using a brand new dependency. If so, you'll need to add it to the
43-
CIPD package for the robolectric tests. See ["Updating a CIPD
44-
dependency"](#Updating-a-CIPD-dependency) below.
45-
46-
Then you'll also need to add the jar to the `robolectric_tests` build target.
47-
Add `//third_party/robolectric/lib/<dependency.jar>` to
48-
`robolectric_tests._jar_dependencies` in `/shell/platform/android/BUILD.gn`.
49-
50-
There's also a chance that you're using a dependency that we're relying on at
51-
runtime, but not compile time. If so you'll just need to update
52-
`_jar_dependencies` in `BUILD.gn`.
53-
54-
### Updating a CIPD dependency
55-
56-
See the Chromium instructions on ["Updating a CIPD
57-
dependency"](https://chromium.googlesource.com/chromium/src/+/master/docs/cipd.md#Updating-a-CIPD-dependency)
58-
for how to upload a package update to CIPD. Download and extract the latest
59-
package from CIPD and then copy
60-
[shell/platform/android/test/cipd.yaml](cipd.yaml) into the extracted directory
61-
to use as the base for the pre-existing package. Add new dependencies to `lib/`.
62-
63-
Once you've uploaded the new version, also make sure to tag it with the updated
64-
timestamp and robolectric version (most likely still 3.8, unless you've migrated
65-
all the packages to 4+).
66-
67-
$ cipd set-tag flutter/android/robolectric_bundle --version=<new_version_hash> -tag=last_updated:<timestamp>
68-
69-
Example of a last-updated timestamp: 2019-07-29T15:27:42-0700
70-
71-
You can generate the same date format with `date +%Y-%m-%dT%T%z`.
72-
73-
$ cipd set-tag flutter/android/robolectric_bundle --version=<new_version_hash> -tag=robolectric_version:<robolectric_version>
74-
75-
You can run `cipd describe flutter/android/robolectric_bundle
76-
--version=<new_version_hash>` to verify. You should see:
77-
78-
```
79-
Package: flutter/android/robolectric_bundle
80-
Instance ID: <new_version_hash>
81-
...
82-
Tags:
83-
last_updated:<timestamp>
84-
robolectric_version:<robolectric_version>
85-
```
86-
87-
Then update the `DEPS` file (located at /src/flutter/DEPS) to use the new version by pointing to
88-
your new `last_updated_at` tag.
89-
90-
```
91-
'src/third_party/robolectric': {
92-
'packages': [
93-
{
94-
'package': 'flutter/android/robolectric_bundle',
95-
'version': 'last_updated:<timestamp>'
96-
}
97-
],
98-
'condition': 'download_android_deps',
99-
'dep_type': 'cipd',
100-
},
101-
```
102-
103-
You can now re-run `gclient sync` to fetch the latest package version.
39+
See [shell/platform/android/embedding_bundle](Updating Embedding Dependencies).

shell/platform/android/test/cipd.yaml

Lines changed: 0 additions & 4 deletions
This file was deleted.

0 commit comments

Comments
 (0)