Can not build the multi-module android app - android

I try to make multi module app and get Type com.example.boombadproject.BuildConfig is defined multiple time when I try to run the app , The problem is disappear when I comment the implementation of module
implementation(project(Modules.core))
/*implementation(project(Modules.onboardingPresentation))
implementation(project(Modules.onboardingDomain))
implementation(project(Modules.trackerPresentation))
implementation(project(Modules.trackerDomain))
implementation(project(Modules.trackerData))*/
I try to clean project, rebluild.I found some solutions to change the pakge name in manifest but still have the issue
--- setting.gradle
pluginManagement {
repositories {
google()
mavenCentral()
gradlePluginPortal()
}
}
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
google()
mavenCentral()
classpath
}
}
rootProject.name = "BoomBadProject"
include ':app'
include ':onboarding'
include ':onboarding:onboarding_domain'
include ':onboarding:onboarding_presentation'
include ':core'
include ':tracker'
include ':tracker:tracker_data'
include ':tracker:tracker_domain'
include ':tracker:tracker_presentation'
-- build.gradle.kts project level
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
mavenCentral()
}
dependencies {
classpath(Build.androidBuildTools)
classpath(Build.hiltAndroidGradlePlugin)
classpath(Build.kotlinGradlePlugin)
classpath("com.android.tools.build:gradle:7.4.1")
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.8.0")
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
tasks.register("clean",Delete::class){
delete(rootProject.buildDir)
}

I didn't see your import, are you import these modules in settings.gradle ?
include ':Modules.core'

Check your manifests to ensure that the different modules don't have the same namespace i.e. com.example.boombadproject you could change it in two ways:
On the manifest file of the module
<manifest package="com.example.boombadproject.onboarding"/>
or Under the android tag on build.gradle file and append the library name etc;
android {
namespace = com.example.boombadproject.onboarding
}

Related

Changes in Android Studio's project gradle file

I have recently updated my Android Studio to latest version. But the gradle file here seems bit different.
here is the gradle code :
// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins {
id 'com.android.application' version '7.3.1' apply false
id 'com.android.library' version '7.3.1' apply false
id 'org.jetbrains.kotlin.android' version '1.7.20' apply false
}
I want to add these below jitsi lines in the project gradle file. how should I paste it so that it syncs properly without any errors.
here is the jitsi code :
allprojects {
repositories {
maven {
url "https://github.com/jitsi/jitsi-maven-repository/raw/master/releases"
}
google()
mavenCentral()
maven { url 'https://www.jitpack.io' }
}
}
I have tried changing the gradle file by adding or replacing the above lines, Nothing changes. It is throwing an error.
As you appear to be using the recently revised build configuration scripts, you should be able to declare your repositories under the settings.gradle file:
pluginManagement {
// Plugin repositories go here
}
// ...
dependencyResolutionManagement {
/**
* The dependencyResolutionManagement {repositories {...}}
* block is where you configure the repositories and dependencies used by
* all modules in your project, such as libraries that you are using to
* create your application. However, you should configure module-specific
* dependencies in each module-level build.gradle file. For new projects,
* Android Studio includes Google's Maven repository and the Maven Central
* Repository by default, but it does not configure any dependencies (unless
* you select a template that requires some).
*/
// The following line makes it so that project modules (such as your
// "app" module) can't declare their own repositories {} block
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
google()
mavenCentral()
// Add your repositories here...
maven {
url "https://github.com/jitsi/jitsi-maven-repository/raw/master/releases"
}
maven { url 'https://www.jitpack.io' }
}
}
only buildscript {}, pluginManagement {} and other plugins {} script blocks are allowed before plugins {} blocks, no other statements are allowed
As for this error, this is because plugins blocks are always resolved first, and so any other code must be declared after that block:
// There shouldn't be any code before this!
plugins {
}
// Okay to have build script code here...
Android studio latest version you move the jitsi repository in the project's settings.gradle file
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
google()
mavenCentral()
mavenLocal()
}
}

How can I add jitpack.io as a repository in my build.gradle correctly?

