How to resolved include module Gradle 6.x? - android

I'm using Gradle 6.6 and have a project include 3 module: app, utils and config; and gradles file
-app
-utils
-config
---Versions.kt
-build.gradle.kts
-settings.gradle.kts
Versions.kt
class Versions {
val kotlin = "1.3.72"
}
settings.gradle.kts
include("app", "utils", "config")
build.gradle.kts
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath(kotlin(module = "gradle-plugin", version = Versions.kotlin))
}
}
allprojects {
repositories {
google()
jcenter()
}
}
This problem is Versions.kotlin in build.gradle.kts file Unresolved reference, although I include config module in settings.gradle.kts
If you understand my problem, please help me, thanks so much!

Related

Packaging Library with another library aar in Kotlin(build.gradle.kts)

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()
}

How do I publish subproject to Maven with subprojects buildscript gradle version?

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.

How to add a library to Gradle build in Android Studio project?

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.

Using Gradle plugin from composite build in root project buildscript

I use Gradle Kotlin DSL and in my project I have separate build-dependencies gradle module which is included in settings.gradle.kts like so:
pluginManagement {
repositories {
google()
jcenter()
gradlePluginPortal()
}
}
includeBuild("build-dependencies")
This module contains empty plugin implementation and Deps object. Its build.gradle.kts below:
repositories {
google()
jcenter()
gradlePluginPortal()
}
plugins {
`kotlin-dsl`
`java-gradle-plugin`
}
gradlePlugin {
plugins.register("com.example.dependencies") {
id = "com.example.dependencies"
implementationClass = "com.example.dependencies.DependenciesPlugin"
}
}
Deps object:
object Deps {
const val buildTools = "com.android.tools.build:gradle:4.1.1"
// more dependencies
}
I want to use this Deps object in all modules by applying the plugin in build.gradle.kts files.
plugins {
id("com.example.dependencies")
}
And it works fine, I can import and use Deps object.
But there is a problem when I want to use it in root projects build.gradle.kts and more precisely in buildscript like so:
buildscript {
repositories {
google()
jcenter()
}
plugins {
id("com.example.dependencies")
}
dependencies {
classpath(com.example.dependencies.Deps.buildTools) // It doesn't work
}
}
Is there any way to use a custom plugin inside buildscript like this or could you suggest something to replace this approach?
I also wonder this. However, I think this is the difference between includeBuild and buildSrc.

Could not find method kotlin() for arguments [gradle-plugin, 1.3.20]

I've copied exactly what the kotlin gradle docs say to implement kotlin gradle plugin, however it's returning the following error:
Could not find method kotlin() for arguments [gradle-plugin, 1.3.20] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.
my gradle
buildscript {
ext.kotlin_version = '1.3.0'
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.3.0'
classpath(kotlin("gradle-plugin", version = "1.3.20"))
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
// ext {
// navigationVersion = '28.0.0'
// }
plugins {
kotlin("<...>")
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
Any idea?
build.gradle can be written in Groovy or Kotlin. You're typing your build.gradle in Groovy (not Kotlin), but you have copied the Kotlin code. You should select the Groovy tab on the documentation:
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath "com.android.tools.build:gradle:3.3.0"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.20"
}
}
Here: https://kotlinlang.org/docs/reference/using-gradle.html#targeting-android
You can also find a decent example by creating an empty Android and Kotlin project.

Categories

Resources