diff --git a/BUILD b/BUILD index 7974b625..777a8c0c 100644 --- a/BUILD +++ b/BUILD @@ -173,3 +173,7 @@ recipe_test( recipe_test( name = "disableTests", ) + +recipe_test( + name = "applyFusedLibraryPlugin", +) diff --git a/recipes/applyFusedLibraryPlugin/README.md b/recipes/applyFusedLibraryPlugin/README.md new file mode 100644 index 00000000..d12e0645 --- /dev/null +++ b/recipes/applyFusedLibraryPlugin/README.md @@ -0,0 +1,173 @@ +# Fused Library Plugin + +## What is Fused Library Plugin? + +An Android Gradle Plugin that helps Android library developers publish multiple Android libraries in a +single Android library artifact i.e. the '.aar' file. + +### *IMPORTANT* - State of the Fused Library Plugin +Fused Library Plugin is currently in an early testing phase. Therefore, artifacts published by the +plugin and plugin behaviour may not be stable at this time. Take caution before distributing +published artifacts created by the plugin; there is no guarantee of correctness. + +As an early adopter, please be aware that there may be frequent breaking changes that may require +you to make changes to your project. + +### This recipe + +This project aims to provide a non-exhaustive, but common examples of plugin usage for consumption +by other libraries. +┌─────────────────────────────────────────┐ +│ :app │ +│ ▲ │ +│ │ │ +│ :fusedLibrary │ +│ ▲ ▲ │ +│ │ │ │ +│ :androidLib2* :androidLib1* │ +│ ▲ ▲ │ +│ │ │ │ +│ :androidLib3 com.google.code.gson:gson* │ +└─────────────────────────────────────────┘ + +This diagram shows an overview of the relevant project dependency structure. +* include dependency of :fusedLibrary + +Example usages of classes, resources and other artifacts are demonstrated in the :app module unit +and instrumentation tests. + +## Usage Guide + +### Setting up the Fused Library + +*This recipe project was set up with the following key steps* + +1. Apply the plugin + gradle/libs.versions.toml append +```kts +[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 +``` +plugins { + alias(libs.plugins.android.fusedlibrary) +} +``` +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: + +```kts +dependencies { + include(project(":androidLib1")) + include(project(":androidLib2")) + include("com.google.code.gson:gson:2.11.0") + include(files("libs/simple-jar-with-A_DoIExist-class.jar")) +} +``` + +### Building the fused library + +1. Check what dependencies will be included in the .aar based on the dependencies configuration + by running `./gradlew :fusedLibrary:report` + Take a look at the report output in the :fusedLibrary build directory + `fusedLibrary/build/reports/fused_library_report/single/report.json`. Check the dependencies that + will be included in the library match your expectations. +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 +Done. + +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. + +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. + +Generating the fused lib POM +1. Follow the steps of `Building a fused library` +2. `./gradlew :fusedLibrary:generatePomFileForMavenPublication` +3. The POM should be created at `fusedLibrary/build/publications/maven/pom-default.xml` +Done. + +Generating a maven repository with the fused library +1. Add configuration to the fused library build file +``` + publishing { + publications { + register("release") { + // Customize with your own publication metadata + groupId = "com.my-company" + artifactId = "my-fused-library" + version = "1.0" + + afterEvaluate { + // fusedLibraryComponent is required for obtaining fused library artifacts + from(components["fusedLibraryComponent"]) + } + } + } + repositories { + maven { + name = "myrepo" + url = uri(layout.buildDirectory.dir("repo")) + } + } + } + +``` +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:publishReleasePublicationToMyrepoRepository` +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 + +| Name | Description | +|---------|:--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| include | Specifies components to be fused into the final artifact. Included components are resolvable at runtime. This configuration is not transitive, therefore dependencies will not be included in the fused artifact. There is no support for file dependencies excluding libs/jars. Databinding dependencies are prohibited. | + +### How can I report issues? + +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%20status:open) + +Follow the below steps and use this [link to **file new bugs**](https://issuetracker.google.com/issues/new?hotlistIds=4053459&component=147324&template=295401) +**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 +Done. diff --git a/recipes/applyFusedLibraryPlugin/androidLib1/.gitignore b/recipes/applyFusedLibraryPlugin/androidLib1/.gitignore new file mode 100644 index 00000000..42afabfd --- /dev/null +++ b/recipes/applyFusedLibraryPlugin/androidLib1/.gitignore @@ -0,0 +1 @@ +/build \ No newline at end of file diff --git a/recipes/applyFusedLibraryPlugin/androidLib1/build.gradle.kts b/recipes/applyFusedLibraryPlugin/androidLib1/build.gradle.kts new file mode 100644 index 00000000..411a4757 --- /dev/null +++ b/recipes/applyFusedLibraryPlugin/androidLib1/build.gradle.kts @@ -0,0 +1,64 @@ +/* + * Copyright 2024 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +plugins { + alias(libs.plugins.android.library) + alias(libs.plugins.jetbrains.kotlin.android) +} + +android { + namespace = "com.example.androidlib1" + compileSdk = 34 + + defaultConfig { + minSdk = 34 + + testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" + consumerProguardFiles("consumer-rules.pro") + } + + buildTypes { + release { + isMinifyEnabled = false + proguardFiles( + getDefaultProguardFile("proguard-android-optimize.txt"), + "proguard-rules.pro" + ) + } + } + sourceSets { + named("main") { + resources.srcDirs("src/main/resources") + } + } + compileOptions { + sourceCompatibility = JavaVersion.VERSION_1_8 + targetCompatibility = JavaVersion.VERSION_1_8 + } + kotlinOptions { + jvmTarget = "1.8" + } +} + +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) +} diff --git a/recipes/applyFusedLibraryPlugin/androidLib1/consumer-rules.pro b/recipes/applyFusedLibraryPlugin/androidLib1/consumer-rules.pro new file mode 100644 index 00000000..e69de29b diff --git a/recipes/applyFusedLibraryPlugin/androidLib1/proguard-rules.pro b/recipes/applyFusedLibraryPlugin/androidLib1/proguard-rules.pro new file mode 100644 index 00000000..481bb434 --- /dev/null +++ b/recipes/applyFusedLibraryPlugin/androidLib1/proguard-rules.pro @@ -0,0 +1,21 @@ +# Add project specific ProGuard rules here. +# You can control the set of applied configuration files using the +# proguardFiles setting in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} + +# Uncomment this to preserve the line number information for +# debugging stack traces. +#-keepattributes SourceFile,LineNumberTable + +# If you keep the line number information, uncomment this to +# hide the original source file name. +#-renamesourcefileattribute SourceFile \ No newline at end of file diff --git a/recipes/applyFusedLibraryPlugin/androidLib1/src/main/AndroidManifest.xml b/recipes/applyFusedLibraryPlugin/androidLib1/src/main/AndroidManifest.xml new file mode 100644 index 00000000..c1baa121 --- /dev/null +++ b/recipes/applyFusedLibraryPlugin/androidLib1/src/main/AndroidManifest.xml @@ -0,0 +1,17 @@ + + + + + + \ No newline at end of file diff --git a/recipes/applyFusedLibraryPlugin/androidLib1/src/main/assets/androidLib1-asset.json b/recipes/applyFusedLibraryPlugin/androidLib1/src/main/assets/androidLib1-asset.json new file mode 100644 index 00000000..386af8d8 --- /dev/null +++ b/recipes/applyFusedLibraryPlugin/androidLib1/src/main/assets/androidLib1-asset.json @@ -0,0 +1,5 @@ +[ + { + "info" : "This is an asset from androidLib1" + } +] \ No newline at end of file diff --git a/recipes/applyFusedLibraryPlugin/androidLib1/src/main/java/com/example/androidlib1/ClassFromAndroidLib1.kt b/recipes/applyFusedLibraryPlugin/androidLib1/src/main/java/com/example/androidlib1/ClassFromAndroidLib1.kt new file mode 100644 index 00000000..3100dee0 --- /dev/null +++ b/recipes/applyFusedLibraryPlugin/androidLib1/src/main/java/com/example/androidlib1/ClassFromAndroidLib1.kt @@ -0,0 +1,25 @@ +/* + * Copyright (C) 2024 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.example.androidlib1 + + +class ClassFromAndroidLib1 { + + fun foo(): String { + return "foo" + } +} \ No newline at end of file diff --git a/recipes/applyFusedLibraryPlugin/androidLib1/src/main/res/values/strings.xml b/recipes/applyFusedLibraryPlugin/androidLib1/src/main/res/values/strings.xml new file mode 100644 index 00000000..f28b8ef3 --- /dev/null +++ b/recipes/applyFusedLibraryPlugin/androidLib1/src/main/res/values/strings.xml @@ -0,0 +1,20 @@ + + + + + androidLib1 + \ No newline at end of file diff --git a/recipes/applyFusedLibraryPlugin/androidLib2/.gitignore b/recipes/applyFusedLibraryPlugin/androidLib2/.gitignore new file mode 100644 index 00000000..42afabfd --- /dev/null +++ b/recipes/applyFusedLibraryPlugin/androidLib2/.gitignore @@ -0,0 +1 @@ +/build \ No newline at end of file diff --git a/recipes/applyFusedLibraryPlugin/androidLib2/build.gradle.kts b/recipes/applyFusedLibraryPlugin/androidLib2/build.gradle.kts new file mode 100644 index 00000000..70bded8d --- /dev/null +++ b/recipes/applyFusedLibraryPlugin/androidLib2/build.gradle.kts @@ -0,0 +1,51 @@ +/* + * Copyright (C) 2024 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +plugins { + alias(libs.plugins.android.library) + alias(libs.plugins.jetbrains.kotlin.android) + `maven-publish` +} + +android { + namespace = "com.example.androidlib2" + compileSdk = 34 + + defaultConfig { + minSdk = 34 + + testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" + } + + compileOptions { + sourceCompatibility = JavaVersion.VERSION_1_8 + targetCompatibility = JavaVersion.VERSION_1_8 + } + kotlinOptions { + jvmTarget = "1.8" + } +} + +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/proguard-rules.pro b/recipes/applyFusedLibraryPlugin/androidLib2/proguard-rules.pro new file mode 100644 index 00000000..481bb434 --- /dev/null +++ b/recipes/applyFusedLibraryPlugin/androidLib2/proguard-rules.pro @@ -0,0 +1,21 @@ +# Add project specific ProGuard rules here. +# You can control the set of applied configuration files using the +# proguardFiles setting in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} + +# Uncomment this to preserve the line number information for +# debugging stack traces. +#-keepattributes SourceFile,LineNumberTable + +# If you keep the line number information, uncomment this to +# hide the original source file name. +#-renamesourcefileattribute SourceFile \ No newline at end of file diff --git a/recipes/applyFusedLibraryPlugin/androidLib2/src/main/AndroidManifest.xml b/recipes/applyFusedLibraryPlugin/androidLib2/src/main/AndroidManifest.xml new file mode 100644 index 00000000..b0b46829 --- /dev/null +++ b/recipes/applyFusedLibraryPlugin/androidLib2/src/main/AndroidManifest.xml @@ -0,0 +1,25 @@ + + + + + + + + \ No newline at end of file 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 new file mode 100644 index 00000000..3d35cf9d --- /dev/null +++ b/recipes/applyFusedLibraryPlugin/androidLib2/src/main/java/com/example/androidlib2/ClassFromAndroidLib2.kt @@ -0,0 +1,27 @@ +/* + * Copyright (C) 2024 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.example.androidlib2 + +import android.content.Context +import android.provider.Settings.Global.getString + +class ClassFromAndroidLib2 { + + fun foo(): String { + return "bar" + } +} \ No newline at end of file diff --git a/recipes/applyFusedLibraryPlugin/androidLib2/src/main/res/values/colors.xml b/recipes/applyFusedLibraryPlugin/androidLib2/src/main/res/values/colors.xml new file mode 100644 index 00000000..11cb8ab7 --- /dev/null +++ b/recipes/applyFusedLibraryPlugin/androidLib2/src/main/res/values/colors.xml @@ -0,0 +1,26 @@ + + + + + #FFBB86FC + #FF6200EE + #FF3700B3 + #FF03DAC5 + #FF018786 + #FF000000 + #FFFFFFFF + \ No newline at end of file diff --git a/recipes/applyFusedLibraryPlugin/androidLib2/src/main/res/values/strings.xml b/recipes/applyFusedLibraryPlugin/androidLib2/src/main/res/values/strings.xml new file mode 100644 index 00000000..8c84c78a --- /dev/null +++ b/recipes/applyFusedLibraryPlugin/androidLib2/src/main/res/values/strings.xml @@ -0,0 +1,20 @@ + + + + androidLib2 + androidLib2 + \ No newline at end of file diff --git a/recipes/applyFusedLibraryPlugin/androidLib3/.gitignore b/recipes/applyFusedLibraryPlugin/androidLib3/.gitignore new file mode 100644 index 00000000..42afabfd --- /dev/null +++ b/recipes/applyFusedLibraryPlugin/androidLib3/.gitignore @@ -0,0 +1 @@ +/build \ No newline at end of file diff --git a/recipes/applyFusedLibraryPlugin/androidLib3/build.gradle.kts b/recipes/applyFusedLibraryPlugin/androidLib3/build.gradle.kts new file mode 100644 index 00000000..50f053d4 --- /dev/null +++ b/recipes/applyFusedLibraryPlugin/androidLib3/build.gradle.kts @@ -0,0 +1,75 @@ +/* + * Copyright 2024 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +plugins { + alias(libs.plugins.android.library) + alias(libs.plugins.jetbrains.kotlin.android) + `maven-publish` +} + +android { + namespace = "com.example.androidlib3" + compileSdk = 34 + + defaultConfig { + minSdk = 24 + + testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" + consumerProguardFiles("consumer-rules.pro") + } + + buildTypes { + release { + isMinifyEnabled = false + proguardFiles( + getDefaultProguardFile("proguard-android-optimize.txt"), + "proguard-rules.pro" + ) + } + } + compileOptions { + sourceCompatibility = JavaVersion.VERSION_1_8 + targetCompatibility = JavaVersion.VERSION_1_8 + } + kotlinOptions { + jvmTarget = "1.8" + } +} + +publishing { + publications { + register("maven") { + afterEvaluate { + from(components["release"]) + } + } + } + repositories { + maven { + name = "myrepo" + url = uri(project(":fusedLibrary").layout.buildDirectory.dir("repo")) + } + } +} + +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/androidLib3/consumer-rules.pro b/recipes/applyFusedLibraryPlugin/androidLib3/consumer-rules.pro new file mode 100644 index 00000000..e69de29b diff --git a/recipes/applyFusedLibraryPlugin/androidLib3/proguard-rules.pro b/recipes/applyFusedLibraryPlugin/androidLib3/proguard-rules.pro new file mode 100644 index 00000000..481bb434 --- /dev/null +++ b/recipes/applyFusedLibraryPlugin/androidLib3/proguard-rules.pro @@ -0,0 +1,21 @@ +# Add project specific ProGuard rules here. +# You can control the set of applied configuration files using the +# proguardFiles setting in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} + +# Uncomment this to preserve the line number information for +# debugging stack traces. +#-keepattributes SourceFile,LineNumberTable + +# If you keep the line number information, uncomment this to +# hide the original source file name. +#-renamesourcefileattribute SourceFile \ No newline at end of file diff --git a/recipes/applyFusedLibraryPlugin/androidLib3/src/main/AndroidManifest.xml b/recipes/applyFusedLibraryPlugin/androidLib3/src/main/AndroidManifest.xml new file mode 100644 index 00000000..afe630bd --- /dev/null +++ b/recipes/applyFusedLibraryPlugin/androidLib3/src/main/AndroidManifest.xml @@ -0,0 +1,20 @@ + + + + + + \ No newline at end of file diff --git a/recipes/applyFusedLibraryPlugin/androidLib3/src/main/java/com/example/androidlib3/AndroidLib3Class.kt b/recipes/applyFusedLibraryPlugin/androidLib3/src/main/java/com/example/androidlib3/AndroidLib3Class.kt new file mode 100644 index 00000000..61975fd7 --- /dev/null +++ b/recipes/applyFusedLibraryPlugin/androidLib3/src/main/java/com/example/androidlib3/AndroidLib3Class.kt @@ -0,0 +1,23 @@ +/* + * Copyright (C) 2024 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.example.androidlib3 + +class AndroidLib3Class { + + fun bar(): String { + return "foo" + } +} \ No newline at end of file diff --git a/recipes/applyFusedLibraryPlugin/androidLib3/src/main/res/values/strings.xml b/recipes/applyFusedLibraryPlugin/androidLib3/src/main/res/values/strings.xml new file mode 100644 index 00000000..07129f89 --- /dev/null +++ b/recipes/applyFusedLibraryPlugin/androidLib3/src/main/res/values/strings.xml @@ -0,0 +1,20 @@ + + + + androidLib3 + androidLib3 + diff --git a/recipes/applyFusedLibraryPlugin/app/.gitignore b/recipes/applyFusedLibraryPlugin/app/.gitignore new file mode 100644 index 00000000..42afabfd --- /dev/null +++ b/recipes/applyFusedLibraryPlugin/app/.gitignore @@ -0,0 +1 @@ +/build \ No newline at end of file diff --git a/recipes/applyFusedLibraryPlugin/app/build.gradle.kts b/recipes/applyFusedLibraryPlugin/app/build.gradle.kts new file mode 100644 index 00000000..84cf6b7a --- /dev/null +++ b/recipes/applyFusedLibraryPlugin/app/build.gradle.kts @@ -0,0 +1,74 @@ +/* + * Copyright (C) 2024 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +plugins { + alias(libs.plugins.android.application) + alias(libs.plugins.jetbrains.kotlin.android) +} + +android { + namespace = "com.example.fusedlibrarysample" + compileSdk = 35 + + defaultConfig { + applicationId = "com.example.fusedlibrarysample" + minSdk = 34 + targetSdk = 34 + versionCode = 1 + versionName = "1.0" + + testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" + } + + buildTypes { + release { + isMinifyEnabled = false + proguardFiles( + getDefaultProguardFile("proguard-android-optimize.txt"), + "proguard-rules.pro" + ) + } + } + compileOptions { + sourceCompatibility = JavaVersion.VERSION_17 + targetCompatibility = JavaVersion.VERSION_17 + } + kotlinOptions { + jvmTarget = "17" + } +} + +dependencies { + implementation(project(":fusedLibrary")) + implementation(libs.mycompany.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) +} + +configurations.all { + resolutionStrategy.dependencySubstitution { + if (file("${rootProject.projectDir}/fusedLibrary/build/repo").exists()) { + substitute(project(":fusedLibrary")) + .using(module("my-company:my-fused-library:1.0")) + } + } +} diff --git a/recipes/applyFusedLibraryPlugin/app/proguard-rules.pro b/recipes/applyFusedLibraryPlugin/app/proguard-rules.pro new file mode 100644 index 00000000..481bb434 --- /dev/null +++ b/recipes/applyFusedLibraryPlugin/app/proguard-rules.pro @@ -0,0 +1,21 @@ +# Add project specific ProGuard rules here. +# You can control the set of applied configuration files using the +# proguardFiles setting in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} + +# Uncomment this to preserve the line number information for +# debugging stack traces. +#-keepattributes SourceFile,LineNumberTable + +# If you keep the line number information, uncomment this to +# hide the original source file name. +#-renamesourcefileattribute SourceFile \ No newline at end of file diff --git a/recipes/applyFusedLibraryPlugin/app/src/main/AndroidManifest.xml b/recipes/applyFusedLibraryPlugin/app/src/main/AndroidManifest.xml new file mode 100644 index 00000000..794426c7 --- /dev/null +++ b/recipes/applyFusedLibraryPlugin/app/src/main/AndroidManifest.xml @@ -0,0 +1,23 @@ + + + + + + + + + \ No newline at end of file diff --git a/recipes/applyFusedLibraryPlugin/app/src/main/res/values/strings.xml b/recipes/applyFusedLibraryPlugin/app/src/main/res/values/strings.xml new file mode 100644 index 00000000..80a9daf3 --- /dev/null +++ b/recipes/applyFusedLibraryPlugin/app/src/main/res/values/strings.xml @@ -0,0 +1,20 @@ + + + + Fused Library Sample + @string/string_from_androidLib_1 + \ No newline at end of file diff --git a/recipes/applyFusedLibraryPlugin/build.gradle.kts b/recipes/applyFusedLibraryPlugin/build.gradle.kts new file mode 100644 index 00000000..965844cc --- /dev/null +++ b/recipes/applyFusedLibraryPlugin/build.gradle.kts @@ -0,0 +1,23 @@ +/* + * Copyright (C) 2024 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// Top-level build file where you can add configuration options common to all sub-projects/modules. +plugins { + alias(libs.plugins.android.application) apply false + alias(libs.plugins.jetbrains.kotlin.android) apply false + alias(libs.plugins.android.library) apply false + alias(libs.plugins.android.fusedlibrary) apply false +} diff --git a/recipes/applyFusedLibraryPlugin/docs/CONTRIBUTING.md b/recipes/applyFusedLibraryPlugin/docs/CONTRIBUTING.md new file mode 100644 index 00000000..bc23aaed --- /dev/null +++ b/recipes/applyFusedLibraryPlugin/docs/CONTRIBUTING.md @@ -0,0 +1,33 @@ +# How to contribute + +We'd love to accept your patches and contributions to this project. + +## Before you begin + +### Sign our Contributor License Agreement + +Contributions to this project must be accompanied by a +[Contributor License Agreement](https://cla.developers.google.com/about) (CLA). +You (or your employer) retain the copyright to your contribution; this simply +gives us permission to use and redistribute your contributions as part of the +project. + +If you or your current employer have already signed the Google CLA (even if it +was for a different project), you probably don't need to do it again. + +Visit to see your current agreements or to +sign a new one. + +### Review our community guidelines + +This project follows +[Google's Open Source Community Guidelines](https://opensource.google/conduct/). + +## Contribution process + +### Code reviews + +All submissions, including submissions by project members, require review. We +use GitHub pull requests for this purpose. Consult +[GitHub Help](https://help.github.com/articles/about-pull-requests/) for more +information on using pull requests. \ No newline at end of file diff --git a/recipes/applyFusedLibraryPlugin/fusedLibrary/.gitignore b/recipes/applyFusedLibraryPlugin/fusedLibrary/.gitignore new file mode 100644 index 00000000..42afabfd --- /dev/null +++ b/recipes/applyFusedLibraryPlugin/fusedLibrary/.gitignore @@ -0,0 +1 @@ +/build \ No newline at end of file diff --git a/recipes/applyFusedLibraryPlugin/fusedLibrary/build.gradle.kts b/recipes/applyFusedLibraryPlugin/fusedLibrary/build.gradle.kts new file mode 100644 index 00000000..7ad5c784 --- /dev/null +++ b/recipes/applyFusedLibraryPlugin/fusedLibrary/build.gradle.kts @@ -0,0 +1,57 @@ +/* + * Copyright (C) 2024 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +plugins { + alias(libs.plugins.android.fusedlibrary) + `maven-publish` +} + +androidFusedLibrary { + namespace = "com.example.fusedlibrary" + minSdk = 34 + + // If aarMetadata is not explicitly specified, + // aar metadata will be generated based on dependencies. + aarMetadata { + minAgpVersion = "8.9.0" + minCompileSdk = 34 + minCompileSdkExtension = 1 + } +} + +publishing { + publications { + register("release") { + groupId = "my-company" + artifactId = "my-fused-library" + version = "1.0" + from(components["fusedLibraryComponent"]) + } + } + repositories { + maven { + name = "myrepo" + url = uri(layout.buildDirectory.dir("repo")) + } + } +} + +dependencies { + include(project(":androidLib1")) + include(project(":androidLib2")) + include("com.google.code.gson:gson:2.11.0") + include(files("libs/simple-jar-with-A_DoIExist-class.jar")) +} diff --git a/recipes/applyFusedLibraryPlugin/fusedLibrary/consumer-rules.pro b/recipes/applyFusedLibraryPlugin/fusedLibrary/consumer-rules.pro new file mode 100644 index 00000000..e69de29b diff --git a/recipes/applyFusedLibraryPlugin/fusedLibrary/libs/simple-jar-with-A_DoIExist-class.jar b/recipes/applyFusedLibraryPlugin/fusedLibrary/libs/simple-jar-with-A_DoIExist-class.jar new file mode 100644 index 00000000..59dc60e5 Binary files /dev/null and b/recipes/applyFusedLibraryPlugin/fusedLibrary/libs/simple-jar-with-A_DoIExist-class.jar differ diff --git a/recipes/applyFusedLibraryPlugin/fusedLibrary/proguard-rules.pro b/recipes/applyFusedLibraryPlugin/fusedLibrary/proguard-rules.pro new file mode 100644 index 00000000..481bb434 --- /dev/null +++ b/recipes/applyFusedLibraryPlugin/fusedLibrary/proguard-rules.pro @@ -0,0 +1,21 @@ +# Add project specific ProGuard rules here. +# You can control the set of applied configuration files using the +# proguardFiles setting in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} + +# Uncomment this to preserve the line number information for +# debugging stack traces. +#-keepattributes SourceFile,LineNumberTable + +# If you keep the line number information, uncomment this to +# hide the original source file name. +#-renamesourcefileattribute SourceFile \ No newline at end of file diff --git a/recipes/applyFusedLibraryPlugin/gradle.properties b/recipes/applyFusedLibraryPlugin/gradle.properties new file mode 100644 index 00000000..66462255 --- /dev/null +++ b/recipes/applyFusedLibraryPlugin/gradle.properties @@ -0,0 +1,27 @@ +# 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=-Xmx2048m -Dfile.encoding=UTF-8 +# When configured, Gradle will run in incubating parallel mode. +# This option should only be used with decoupled projects. For more details, visit +# https://developer.android.com/r/tools/gradle-multi-project-decoupled-projects +# org.gradle.parallel=true +# AndroidX package structure to make it clearer which packages are bundled with the +# Android operating system, and which are packaged with your app's APK +# https://developer.android.com/topic/libraries/support-library/androidx-rn +android.useAndroidX=true +# Kotlin code style for this project: "official" or "obsolete": +kotlin.code.style=official +# Enables namespacing of each library's R class so that its R class includes only the +# resources declared in the library itself and none from the library's dependencies, +# thereby reducing the size of the R class for that library +android.nonTransitiveRClass=true + +# Required for builds with at least one module applying +# the experimental "com.android.fused-library" plugin. +android.experimental.fusedLibrarySupport=true \ No newline at end of file diff --git a/recipes/applyFusedLibraryPlugin/gradle/libs.versions.toml b/recipes/applyFusedLibraryPlugin/gradle/libs.versions.toml new file mode 100644 index 00000000..fccdc807 --- /dev/null +++ b/recipes/applyFusedLibraryPlugin/gradle/libs.versions.toml @@ -0,0 +1,30 @@ +[versions] +agp = "8.9.0-alpha03" +kotlin = "1.9.0" +coreKtx = "1.15.0" +junit = "4.13.2" +junitVersion = "1.2.1" +espressoCore = "3.6.1" +appcompat = "1.7.0" +material = "1.12.0" +activity = "1.8.0" +constraintlayout = "2.1.4" +mycompany = "1.0" + +[libraries] +androidx-core-ktx = { group = "androidx.core", name = "core-ktx", version.ref = "coreKtx" } +junit = { group = "junit", name = "junit", version.ref = "junit" } +androidx-junit = { group = "androidx.test.ext", name = "junit", version.ref = "junitVersion" } +androidx-espresso-core = { group = "androidx.test.espresso", name = "espresso-core", version.ref = "espressoCore" } +androidx-appcompat = { group = "androidx.appcompat", name = "appcompat", version.ref = "appcompat" } +material = { group = "com.google.android.material", name = "material", version.ref = "material" } +androidx-activity = { group = "androidx.activity", name = "activity", version.ref = "activity" } +androidx-constraintlayout = { group = "androidx.constraintlayout", name = "constraintlayout", version.ref = "constraintlayout" } +mycompany-fusedlibrary = { group = "my-company", name = "my-fused-library", version.ref = "mycompany" } + +[plugins] +android-application = { id = "com.android.application", version.ref = "agp" } +jetbrains-kotlin-android = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" } +android-library = { id = "com.android.library", version.ref = "agp" } +android-fusedlibrary = { id = "com.android.fused-library", version.ref = "agp" } + diff --git a/recipes/applyFusedLibraryPlugin/recipe_metadata.toml b/recipes/applyFusedLibraryPlugin/recipe_metadata.toml new file mode 100644 index 00000000..b10bdeb8 --- /dev/null +++ b/recipes/applyFusedLibraryPlugin/recipe_metadata.toml @@ -0,0 +1,26 @@ +# optional (if present and non-blank) name to use in the index +indexName = "" +# optional (if present and non-blank) folder name to use when converting recipe in RELEASE mode +destinationFolder = "" + +description =""" + Recipe to demonstrate FusedLibraryPlugin usage. + """ + +[agpVersion] +min = "8.9.0" + +# Relevant Gradle tasks to run per recipe +[gradleTasks] +tasks = [ + ":fusedLibrary:assemble", + ":fusedLibrary:report", + ":fusedLibrary:generatePomFileForMavenPublication", + ":fusedLibrary:generateRepo", + ":androidLib3:generateRepo" +] + +# All the relevant metadata fields to create an index based on language/API/etc' +[indexMetadata] +index = [] + diff --git a/recipes/applyFusedLibraryPlugin/settings.gradle.kts b/recipes/applyFusedLibraryPlugin/settings.gradle.kts new file mode 100644 index 00000000..aafedea2 --- /dev/null +++ b/recipes/applyFusedLibraryPlugin/settings.gradle.kts @@ -0,0 +1,40 @@ +/* + * Copyright (C) 2024 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +rootProject.name = "fused-library-samples" + +pluginManagement { + repositories { + $AGP_REPOSITORY + $PLUGIN_REPOSITORIES + maven(url = uri("${rootProject.projectDir}/fusedLibrary/build/repo")) + } +} + +dependencyResolutionManagement { + repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS) + repositories { + $AGP_REPOSITORY + $DEPENDENCY_REPOSITORIES + maven(url = uri("${rootProject.projectDir}/fusedLibrary/build/repo")) + } +} + +include(":app") +include(":fusedLibrary") +include(":androidLib1") +include(":androidLib2") +include(":androidLib3")