diff --git a/BUILD b/BUILD index 9b5d0ba6..fb56ecad 100644 --- a/BUILD +++ b/BUILD @@ -43,6 +43,7 @@ kotlin_library( "//tools/base/bazel:gradle", "//tools/base/common:tools.common", "//tools/base/testutils:tools.testutils", + "@maven//:com.google.code.gson.gson", "@maven//:junit.junit", ], ) diff --git a/recipes/applyFusedLibraryPlugin/README.md b/recipes/applyFusedLibraryPlugin/README.md index 53c88dae..e01fe26d 100644 --- a/recipes/applyFusedLibraryPlugin/README.md +++ b/recipes/applyFusedLibraryPlugin/README.md @@ -34,8 +34,9 @@ by other libraries. │ :androidLib3 com.google.code.gson:gson* │ └─────────────────────────────────────────┘ -This diagram shows an overview of the relevant project dependency structure. -* include dependency of :fusedLibrary +This diagram shows an overview of the relevant project dependency structure. + +`*` indicates an `include` dependency of the `:fusedLibrary` module Example usages of classes, resources and other artifacts are demonstrated in the :app module unit and instrumentation tests. @@ -48,16 +49,15 @@ and instrumentation tests. 1. Apply the plugin gradle/libs.versions.toml append -```kts +```toml [plugins] -... android-fusedlibrary = { id = "com.android.fusedlibrary", version.ref = "agp" } ``` 2. Create a new module. `File` > `New Module...` . Then, click `Android Library` and fill out the required module metadata. Click `Finish`. 3. In the new module (let's call it `:fusedLibrary`) open the `build.gradle.kts` file, then replace the `plugins` block with -``` +```kts plugins { alias(libs.plugins.android.fusedlibrary) } @@ -65,12 +65,13 @@ plugins { to apply the Fused Library Plugin 4. Fused library modules cannot not contain sources such as code or resources, nor does it use the typical `implementation` or `api` configurations you may expect to declare as dependencies. + Done. Fused library introduces a new configuration `include`, that declares what dependencies will be fused in the built/published .aar file. -For example, the :fusedLibrary could define the following in the `dependencies` block: +For example, the `:fusedLibrary` could define the following in the `dependencies` block: ```kts dependencies { @@ -91,25 +92,27 @@ dependencies { 2. Once you are satisfied, you can proceed to build the library using `./gradlew :fusedLibrary:assemble`. Assuming dependencies are valid, this task produces the .aar fused library at `fusedLibrary/build/bundle/bundle.aar`. -3. Resync project ctrl+shift+O +3. Resync project `ctrl+shift+O` + Done. -At this point you can add the fused library as a dependency from other modules. +At this point, you can add the fused library as a dependency from other modules. ### Running the consumption tests In the :app module there are tests that make use of the classes and resource distributed via -:fusedLibrary. +`:fusedLibrary`. Run unit tests: `./gradlew :app:testDebugUnitTest --tests "com.example.fusedlibrarysample.FusedLibraryConsumptionUnitTest"` + Run instrumentation tests: `./gradlew :app:connectedDebugAndroidTest` ### Publishing the fused library Fused Library Plugin artifacts can be easily configured for publication with Maven publishing plugins. The plugin generates it's own POM for distribution that preserves the artifact dependencies. -We'll provide some typical configurations for publishing that may be useful for most use cases, -however if your needs are more complex, consult the Maven documentation. +We'll provide some typical configurations for publishing that may be useful for most use cases +however, if your needs are more complex, consult the Maven documentation. Generating the fused lib POM 1. Follow the steps of `Building a fused library` @@ -143,12 +146,13 @@ Generating a maven repository with the fused library } ``` -2. Execute the task for creating the repository `./gradlew fusedLibrary:publishReleasePublicationToMyrepoRepository` +2. Execute the task for creating the repository `./gradlew :fusedLibrary:publishReleasePublicationToMyrepoRepository` 3. As androidLib3 is a project dependency of the fused library, that also needs to be published to -the repository`./gradlew androidLib3:publishMavenPublicationToMyrepoRepository` -4. Note: :app has already configured dependency substitution that prefers the published local repo -artifacts over the :fusedLibrary project itself, so :app now automatically depends on the correct +the repository`./gradlew :androidLib3:publishMavenPublicationToMyrepoRepository` +4. Note: `:app` has already configured dependency substitution that prefers the published local repo +artifacts over the `:fusedLibrary` project itself, so `:app` now automatically depends on the correct artifacts. + Done. ### Configurations @@ -162,16 +166,16 @@ Done. This plugin remains in early stages, and there may be corner cases that have not been fully tested or developed. -See open public issues at this link [open issues](https://issuetracker.google.com/issues?q=hotlistid:4053459) +See open public issues at this link [open issues](https://issuetracker.google.com/components/1692458) -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) +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) **or provide suggestions** for the Fused Library Plugin. When filing an issue, please include the following information: 1. Steps to reproduce 2. A paste of the exception -3. run `\gradle :\:report\` and paste the contents of -`\build/reports/fused_library_report/single/report.json` -4.Also consider running \`gradle :\:dependencies\` if dependency information is relevant -5.\[optional\] if the build was successful, provide a copy of the .aar +3. run `./gradlew ::report` and paste the contents of +`build/reports/fused_library_report/single/report.json` +4. Also consider running `./gradlew ::dependencies` if dependency information is relevant +5. \[optional\] if the build was successful, provide a copy of the .aar Done. diff --git a/recipes/applyFusedLibraryPlugin/androidLib1/build.gradle.kts b/recipes/applyFusedLibraryPlugin/androidLib1/build.gradle.kts index 411a4757..8e92d8e4 100644 --- a/recipes/applyFusedLibraryPlugin/androidLib1/build.gradle.kts +++ b/recipes/applyFusedLibraryPlugin/androidLib1/build.gradle.kts @@ -21,10 +21,10 @@ plugins { android { namespace = "com.example.androidlib1" - compileSdk = 34 + compileSdk = $COMPILE_SDK defaultConfig { - minSdk = 34 + minSdk = $MINIMUM_SDK testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" consumerProguardFiles("consumer-rules.pro") @@ -54,11 +54,5 @@ android { } dependencies { - implementation("com.google.code.gson:gson:2.11.0") - implementation(libs.androidx.core.ktx) - implementation(libs.androidx.appcompat) - implementation(libs.material) - testImplementation(libs.junit) - androidTestImplementation(libs.androidx.junit) - androidTestImplementation(libs.androidx.espresso.core) + implementation("com.google.code.gson:gson:2.10.1") } diff --git a/recipes/applyFusedLibraryPlugin/androidLib2/build.gradle.kts b/recipes/applyFusedLibraryPlugin/androidLib2/build.gradle.kts index 70bded8d..ab770dfb 100644 --- a/recipes/applyFusedLibraryPlugin/androidLib2/build.gradle.kts +++ b/recipes/applyFusedLibraryPlugin/androidLib2/build.gradle.kts @@ -22,10 +22,10 @@ plugins { android { namespace = "com.example.androidlib2" - compileSdk = 34 + compileSdk = $COMPILE_SDK defaultConfig { - minSdk = 34 + minSdk = $MINIMUM_SDK testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" } @@ -41,11 +41,4 @@ android { dependencies { implementation(project(":androidLib3")) - implementation("com.google.errorprone:error_prone_annotations:2.27.0") - implementation(libs.androidx.core.ktx) - implementation(libs.androidx.appcompat) - implementation(libs.material) - testImplementation(libs.junit) - androidTestImplementation(libs.androidx.junit) - androidTestImplementation(libs.androidx.espresso.core) } diff --git a/recipes/applyFusedLibraryPlugin/androidLib2/src/main/java/com/example/androidlib2/ClassFromAndroidLib2.kt b/recipes/applyFusedLibraryPlugin/androidLib2/src/main/java/com/example/androidlib2/ClassFromAndroidLib2.kt index 3d35cf9d..a3b3fbf3 100644 --- a/recipes/applyFusedLibraryPlugin/androidLib2/src/main/java/com/example/androidlib2/ClassFromAndroidLib2.kt +++ b/recipes/applyFusedLibraryPlugin/androidLib2/src/main/java/com/example/androidlib2/ClassFromAndroidLib2.kt @@ -16,9 +16,6 @@ package com.example.androidlib2 -import android.content.Context -import android.provider.Settings.Global.getString - class ClassFromAndroidLib2 { fun foo(): String { diff --git a/recipes/applyFusedLibraryPlugin/androidLib3/build.gradle.kts b/recipes/applyFusedLibraryPlugin/androidLib3/build.gradle.kts index 50f053d4..127e21f3 100644 --- a/recipes/applyFusedLibraryPlugin/androidLib3/build.gradle.kts +++ b/recipes/applyFusedLibraryPlugin/androidLib3/build.gradle.kts @@ -22,10 +22,10 @@ plugins { android { namespace = "com.example.androidlib3" - compileSdk = 34 + compileSdk = $COMPILE_SDK defaultConfig { - minSdk = 24 + minSdk = $MINIMUM_SDK testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" consumerProguardFiles("consumer-rules.pro") @@ -66,10 +66,4 @@ publishing { } dependencies { - implementation(libs.androidx.core.ktx) - implementation(libs.androidx.appcompat) - implementation(libs.material) - testImplementation(libs.junit) - androidTestImplementation(libs.androidx.junit) - androidTestImplementation(libs.androidx.espresso.core) } diff --git a/recipes/applyFusedLibraryPlugin/app/build.gradle.kts b/recipes/applyFusedLibraryPlugin/app/build.gradle.kts index a135b06e..d272d18e 100644 --- a/recipes/applyFusedLibraryPlugin/app/build.gradle.kts +++ b/recipes/applyFusedLibraryPlugin/app/build.gradle.kts @@ -21,12 +21,12 @@ plugins { android { namespace = "com.example.fusedlibrarysample" - compileSdk = 35 + compileSdk = $COMPILE_SDK defaultConfig { applicationId = "com.example.fusedlibrarysample" - minSdk = 34 - targetSdk = 34 + minSdk = $MINIMUM_SDK + targetSdk = $COMPILE_SDK versionCode = 1 versionName = "1.0" @@ -53,11 +53,6 @@ android { dependencies { implementation(project(":fusedLibrary")) - implementation(libs.androidx.core.ktx) - implementation(libs.androidx.appcompat) - implementation(libs.material) - implementation(libs.androidx.activity) - implementation(libs.androidx.constraintlayout) testImplementation(libs.junit) androidTestImplementation(libs.androidx.junit) androidTestImplementation(libs.androidx.espresso.core) diff --git a/recipes/applyFusedLibraryPlugin/app/src/androidTest/java/com/example/fusedlibrarysample/FusedLibraryInstrumentationTest.kt b/recipes/applyFusedLibraryPlugin/app/src/androidTest/java/com/example/fusedlibrarysample/FusedLibraryInstrumentationTest.kt index 73e223f8..26adb917 100644 --- a/recipes/applyFusedLibraryPlugin/app/src/androidTest/java/com/example/fusedlibrarysample/FusedLibraryInstrumentationTest.kt +++ b/recipes/applyFusedLibraryPlugin/app/src/androidTest/java/com/example/fusedlibrarysample/FusedLibraryInstrumentationTest.kt @@ -30,9 +30,9 @@ import org.junit.Assert.* */ @RunWith(AndroidJUnit4::class) class FusedLibraryInstrumentationTest { - + @Test - fun `access resources from fused library`() { + fun accessResourcesFromFusedLibrary() { val appContext = InstrumentationRegistry.getInstrumentation().targetContext val stringOverridden = appContext.getString(com.example.fusedlibrary.R.string.string_overridden) @@ -43,7 +43,7 @@ class FusedLibraryInstrumentationTest { } @Test - fun `access external libraries from include dependencies`() { + fun accessExternalLibrariesFromIncludeDependencies() { val appContext = InstrumentationRegistry.getInstrumentation().targetContext val androidLib1AssetInputStream = appContext.assets.open("androidLib1-asset.json") val jsonString = androidLib1AssetInputStream.bufferedReader().use {it.readText() } diff --git a/recipes/applyFusedLibraryPlugin/app/src/test/java/com/example/fusedlibrarysample/FusedLibraryConsumptionUnitTest.kt b/recipes/applyFusedLibraryPlugin/app/src/test/java/com/example/fusedlibrarysample/FusedLibraryConsumptionUnitTest.kt index 1bc863d9..4d1f7de9 100644 --- a/recipes/applyFusedLibraryPlugin/app/src/test/java/com/example/fusedlibrarysample/FusedLibraryConsumptionUnitTest.kt +++ b/recipes/applyFusedLibraryPlugin/app/src/test/java/com/example/fusedlibrarysample/FusedLibraryConsumptionUnitTest.kt @@ -29,7 +29,7 @@ import org.junit.Assert.* class FusedLibraryConsumptionUnitTest { @Test - fun `test classes from included dependencies`() { + fun testClassesFromIncludedDependencies() { // Access symbols from local library dependencies val androidLib1Class = ClassFromAndroidLib1() val androidLib2Class = ClassFromAndroidLib2() @@ -45,7 +45,7 @@ class FusedLibraryConsumptionUnitTest { } @Test - fun `test local lib jar dependencies are accessible`() { + fun testLocalLibJarDependenciesAreAccessible() { // Access class in local jar from fused library file dependencies // A_DoIExist is class from a libs jar file dependency // (fusedLibrary/libs/simple-jar-with-A_DoIExist-class.jar) diff --git a/recipes/applyFusedLibraryPlugin/fusedLibrary/build.gradle.kts b/recipes/applyFusedLibraryPlugin/fusedLibrary/build.gradle.kts index d6a14bae..9947d07a 100644 --- a/recipes/applyFusedLibraryPlugin/fusedLibrary/build.gradle.kts +++ b/recipes/applyFusedLibraryPlugin/fusedLibrary/build.gradle.kts @@ -21,12 +21,12 @@ plugins { androidFusedLibrary { namespace = "com.example.fusedlibrary" - minSdk = 34 + minSdk = $MINIMUM_SDK // If aarMetadata is not explicitly specified, // aar metadata will be generated based on dependencies. aarMetadata { - minCompileSdk = 19 + minCompileSdk = $MINIMUM_SDK minCompileSdkExtension = 1 } } @@ -51,6 +51,6 @@ publishing { dependencies { include(project(":androidLib1")) include(project(":androidLib2")) - include("com.google.code.gson:gson:2.11.0") + include("com.google.code.gson:gson:2.10.1") include(files("libs/simple-jar-with-A_DoIExist-class.jar")) } diff --git a/recipes/applyFusedLibraryPlugin/gradle/libs.versions.toml b/recipes/applyFusedLibraryPlugin/gradle/libs.versions.toml index fccdc807..d26c3da4 100644 --- a/recipes/applyFusedLibraryPlugin/gradle/libs.versions.toml +++ b/recipes/applyFusedLibraryPlugin/gradle/libs.versions.toml @@ -1,10 +1,10 @@ [versions] -agp = "8.9.0-alpha03" -kotlin = "1.9.0" +agp = $AGP_VERSION +kotlin = $KOTLIN_VERSION coreKtx = "1.15.0" junit = "4.13.2" -junitVersion = "1.2.1" -espressoCore = "3.6.1" +junitVersion = "1.1.5" +espressoCore = "3.5.1" appcompat = "1.7.0" material = "1.12.0" activity = "1.8.0" diff --git a/recipes/applyFusedLibraryPlugin/recipe_metadata.toml b/recipes/applyFusedLibraryPlugin/recipe_metadata.toml index c4f4a5f9..d31e385f 100644 --- a/recipes/applyFusedLibraryPlugin/recipe_metadata.toml +++ b/recipes/applyFusedLibraryPlugin/recipe_metadata.toml @@ -8,7 +8,7 @@ description =""" """ [agpVersion] -min = "8.9.0" +min = "8.9.0-alpha08" # Relevant Gradle tasks to run per recipe [gradleTasks] @@ -19,10 +19,11 @@ tasks = [ ":fusedLibrary:publishReleasePublicationToMyrepoRepository", ":fusedLibrary:publishReleasePublicationToMyrepoRepository", ":app:testDebugUnitTest", - ":app:connectedDebugAndroidTest" ] # All the relevant metadata fields to create an index based on language/API/etc' [indexMetadata] -index = [] +index = [ + "Plugin Features/Fused Library Plugin" +]