Skip to content

Commit d70bf88

Browse files
Treehugger RobotAndroid (Google) Code Review
Treehugger Robot
authored and
Android (Google) Code Review
committed
Merge "[fused lib] Publish sample in 8.9 & fix formatting" into studio-main
2 parents 6a48436 + 904dcd0 commit d70bf88

File tree

12 files changed

+52
-73
lines changed

12 files changed

+52
-73
lines changed

BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ kotlin_library(
4343
"//tools/base/bazel:gradle",
4444
"//tools/base/common:tools.common",
4545
"//tools/base/testutils:tools.testutils",
46+
"@maven//:com.google.code.gson.gson",
4647
"@maven//:junit.junit",
4748
],
4849
)

recipes/applyFusedLibraryPlugin/README.md

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,9 @@ by other libraries.
3434
│ :androidLib3 com.google.code.gson:gson* │
3535
└─────────────────────────────────────────┘
3636
</pre>
37-
This diagram shows an overview of the relevant project dependency structure.
38-
* include dependency of :fusedLibrary
37+
This diagram shows an overview of the relevant project dependency structure.
38+
39+
`*` indicates an `include` dependency of the `:fusedLibrary` module
3940

4041
Example usages of classes, resources and other artifacts are demonstrated in the :app module unit
4142
and instrumentation tests.
@@ -48,29 +49,29 @@ and instrumentation tests.
4849

4950
1. Apply the plugin
5051
gradle/libs.versions.toml append
51-
```kts
52+
```toml
5253
[plugins]
53-
...
5454
android-fusedlibrary = { id = "com.android.fusedlibrary", version.ref = "agp" }
5555
```
5656
2. Create a new module. `File` > `New Module...` . Then, click `Android Library` and fill out the
5757
required module metadata. Click `Finish`.
5858
3. In the new module (let's call it `:fusedLibrary`) open the `build.gradle.kts` file,
5959
then replace the `plugins` block with
60-
```
60+
```kts
6161
plugins {
6262
alias(libs.plugins.android.fusedlibrary)
6363
}
6464
```
6565
to apply the Fused Library Plugin
6666
4. Fused library modules cannot not contain sources such as code or resources, nor does it use
6767
the typical `implementation` or `api` configurations you may expect to declare as dependencies.
68+
6869
Done.
6970

7071
Fused library introduces a new configuration `include`, that declares what dependencies will be
7172
fused in the built/published .aar file.
7273

73-
For example, the :fusedLibrary could define the following in the `dependencies` block:
74+
For example, the `:fusedLibrary` could define the following in the `dependencies` block:
7475

7576
```kts
7677
dependencies {
@@ -91,25 +92,27 @@ dependencies {
9192
2. Once you are satisfied, you can proceed to build the library using
9293
`./gradlew :fusedLibrary:assemble`. Assuming dependencies are valid,
9394
this task produces the .aar fused library at `fusedLibrary/build/bundle/bundle.aar`.
94-
3. Resync project ctrl+shift+O
95+
3. Resync project `ctrl+shift+O`
96+
9597
Done.
9698

97-
At this point you can add the fused library as a dependency from other modules.
99+
At this point, you can add the fused library as a dependency from other modules.
98100

99101
### Running the consumption tests
100102

101103
In the :app module there are tests that make use of the classes and resource distributed via
102-
:fusedLibrary.
104+
`:fusedLibrary`.
103105

104106
Run unit tests: `./gradlew :app:testDebugUnitTest --tests "com.example.fusedlibrarysample.FusedLibraryConsumptionUnitTest"`
107+
105108
Run instrumentation tests: `./gradlew :app:connectedDebugAndroidTest`
106109

107110
### Publishing the fused library
108111

109112
Fused Library Plugin artifacts can be easily configured for publication with Maven publishing
110113
plugins. The plugin generates it's own POM for distribution that preserves the artifact dependencies.
111-
We'll provide some typical configurations for publishing that may be useful for most use cases,
112-
however if your needs are more complex, consult the Maven documentation.
114+
We'll provide some typical configurations for publishing that may be useful for most use cases
115+
however, if your needs are more complex, consult the Maven documentation.
113116

114117
Generating the fused lib POM
115118
1. Follow the steps of `Building a fused library`
@@ -143,12 +146,13 @@ Generating a maven repository with the fused library
143146
}
144147
145148
```
146-
2. Execute the task for creating the repository `./gradlew fusedLibrary:publishReleasePublicationToMyrepoRepository`
149+
2. Execute the task for creating the repository `./gradlew :fusedLibrary:publishReleasePublicationToMyrepoRepository`
147150
3. As androidLib3 is a project dependency of the fused library, that also needs to be published to
148-
the repository`./gradlew androidLib3:publishMavenPublicationToMyrepoRepository`
149-
4. Note: :app has already configured dependency substitution that prefers the published local repo
150-
artifacts over the :fusedLibrary project itself, so :app now automatically depends on the correct
151+
the repository`./gradlew :androidLib3:publishMavenPublicationToMyrepoRepository`
152+
4. Note: `:app` has already configured dependency substitution that prefers the published local repo
153+
artifacts over the `:fusedLibrary` project itself, so `:app` now automatically depends on the correct
151154
artifacts.
155+
152156
Done.
153157

