I have some problems with building multiproject with gradle. I read all similar questions but nothing help. The structure of my projects looks like:
App/
settings.gradle
app/
build.gradle
libraries/
Core(git submodule)/
Core/
build.gradle
libraries/
ZBarLibrary/
build.gradle
settings.gradle
App/settings.gradle
include ':App', ':libraries:Core', ':libraries:ZBarLibrary'
project(':libraries:Core').projectDir = new File(settingsDir, 'libraries/Core/Core')
project(':libraries:ZBarLibrary').projectDir = new File(settingsDir, 'libraries/Core/libraries/ZBarLibrary')
App/app/build.gradle
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.5.+'
}
}
apply plugin: 'android'
repositories {
mavenCentral()
}
android {
compileSdkVersion 17
buildToolsVersion "17.0.0"
defaultConfig {
minSdkVersion 14
targetSdkVersion 16
}
}
dependencies {
compile 'com.android.support:support-v4:18.0.0'
compile project(':libraries:Core')
}
App/libraries/Core/Core/build.gradle
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.5.+'
}
}
apply plugin: 'android'
repositories {
mavenCentral()
}
dependencies {
instrumentTestCompile "junit:junit:4.5+"
compile project(':libraries:ZBarLibrary')
compile fileTree(dir: 'libs', include: '*.jar')
}
android {
compileSdkVersion 17
buildToolsVersion "17.0.0"
defaultConfig {
minSdkVersion 14
targetSdkVersion 16
}
}
App/libraries/Core/libraries/ZBarLibrary/build.gradle
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.5.+'
}
}
apply plugin: 'android-library'
repositories {
mavenCentral()
}
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
}
android {
compileSdkVersion 17
buildToolsVersion "17.0.0"
defaultConfig {
minSdkVersion 14
targetSdkVersion 16
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
}
}
Command "gradle build" in App directory generates error: "package com… does not exist". This package is used in app module but it is find in App/libraries/Core/Core/src/main/java. Could you help me?
Your app module's build.gradle should contain (among other things)
apply plugin: 'com.android.application'
dependencies {
compile project(':my_library_module')
}
Your library module's build.gradle file should contain
apply plugin: 'com.android.library'
If you're using Core as library you should change apply plugin: 'android' to apply plugin: 'android-library' in App/libraries/Core/Core/build.gradle
To resolve the package not found errors, in the app module's build.gradle file I added
dependencies {
// ...
compile project(':library')
}
which adds the library module as a dependency to the app module
I have the same problem with Gradle 6.4 (multi-module project) and Java 13
Project structure:
app:
backend:
/src
build.gradle
base:
/src
build.gradle
build.gradle
settings.gradle
Main class is contained in base/build.gradle and also base-module depends on backend-module.
SOLUTION: It is necessary to add following rows to backend/build.gradle
jar {
enabled = true
}
bootJar {
enabled = false
}
and check that base/build.gradle has the following rows:
bootJar {
archivesBaseName = 'base'
}
dependencies {
implementation project(":backend")
}
Just in case, for newcomers in gradle put the listing of settings.gradle file:
rootProject.name = 'app'
include 'backend', 'base'
Related
I'm trying to add Realm to an Android project, I've added the project level classpath dependency, but putting the
apply plugin: 'realm-android'
line in my module's build.gradle file results in the following build error:
Error:Execution failed for task ':data:compileDebugAndroidTestJavaWithJavac'.
java.lang.NoClassDefFoundError:
org/jetbrains/kotlin/annotation/AnnotationProcessorWrapper
Without that line, the application builds and runs fine, there is no Realm code in it yet.
Project level build.gradle:
allprojects {
repositories {
jcenter()
mavenCentral()
}
}
buildscript {
ext.kotlin_version = '1.0.6'
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.3'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "io.realm:realm-gradle-plugin:2.3.0"
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
Module build.gradle:
apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
apply plugin: 'realm-android'
android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
defaultConfig {
minSdkVersion 15
targetSdkVersion 25
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
sourceSets {
main.java.srcDirs += 'src/main/kotlin'
test {
java.srcDirs = ['src/test/kotlin']
}
}
}
buildscript {
ext.kotlin_version = '1.0.6'
repositories {
mavenCentral()
jcenter()
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
kapt {
generateStubs = true
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile project(path: ':domain')
compile 'org.jetbrains.kotlin:kotlin-stdlib:1.0.6'
compile 'io.reactivex:rxjava:1.1.6'
compile 'io.reactivex:rxkotlin:0.60.0'
compile 'javax.inject:javax.inject:1'
testCompile 'junit:junit:4.12'
testCompile 'org.mockito:mockito-core:2.6.3'
testCompile 'com.nhaarman:mockito-kotlin:1.1.0'
}
To close this question:
The comment #zaki50 wrote worked for me which is:
Adding apply plugin: 'kotlin-kapt' to app/build.gradle.
I added it right after apply plugin: 'kotlin-android'.
This issue is tracked by https://github.com/realm/realm-java/issues/4087
The file google-sevices.json is missing from module root folder even the file is in the app directory. My gradle version is 2.10. I have spent most of my time to solve this issue but still I cannot resolve the issue.
Project-level gradle
// 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:2.1.0'
classpath 'com.google.gms:google-services:2.1.0' //this is the latest version
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
App-Level gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
applicationId "com.myairticket.testpush3"
minSdkVersion 9
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
sourceSets { main { res.srcDirs = \['src/main/res', 'src/main/jsonfiles'\] } }
}
dependencies {
compile fileTree(dir: 'libs', include: \['*.jar'\])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.3.0'
compile 'com.android.support:design:23.3.0'
compile 'com.google.android.gms:play-services-gcm:8.4.0'
}
apply plugin:'com.google.gms.google-services
I would double check that it's in your app folder and not in the /res folder. If you dragged the file in to Android Studio and you were in the Android view instead of Project Files, there's a good chance it got copied into the wrong directory.
On my home desktop (Ubuntu) my project runs fine but when I open the project at work (ubuntu), the project fails to sync as the message says:
Gradle project sync failed. Basic functionality will not work properly.
Gradle DSL method not found: 'compile()'
Error:(11,0)
This is my module gradle
apply plugin: 'com.android.application'
apply plugin: 'com.parse'
buildscript {
repositories {
mavenCentral()
maven { url 'https://maven.parse.com/repo' }
}
dependencies {
classpath 'com.parse.tools:gradle:1.+'
compile 'com.stripe:stripe-android:+'
}
}
dependencies {
compile 'com.parse.bolts:bolts-android:1.2.0'
compile fileTree(dir: 'libs', include: 'Parse-*.jar')
compile fileTree(dir: 'libs', include: 'ParseCrashReporting-*.jar')
}
android {
compileSdkVersion rootProject.ext.compileSdkVersion
buildToolsVersion rootProject.ext.buildToolsVersion
defaultConfig {
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
res.srcDirs = ['res']
}
}
}
/* Uncomment if you enable ProGuard and you want to automatically upload symbols on build.
parse {
applicationId YOUR_APPLICATION_ID
masterKey YOUR_MASTER_KEY
// Make symbol upload automatic. Otherwise, use e.g. ../gradlew parseUploadSymbolsDebug;
uploadSymbols true
}
*/
and this is the project gradle
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.2.3'
classpath 'com.jakewharton.sdkmanager:gradle-plugin:0.12.+'
}
}
ext {
compileSdkVersion = 22
buildToolsVersion = "22"
minSdkVersion = 9
targetSdkVersion = 22
}
Move compile 'com.stripe:stripe-android:+' from the dependencies closure in buildscript to your other dependencies closure. com.stripe:stripe-android is a library, not a Gradle plugin.
I create a project on IntelliJ IDEA using Gradle and I'm trying to add AndroidSlidingUpPanel to it (https://github.com/umano/AndroidSlidingUpPanel).
What exactly do I have to do to configure it?
I have the following folder structure:
RootFolder
|_libraries
|_ AndroidSlidingUpPanel
|_ library
|_ build.gradle
|_ settings.gradle
|_ build.gradle
|_app
|_ build.gradle
|_ settings.gradle
|_ build.gradle
The files are like this:
RootFolder/settings.gradle
include ':app'
include ':libraries:AndroidSlidingUpPanel:library'
RootFolder/build.gradle
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.8.+'
}
}
allprojects {
repositories {
mavenCentral()
}
}
RootFolder/libraries/AndroidSlidingUpPanel/settings.gradle
include ':library'
include ':demo'
RootFolder/libraries/AndroidSlidingUpPanel/build.gradle
allprojects {
group 'com.sothree.slidinguppanel'
version '1.0.0-SNAPSHOT'
buildscript {
repositories {
mavenCentral()
}
}
dependencies {
repositories {
mavenCentral()
}
}
}
RootFolder/libraries/AndroidSlidingUpPanel/library/build.gradle
apply plugin: 'android-library'
buildscript {
dependencies {
classpath 'com.android.tools.build:gradle:0.7.+'
}
}
dependencies {
compile 'com.android.support:support-v4:13.0.0'
}
android {
compileSdkVersion 19
buildToolsVersion "19.0.1"
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
}
}
RootFolder/app/build.gradle
apply plugin: 'android'
android {
compileSdkVersion 19
buildToolsVersion "19.0.2"
defaultConfig {
minSdkVersion 10
targetSdkVersion 19
versionCode 1
versionName "1.0"
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
dependencies {
compile 'com.android.support:gridlayout-v7:19.0.1'
compile 'com.android.support:support-v4:19.0.1'
compile 'com.android.support:appcompat-v7:19.0.1'
compile fileTree(dir: 'libs', include: ['*.jar'])
}
You aren't clear about what build errors you may be having or what your exact question is, though since you haven't got a dependency to SlidingUpPanel in your app/build.gradle, the question is how to include it?
If so, the first thing to bear in mind is that a project can't have more than one settings.gradle. To be more precise, it only looks in the root folder for it and uses it if it's there. So the settings.gradle in RootFolder/libraries/AndroidSlidingUpPanel/ will be ignored. It looks like you've properly set up an include to the SlidingUpPanel library in RootFolder/settings.gradle, so that's good:
include ':libraries:AndroidSlidingUpPanel:library'
to include a dependency on it in your app, you use a compile project statement and give it the same path:
dependencies {
compile 'com.android.support:gridlayout-v7:19.0.1'
compile 'com.android.support:support-v4:19.0.1'
compile 'com.android.support:appcompat-v7:19.0.1'
compile project(':libraries:AndroidSlidingUpPanel:library')
compile fileTree(dir: 'libs', include: ['*.jar'])
}
If you're using Android Studio (it should also work with Gradle-based projects in IntelliJ Community Edition), you can set up dependencies on modules from the Project Structure dialog via Modules > Your module > Dependencies > + > Module dependency:
If you've added the module to your settings.gradle file as you already have and have synced up your project to the Gradle files, then the SlidingUpPanel module should appear in the Project view in the IDE and should appear as a module choice in that dependency list.
I was trying to integrate j soup library in android studio. I am getting error.
StackTrace:
Gradle: A problem occurred configuring root project 'JsoupProject'.
Failed to notify project evaluation listener.
Main Manifest missing from C:\Users\Asthme\Androidstudio\JsoupProject\src\main\AndroidManifest.xml
settings .gradle:
include ':Jsoup'
include ':libraries:jsoup-1.7.2.jar'
Build.gradle
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.6.+'
}
}
apply plugin: 'android'
dependencies {
compile fileTree(dir: 'libs', include: 'jsoup-1.7.2.jar')
}
repositories {
mavenCentral()
}
android {
compileSdkVersion 19
buildToolsVersion "19.0.0"
defaultConfig {
minSdkVersion 7
targetSdkVersion 19
}
}
dependencies {
compile 'com.android.support:appcompat-v7:+'
}
Library build.gradle
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.6.+'
}
}
apply plugin: 'android-library'
android {
compileSdkVersion 19
buildToolsVersion "19.0.0"
defaultConfig {
minSdkVersion 7
targetSdkVersion 19
}
}
dependencies {
...
implementation 'org.jsoup:jsoup:1.11.3'
}
(check the latest version number here: https://jsoup.org/download)
Don't include the Jsoup library from your settings.gradle, that's only for module. Just put it in the dependencies statement from any module that needs it. I see you've done it in your build.gradle file in your question, so you should be fine there.
My solution was: Copy for /app/libs the jsoup-1.10.3.jar, after import in the MainActivity.java "import org.jsoup.Jsoup;" and it working. With the code compile fileTree(dir: 'libs', include: ['*.jar']) in the buil.gradle(app) it work. jsoup in the /app/libs build.gradle(app)
Note: I am using Android Studio 2.2.1