I have an android project which includes 3 modules ModuleA, ModuleB, ModuleC. ModuleA depends on both ModuleB and ModuleC. I'm trying to publish the ModuleA to a maven repository using android-maven-publish plugin and looks like it is not automatically publishing ModuleB and ModuleC to maven when I run publishToMavenLocal. When I try to use published ModuleA as a dependency in a different project gradle could not resolve ModuleB, ModuleC.
Is there something that I am missing?.
I am using gradle plugin version 3.5.0, gradle version 5.4.1 and mavenPublishVersion 3.6.2.
This is how project's gradle looks like
build.gradle(project)
buildScript {
...
dependencies {
classpath "digital.wup:android-maven-publish:3.6.2"
}
}
allprojects {
apply plugin: "digital.wup.android-maven-publish"
}
and ModuleA's build.gradle
build.gradle(ModuleA)
...
dependencies {
api project(":moduleB")
api project(":moduleC")
}
publishing {
repositories {
...
mavenLocal()
}
publications {
mavenSrcModuleA(MavenPublication) {
from components.android
groupId = "com.example.sdk"
artifactId = "moduleA"
version = "1.0.0"
}
}
}
and ModuleB's build.gradle
build.gradle(ModuleB)
...
publishing {
repositories {
...
mavenLocal()
}
publications {
mavenSrcModuleB(MavenPublication) {
from components.android
groupId = "com.example.sdk"
artifactId = "moduleB"
version = "1.0.0"
}
}
}
and ModuleC's build.gradle
build.gradle(ModuleC)
...
publishing {
repositories {
...
mavenLocal()
}
publications {
mavenSrcModuleC(MavenPublication) {
from components.android
groupId = "com.example.sdk"
artifactId = "moduleC"
version = "1.0.0"
}
}
}
Related
I am creating a library project (lets say B) and I have a dependency for another library (let's say A) which I have in the form of an aar (a.aar) file.
When I build b.aar should be packaged in a way that the a.aar will be bundled inside b.aar
Main Project is not controlled by us, so I do not have control to get a.aar while building the main project and they are looking for a way to bundle a.aar while we build b.aar.
Below is the b build.gradle.kts file.
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
plugins {
id("com.android.library")
kotlin("android")
id("gradle-****-android-module")
id("maven-publish")
}
group = "com.****.******"
version = "0.1-SNAPSHOT"
android {
compileSdk = 33
defaultConfig {
minSdk = 23
targetSdk = 33
consumerProguardFiles("proguard-rules.pro")
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}
tasks.withType<KotlinCompile> {
kotlinOptions {
jvmTarget = "11"
}
}
}
dependencies {
implementation("androidx.appcompat:appcompat:1.4.1")
androidTestImplementation("androidx.test:runner:1.4.0")
androidTestImplementation("androidx.test.espresso:espresso-core:3.5.0-alpha06")
testImplementation("junit:junit:4.12")
implementation("com.google.mlkit:image-labeling:17.0.7")
implementation("com.google.android.gms:play-services-mlkit-text-recognition:18.0.2")
implementation("com.google.android.gms:play-services-mlkit-image-labeling:16.0.8")
implementation("com.example.servicelibrary:servicelibrary:1.0")
}
And in my repositories section, I'm trying to load the a.aar file from local maven.
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
val agpVersion: String by project
val repositoryUrl = "file:${rootProject.projectDir.absolutePath}/repository"
repositories {
maven(url = repositoryUrl)
mavenLocal()
google()
mavenCentral()
maven {
url = uri("file://home/*******/.m2/repository/")
}
}
dependencies {
val pmcModuleVersion: String by project
val kotlinVersion: String by project
classpath("com.android.tools.build:gradle:$agpVersion")
classpath(kotlin("gradle-plugin", version = "$kotlinVersion"))
classpath("com.****.gradle.plugins:gradle-****-android-module:$pmcModuleVersion")
}
}
allprojects {
val repositoryUrl = "file:${rootProject.projectDir.absolutePath}/repository"
buildscript {
repositories {
mavenLocal()
google()
mavenCentral()
maven(url = repositoryUrl)
maven {
url = uri("file://home/*******/.m2/repository/")
}
}
}
repositories {
mavenLocal()
google()
mavenCentral()
maven(url = repositoryUrl)
maven {
url = uri("file://home/*******/.m2/repository/")
}
}
}
tasks {
val clean by registering(Delete::class) {
delete(builder)
}
}
Any inputs will be really helpful
In order to bundle LibraryA while building LibraryB, you will need to include LibraryA as a dependency in the build.gradle file of LibraryB.
Follow the steps mentioned below-
Paste ‘LibraryA’ inside the android’s project directory outside the app folder.
In the app level gradle i.e in 'build.gradle(:app)' file of LibraryB, add the following line to the dependencies section:
implementation project(':libraryA')
Make sure that the libraryA module is included in the 'settings.gradle' file of the project
include ':libraryA' //below include ':app'
If their are modules in LibraryA (Eg. Firebase or OneSignalConfig etc) and is mandatory to use then add the module's implementation also in the step 2 -
implementation project(':LibraryA:<module_name>') //add below implementation project(':libraryA')
example - implementation project(':LibraryA:Firebase')
Now try to build and run the app
IN CASE OF ANY DEPENDENCY ERROR WHILE BUILDING/RUNNING THE APP, TRY BELOW STEP
If using latest android structure then Add below code in 'settings.gradle' inside dependencyResolutionManagement{} and inside pluginManagement{}
repositories {
..
maven{url 'https://jitpack.io'} //add this below mavenCentral()
}
If you are using old android structure, then in project level gradle i.e in 'build.gradle(project_name)' add inside allprojects{}-
repositories {
..
maven{url 'https://jitpack.io'} //add below jcenter() and google()
}
I made an aar library and uploaded it locally, and then another project gradle went to download it, which prompted that it could not be downloaded
Library, aar file has been found locally
plugins {
id 'com.android.library'
id 'maven-publish'
}
def GroupId = 'intbird.soft.gradle'
def ArtifactId = 'maven-publish'
def Version = '1.0.0-SNAPSHOT'
afterEvaluate {
publishing {
publications {
release(MavenPublication) {
// Applies the component for the release build variant.
from components.release
// You can then customize attributes of the publication as shown below.
groupId = GroupId
artifactId = ArtifactId
version = Version
pom {
name = "task Lib"
description = "task Lib Project Pom."
url = 'http://localhost.net'
}
}
debug(MavenPublication) {
// Applies the component for the debug build variant.
from components.debug
groupId = GroupId
artifactId = ArtifactId
version = Version
}
}
repositories {
maven {
def releasesRepoUrl = "file://C:\\repository"
def snapshotsRepoUrl = "file://C:\\repository"
url = project.hasProperty('release') ? releasesRepoUrl : snapshotsRepoUrl
}
}
}
}
===============================
My new project
Failed to resolve :intbird.soft.gradle:maven-publish:1.0.0-SNAPSHOT
application gradle code blow:
buildscript {
repositories {
maven { url "file://C:\\repository" }
mavenLocal()
google()
mavenCentral()
}
dependencies {
classpath "com.android.tools.build:gradle:7.0.0"
}
}
app gradle code blow:
dependencies {
implementation 'intbird.soft.gradle:maven-publish:1.0.0-SNAPSHOT'
}
WHY???
I want to publish some subproject to maven by using maven-publish plugin. The current Gradle script looks like this.
apply plugin: 'maven-publish'
group "com.huawei.quickapp"
version "1.0-SNAPSHOT"
publishing {
publications {
publishTask(MavenPublication) {
}
}
repositories {
maven {
url = uri("${rootDir}/local_repo/repos/")
}
}
}
}
static Boolean publishIfNeeded(taskName){
println("name = " + taskName)
def list = ["baselibrary", "corelibrary"]
if (taskName in list) {
return true
}
return false
}
I just want two libraries,core and base to be published. When I submitted the code to the pipeline, the CI suggested that the NDK version did not match, but there was no NDK-related configuration in my code. The upgrade is necessary because only versions greater than 3.6 support the use of From Components.Debug or some other build variable in gradle script.I tried configuring the build script for Subproject separately like this:
buildscript {
ext.kotlin_version = "1.4.21"
repositories {
google()
jcenter()
}
dependencies {
classpath "com.android.tools.build:gradle:3.5.3"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
subprojects {
buildscript {
ext.kotlin_version = "1.4.21"
repositories {
google()
jcenter()
}
dependencies {
classpath "com.android.tools.build:gradle:4.0.1"
}
}
}
but it still not work. I got this error
Could not get unknown property 'Debug' for SoftwareComponentInternal set of type org.gradle.api.internal.component.DefaultSoftwareComponentContainer.
Is there a way to publish a submodule using the buildScripte of a submodule? thx.
I want to add the following library to the Gradle build of my project. The library that I want to add is : signal-protocol-java-2.8.1.jar that I have downloaded. How can I add it in the Gradle build, so that I import the classes included in the .jar it in the java classes that I am developing ?
Here is my build.gradle file :
buildscript {
repositories {
google()
mavenCentral()
jcenter {
content {
includeVersion 'org.jetbrains.trove4j', 'trove4j', '20160824'
includeGroupByRegex "com\\.archinamon.*"
}
}
}
dependencies {
classpath 'com.android.tools.build:gradle:4.0.1'
classpath 'com.google.protobuf:protobuf-gradle-plugin:0.8.14'
classpath "android.arch.navigation:navigation-safe-args-gradle-plugin:1.0.0-alpha09"
}
}
ext {
BUILD_TOOL_VERSION = '30.0.2'
COMPILE_SDK = 30
TARGET_SDK = 30
MINIMUM_SDK = 19
JAVA_VERSION = JavaVersion.VERSION_1_8
}
wrapper {
distributionType = Wrapper.DistributionType.ALL
}
allprojects {
repositories {
google()
jcenter()
}
}
subprojects {
ext.lib_signal_service_version_number = "2.15.3"
ext.lib_signal_service_group_info = "org.whispersystems"
ext.lib_signal_metadata_version = "0.1.2"
if (JavaVersion.current().isJava8Compatible()) {
allprojects {
tasks.withType(Javadoc) {
options.addStringOption('Xdoclint:none', '-quiet')
}
}
}
}
task qa {
group 'Verification'
description 'Quality Assurance. Run before pushing.'
dependsOn ':Signal-Android:testPlayProdReleaseUnitTest',
':Signal-Android:lintPlayProdRelease',
':libsignal-service:test',
':Signal-Android:assemblePlayProdDebug'
}
You have to edit your module-level build.gradle (the one you've posted is project-level). It's typically in the "app" folder of your project. Find there dependencies block and add this line:
dependencies {
implementation fileTree(dir: "libs", include: ["*.jar"])
...
}
Then create a folder "libs" near this gradle file and put your .jar library there. Sync the project with Gradle.
I have JFrog Open Source installed on a server and upload an android aar library by hand.
In the gradle file, I set up a configuration like this.
buildscript {
dependencies { classpath "org.jfrog.buildinfo:build-info-extractor-gradle:latest.release" }
repositories {
maven {
credentials {
username = artifactory_username
password = artifactory_password
}
url "https://.../artifactory/libs-release"
}
}
}
allprojects{
apply plugin: org.jfrog.gradle.plugin.artifactory.ArtifactoryPlugin
artifactory {
resolve {
contextUrl = "https://.../artifactory"
repoKey = 'libs-global'
username = artifactory_username
password = artifactory_password
}
}
}
buildscript {
repositories {
jcenter()
}
dependencies {
classpath "org.jfrog.buildinfo:build-info-extractor-gradle:latest.release"
}
}
apply plugin: "com.jfrog.artifactory"
QUESTION:
How can download or implement my aar libary in the android project?
Example:
implementation 'com.google.code.gson:gson:2.8.6'
You need to add your Jfrog in build.gradle(project) like this:
allprojects {
repositories {
...
maven {
url("https://your-url.jfrog.com/more/path")
}
google()
jcenter()
...
}
}
Then you just add your dependency in dependencies.