I want to use Stepper-Touch github library. For this I have to add jitpack.io in
allproject{
repositories{
[here]
}
}
in my build.gradle project file. There isn't
allproject{...}
section, so I added it myself, but i got this error
Build was configured to prefer settings repositories over project repositories but repository 'maven' was added by build file 'build.gradle'
Then I looked for answer and found that someone says I should remove
dependencyResolutionManagement
section in my settings.gradle file. I did, but then other dependencies such as constraint layout's, live data's dependencies stopped working.
Help me, how can I fix that all? :(
As of the 7.X.X gradle build tools. allprojects is deprecated use of dependencyResolutionManagement is the best practice for declaring repositories in every subproject of your build. Because of this Android projects will no longer generate with allprojects blocks in their project build.gradle files. It will instead generate a dependencyResolutionManagement block in settings.gradle.
You shouldn't experince any issues if you use dependencyResolutionManagement
to achieve the same result as an allprojects block. You can add repositories to the dependencyResolutionManagement repositories block just like you would with an allprojects block like so
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
google()
mavenCentral()
jcenter() // Warning: this repository is going to shut down soon
// e.g this is how you would add jitpack
maven { url "https://jitpack.io" }
// Add any repositories you would be adding to all projects here
}
}
If you would like to use the old way
Remove the whole dependencyResolutionManagement block from your settings.gradle so that it looks like
rootProject.name = "My Application"
include ':app'
Then add the the allproject block to your project build.gradle and make sure to add all of the dependencies that were in your dependencyResolutionManagement so in our example it would look like
allprojects {
repositories {
google()
mavenCentral()
jcenter() // Warning: this repository is going to shut down soon
// e.g this is how you would add jitpack
maven { url "https://jitpack.io" }
// Add any repositories you would be adding to all projects here
}
}

Android Studio project structure VS build.gradle

I'm trying to add a maven repository to my project by adding it to build.gradle
repositories {
maven {
url "https://XXX/"
}
}
It works fine when I build in the console. When I try to build it with Android Studio, the dependency that I use in that repository is not found.
When I add the repository to File > project structure > project > Default library Repository bam! it works.
What am I doing wrong? why do I have to duplicate the information? What is exactly the purpose of that configuration since it's already in build.gradle file?
Thank you
Aghilas, i am not sure if it is issue with https or http.
I am putting down what works for me. you can add 'maven()' in the block depending on that repo is required for buildscript functionality or for your app.
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.3.2'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
}
}

Why can't I really follow this Android Studio tutorial?

I am following this tutorial on how to use Android Studio to create android apps. At the very end, the user opens the file 'build.gradle' which looks completely different from what I have:
// Top-level build file where you can add configuration options common to
all sub-projects/modules.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.3.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
Maybe this is not very important? Or is the video using an old version of AndroidStudio/SDK/gradle/whatever?
You are opening the top-level gradle file. The gradle file that appears in the video is the app module one.
You can have more than one module in the same project to divide your app code and/or to create different apps that share some code. Each module has its own gradle file to configure its dependencies and know how to compile it. The top-level file contains common configuration options for all modules, as the top comment tells.

How do I add dependencies to gradle.build

I am working on Android Studio and my activities include ViewPagers. For that I had to install packages (Android Support Repository and Android Support Library). Now that I have already installed these, I opened gradle.build and this is what I see:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.13.2'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
My question:
What should I add and where should I add it in here?
Also, I cant locate SDK in my computer :/ . A little help would be really appreciated.
Android use multi project build setup. Your existing file is MAIN build.gradle file.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.13.2'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
// this is where you need to put dependencies of your BUILD SCRIPT
}
}
allprojects {
repositories {
jcenter()
}
dependencies {
compile group: 'org.apache.logging.log4j', name: 'log4j-api', version: '2.1'
compile group: 'org.apache.logging.log4j', name: 'log4j-core', version: '2.1'
// This is where you put dependencies EVERYONE of your modules need.
}
}
In the sub directories of your main build.gradle resides individual build.gradle files.
Module A
dependencies {
// This is where you put dependencies, your module need.
}
Module B
dependencies {
// This is where you put dependencies, your module need.
}
There are more than one gradle files. one of them is located in your project directory. Same name (build.gradle). find it and put your dependencies there.
To find your SDK path: File -> Project Structure -> SDK Location. (Android Studio v0.8.14)

Categories

Resources