154158
### Configurations
@@ -162,16 +166,16 @@ Done.
162166
This plugin remains in early stages, and there may be corner cases that have not been fully tested
163167
or developed.
164168

165-
See open public issues at this link [open issues](https://issuetracker.google.com/issues?q=hotlistid:4053459)
169+
See open public issues at this link [open issues](https://issuetracker.google.com/components/1692458)
166170

167-
Follow the below steps and use this [link to **file new bugs**](https://issuetracker.google.com/createIssue?title=%5Bfused+lib+-+public%5D+%3CIssue+Name+Here%3E&cc=lukeedgar%40google.com%2C+android-gradle%40google.com&description=Please+include+all+of+the+following%3A%0A1.+Steps+to+reproduce%0A2.+A+paste+of+the+exception%0A3.+run+%60.%2Fgradlew+%3A%3Cfused+library+module%5C%3E%3Areport%60+and+paste+the+contents+of+%0A%60%3Cmy+library+module%5C%3Ebuild%2Freports%2Ffused_library_report%2Fsingle%2Freport.json%60%0A4.Also+consider+running+%60gradle+%3A%3Cfused+library+module%3E%3Adependencies%60+if+dependency+information+is+relevant%0A5.%5Boptional%5D+if+the+build+was+successful%2C+provide+a+copy+of+the+.aar&format=MARKDOWN&component=192709&type=BUG&priority=P2&severity=S2&hotlistIds=4053459&assignee=lukeedgar%40google.com)
171+
Follow the below steps and use this [link to **file new bugs**](https://issuetracker.google.com/issues/new?title=%5Bfused+lib+-+public%5D+%3CIssue+Name+Here%3E&cc=lukeedgar%40google.com%2C+android-gradle%40google.com&description=1.+Steps+to+reproduce%0A2.+A+paste+of+the+exception%0A3.+run+%60.%2Fgradlew+%3A%3Cfused+library+module%3E%3Areport%60+and+paste+the+contents+of+%0A%60%3Cmy+library+module%3Ebuild%2Freports%2Ffused_library_report%2Fsingle%2Freport.json%60%0A4.+Also+consider+running+%60.%2Fgradlew+%3A%3Cfused+library+module%3E%3Adependencies%60+if+dependency+information+is+relevant%0A5.+%5C%5Boptional%5C%5D+if+the+build+was+successful%2C+provide+a+copy+of+the+.aar&format=MARKDOWN&component=192708&type=BUG&priority=P2&severity=S2&hotlistIds=4053459&assignee=lukeedgar%40google.com)
168172
**or provide suggestions** for the Fused Library Plugin.
169173

170174
When filing an issue, please include the following information:
171175
1. Steps to reproduce
172176
2. A paste of the exception
173-
3. run `\gradle :\<fused library module\>:report\` and paste the contents of
174-
`\<my library module\>build/reports/fused_library_report/single/report.json`
175-
4.Also consider running \`gradle :\<fused library module\>:dependencies\` if dependency information is relevant
176-
5.\[optional\] if the build was successful, provide a copy of the .aar
177+
3. run `./gradlew :<fused library module>:report` and paste the contents of
178+
`<my library module>build/reports/fused_library_report/single/report.json`
179+
4. Also consider running `./gradlew :<fused library module>:dependencies` if dependency information is relevant
180+
5. \[optional\] if the build was successful, provide a copy of the .aar
177181
Done.

recipes/applyFusedLibraryPlugin/androidLib1/build.gradle.kts

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ plugins {
2121

2222
android {
2323
namespace = "com.example.androidlib1"
24-
compileSdk = 34
24+
compileSdk = $COMPILE_SDK
2525

2626
defaultConfig {
27-
minSdk = 34
27+
minSdk = $MINIMUM_SDK
2828

2929
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
3030
consumerProguardFiles("consumer-rules.pro")
@@ -54,11 +54,5 @@ android {
5454
}
5555

5656
dependencies {
57-
implementation("com.google.code.gson:gson:2.11.0")
58-
implementation(libs.androidx.core.ktx)
59-
implementation(libs.androidx.appcompat)
60-
implementation(libs.material)
61-
testImplementation(libs.junit)
62-
androidTestImplementation(libs.androidx.junit)
63-
androidTestImplementation(libs.androidx.espresso.core)
57+
implementation("com.google.code.gson:gson:2.10.1")
6458
}

recipes/applyFusedLibraryPlugin/androidLib2/build.gradle.kts

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ plugins {
2222

2323
android {
2424
namespace = "com.example.androidlib2"
25-
compileSdk = 34
25+
compileSdk = $COMPILE_SDK
2626

2727
defaultConfig {
28-
minSdk = 34
28+
minSdk = $MINIMUM_SDK
2929

3030
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
3131
}
@@ -41,11 +41,4 @@ android {
4141

4242
dependencies {
4343
implementation(project(":androidLib3"))
44-
implementation("com.google.errorprone:error_prone_annotations:2.27.0")
45-
implementation(libs.androidx.core.ktx)
46-
implementation(libs.androidx.appcompat)
47-
implementation(libs.material)
48-
testImplementation(libs.junit)
49-
androidTestImplementation(libs.androidx.junit)
50-
androidTestImplementation(libs.androidx.espresso.core)
5144
}

recipes/applyFusedLibraryPlugin/androidLib2/src/main/java/com/example/androidlib2/ClassFromAndroidLib2.kt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,6 @@
1616

1717
package com.example.androidlib2
1818

19-
import android.content.Context
20-
import android.provider.Settings.Global.getString
21-
2219
class ClassFromAndroidLib2 {
2320

2421
fun foo(): String {

recipes/applyFusedLibraryPlugin/androidLib3/build.gradle.kts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ plugins {
2222

2323
android {
2424
namespace = "com.example.androidlib3"
25-
compileSdk = 34
25+
compileSdk = $COMPILE_SDK
2626

2727
defaultConfig {
28-
minSdk = 24
28+
minSdk = $MINIMUM_SDK
2929

3030
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
3131
consumerProguardFiles("consumer-rules.pro")
@@ -66,10 +66,4 @@ publishing {
6666
}
6767

6868
dependencies {
69-
implementation(libs.androidx.core.ktx)
70-
implementation(libs.androidx.appcompat)
71-
implementation(libs.material)
72-
testImplementation(libs.junit)
73-
androidTestImplementation(libs.androidx.junit)
74-
androidTestImplementation(libs.androidx.espresso.core)
7569
}

recipes/applyFusedLibraryPlugin/app/build.gradle.kts

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@ plugins {
2121

2222
android {
2323
namespace = "com.example.fusedlibrarysample"
24-
compileSdk = 35
24+
compileSdk = $COMPILE_SDK
2525

2626
defaultConfig {
2727
applicationId = "com.example.fusedlibrarysample"
28-
minSdk = 34
29-
targetSdk = 34
28+
minSdk = $MINIMUM_SDK
29+
targetSdk = $COMPILE_SDK
3030
versionCode = 1
3131
versionName = "1.0"
3232

@@ -53,11 +53,6 @@ android {
5353

5454
dependencies {
5555
implementation(project(":fusedLibrary"))
56-
implementation(libs.androidx.core.ktx)
57-
implementation(libs.androidx.appcompat)
58-
implementation(libs.material)
59-
implementation(libs.androidx.activity)
60-
implementation(libs.androidx.constraintlayout)
6156
testImplementation(libs.junit)
6257
androidTestImplementation(libs.androidx.junit)
6358
androidTestImplementation(libs.androidx.espresso.core)

recipes/applyFusedLibraryPlugin/app/src/androidTest/java/com/example/fusedlibrarysample/FusedLibraryInstrumentationTest.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ import org.junit.Assert.*
3030
*/
3131
@RunWith(AndroidJUnit4::class)
3232
class FusedLibraryInstrumentationTest {
33-
33+
3434
@Test
35-
fun `access resources from fused library`() {
35+
fun accessResourcesFromFusedLibrary() {
3636
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
3737
val stringOverridden =
3838
appContext.getString(com.example.fusedlibrary.R.string.string_overridden)
@@ -43,7 +43,7 @@ class FusedLibraryInstrumentationTest {
4343
}
4444

4545
@Test
46-
fun `access external libraries from include dependencies`() {
46+
fun accessExternalLibrariesFromIncludeDependencies() {
4747
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
4848
val androidLib1AssetInputStream = appContext.assets.open("androidLib1-asset.json")
4949
val jsonString = androidLib1AssetInputStream.bufferedReader().use {it.readText() }

recipes/applyFusedLibraryPlugin/app/src/test/java/com/example/fusedlibrarysample/FusedLibraryConsumptionUnitTest.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import org.junit.Assert.*
2929
class FusedLibraryConsumptionUnitTest {
3030

3131
@Test
32-
fun `test classes from included dependencies`() {
32+
fun testClassesFromIncludedDependencies() {
3333
// Access symbols from local library dependencies
3434
val androidLib1Class = ClassFromAndroidLib1()
3535
val androidLib2Class = ClassFromAndroidLib2()
@@ -45,7 +45,7 @@ class FusedLibraryConsumptionUnitTest {
4545
}
4646

4747
@Test
48-
fun `test local lib jar dependencies are accessible`() {
48+
fun testLocalLibJarDependenciesAreAccessible() {
4949
// Access class in local jar from fused library file dependencies
5050
// A_DoIExist is class from a libs jar file dependency
5151
// (fusedLibrary/libs/simple-jar-with-A_DoIExist-class.jar)

recipes/applyFusedLibraryPlugin/fusedLibrary/build.gradle.kts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@ plugins {
2121

2222
androidFusedLibrary {
2323
namespace = "com.example.fusedlibrary"
24-
minSdk = 34
24+
minSdk = $MINIMUM_SDK
2525

2626
// If aarMetadata is not explicitly specified,
2727
// aar metadata will be generated based on dependencies.
2828
aarMetadata {
29-
minCompileSdk = 19
29+
minCompileSdk = $MINIMUM_SDK
3030
minCompileSdkExtension = 1
3131
}
3232
}
@@ -51,6 +51,6 @@ publishing {
5151
dependencies {
5252
include(project(":androidLib1"))
5353
include(project(":androidLib2"))
54-
include("com.google.code.gson:gson:2.11.0")
54+
include("com.google.code.gson:gson:2.10.1")
5555
include(files("libs/simple-jar-with-A_DoIExist-class.jar"))
5656
}

recipes/applyFusedLibraryPlugin/gradle/libs.versions.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
[versions]
2-
agp = "8.9.0-alpha03"
3-
kotlin = "1.9.0"
2+
agp = $AGP_VERSION
3+
kotlin = $KOTLIN_VERSION
44
coreKtx = "1.15.0"
55
junit = "4.13.2"
6-
junitVersion = "1.2.1"
7-
espressoCore = "3.6.1"
6+
junitVersion = "1.1.5"
7+
espressoCore = "3.5.1"
88
appcompat = "1.7.0"
99
material = "1.12.0"
1010
activity = "1.8.0"

recipes/applyFusedLibraryPlugin/recipe_metadata.toml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ description ="""
88
"""
99

1010
[agpVersion]
11-
min = "8.9.0"
11+
min = "8.9.0-alpha08"
1212

1313
# Relevant Gradle tasks to run per recipe
1414
[gradleTasks]
@@ -19,10 +19,11 @@ tasks = [
1919
":fusedLibrary:publishReleasePublicationToMyrepoRepository",
2020
":fusedLibrary:publishReleasePublicationToMyrepoRepository",
2121
":app:testDebugUnitTest",
22-
":app:connectedDebugAndroidTest"
2322
]
2423

2524
# All the relevant metadata fields to create an index based on language/API/etc'
2625
[indexMetadata]
27-
index = []
26+
index = [
27+
"Plugin Features/Fused Library Plugin"
28+
]
2829

0 commit comments

Comments
 (0)